DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 0/6] devtools: improve Linux uAPI script
@ 2025-08-27  8:21 Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 1/6] devtools: remove superfluous curly braces in " Thomas Monjalon
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Thomas Monjalon @ 2025-08-27  8:21 UTC (permalink / raw)
  To: dev

The main goal of this series is to check Linux uAPI headers quietly.
While doing so, few minor improvements are done.

Thomas Monjalon (6):
  devtools: remove superfluous curly braces in uAPI script
  devtools: remove superfluous fallbacks in uAPI script
  devtools: move uAPI processing into functions
  devtools: remove unused variables in uAPI script
  devtools: make uAPI check exclusive to other options
  devtools: add quiet mode in uAPI script

 devtools/linux-uapi.sh | 146 ++++++++++++++++++++++-------------------
 1 file changed, 80 insertions(+), 66 deletions(-)

-- 
2.47.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/6] devtools: remove superfluous curly braces in uAPI script
  2025-08-27  8:21 [PATCH 0/6] devtools: improve Linux uAPI script Thomas Monjalon
@ 2025-08-27  8:21 ` Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 2/6] devtools: remove superfluous fallbacks " Thomas Monjalon
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2025-08-27  8:21 UTC (permalink / raw)
  To: dev; +Cc: Maxime Coquelin

The use of curly braces for variables is inconsistent
in the Linux uAPI script.
It is chosen to remove all of them if not required.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 devtools/linux-uapi.sh | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index ccd8b6816e..2000152607 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -30,7 +30,7 @@ download_header()
 	local header=$1
 	local path=$2
 
-	local url="${base_url}${header}?h=${version}"
+	local url="$base_url$header?h=$version"
 
 	if ! curl -s -f --create-dirs -o $path $url; then
 		echo "Failed to download $url"
@@ -61,12 +61,12 @@ import_header()
 	local import
 	local header=$1
 
-	local path="${base_path}${header}"
+	local path="$base_path$header"
 
 	download_header $header $path || return 1
 
 	for include in $(sed -ne 's/^#include <\(.*\)>$/\1/p' $path); do
-		if [ ! -f "${base_path}${include}" ]; then
+		if [ ! -f "$base_path$include" ]; then
 			read -p "Import $include (y/n): " import && [ "$import" = 'y' ] || continue
 			echo "Importing $include for $path"
 			import_header "$include" || return 1
@@ -85,8 +85,8 @@ fixup_includes()
 
 	# Prepend include path with "uapi/" if the header is imported
 	for include in $(sed -ne 's/^#include <\(.*\)>$/\1/p' $path); do
-		if [ -f "${base_path}${include}" ]; then
-			sed -i "s|${include}|uapi/${include}|g" $path
+		if [ -f "$base_path$include" ]; then
+			sed -i "s|$include|uapi/$include|g" $path
 		fi
 	done
 }
@@ -106,7 +106,7 @@ check_header() {
 }
 
 while getopts i:u:ch opt ; do
-	case ${opt} in
+	case $opt in
 		i ) file=$OPTARG ;;
 		u ) version=$OPTARG ;;
 		c ) check_headers=1 ;;
@@ -123,9 +123,9 @@ fi
 
 cd $(dirname $0)/..
 
-current_version=$(< ${base_path}/version)
+current_version=$(< $base_path/version)
 
-if [ -n "${version}" ]; then
+if [ -n "$version" ]; then
 	if version_older_than "$version" "$current_version"; then
 		echo "Headers already up to date ($current_version >= $version)"
 		version=$current_version
@@ -137,7 +137,7 @@ else
 	version=$current_version
 fi
 
-if [ -n "${file}" ]; then
+if [ -n "$file" ]; then
 	import_header $file || exit 1
 fi
 
@@ -145,7 +145,7 @@ for filename in $(find $base_path -name "*.h" -type f); do
 	fixup_includes $filename || exit 1
 done
 
-echo $version > ${base_path}/version
+echo $version > $base_path/version
 
 if [ $check_headers -eq 0 ]; then
 	exit 0
@@ -154,7 +154,7 @@ fi
 tmpheader="$(mktemp -t dpdk.checkuapi.XXXXXX)"
 trap "rm -f '$tmpheader'" INT
 
-echo "Checking imported headers for version ${version}"
+echo "Checking imported headers for version $version"
 
 for filename in $(find $base_path -name "*.h" -type f); do
 	header=${filename#$base_path}
-- 
2.47.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/6] devtools: remove superfluous fallbacks in uAPI script
  2025-08-27  8:21 [PATCH 0/6] devtools: improve Linux uAPI script Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 1/6] devtools: remove superfluous curly braces in " Thomas Monjalon
@ 2025-08-27  8:21 ` Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 3/6] devtools: move uAPI processing into functions Thomas Monjalon
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2025-08-27  8:21 UTC (permalink / raw)
  To: dev; +Cc: Maxime Coquelin

The option -e was set on the script shebang (first line),
so the script will stop if an error is not caught.
Hence the explicit return or exit commands in case of error
were superfluous and can be removed.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 devtools/linux-uapi.sh | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index 2000152607..dc2f8bb36e 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -49,7 +49,7 @@ update_headers()
 	echo "Updating to $version"
 	for filename in $(find $base_path -name "*.h" -type f); do
 		header=${filename#$base_path}
-		download_header $header $filename || return 1
+		download_header $header $filename
 	done
 
 	return 0
@@ -63,13 +63,13 @@ import_header()
 
 	local path="$base_path$header"
 
-	download_header $header $path || return 1
+	download_header $header $path
 
 	for include in $(sed -ne 's/^#include <\(.*\)>$/\1/p' $path); do
 		if [ ! -f "$base_path$include" ]; then
 			read -p "Import $include (y/n): " import && [ "$import" = 'y' ] || continue
 			echo "Importing $include for $path"
-			import_header "$include" || return 1
+			import_header "$include"
 		fi
 	done
 
@@ -130,7 +130,7 @@ if [ -n "$version" ]; then
 		echo "Headers already up to date ($current_version >= $version)"
 		version=$current_version
 	else
-		update_headers || exit 1
+		update_headers
 	fi
 else
 	echo "Version not specified, using current version ($current_version)"
@@ -138,11 +138,11 @@ else
 fi
 
 if [ -n "$file" ]; then
-	import_header $file || exit 1
+	import_header $file
 fi
 
 for filename in $(find $base_path -name "*.h" -type f); do
-	fixup_includes $filename || exit 1
+	fixup_includes $filename
 done
 
 echo $version > $base_path/version
@@ -158,8 +158,8 @@ echo "Checking imported headers for version $version"
 
 for filename in $(find $base_path -name "*.h" -type f); do
 	header=${filename#$base_path}
-	download_header $header $tmpheader || exit 1
-	fixup_includes $tmpheader || exit 1
+	download_header $header $tmpheader
+	fixup_includes $tmpheader
 	check_header $filename $tmpheader || errors=$((errors+1))
 done
 
-- 
2.47.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/6] devtools: move uAPI processing into functions
  2025-08-27  8:21 [PATCH 0/6] devtools: improve Linux uAPI script Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 1/6] devtools: remove superfluous curly braces in " Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 2/6] devtools: remove superfluous fallbacks " Thomas Monjalon
@ 2025-08-27  8:21 ` Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 4/6] devtools: remove unused variables in uAPI script Thomas Monjalon
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2025-08-27  8:21 UTC (permalink / raw)
  To: dev; +Cc: Maxime Coquelin

There are two main parts in the Linux uAPI script:
- update the headers
- check the headers

In order to facilitate reading and rework,
these two parts are move in functions.

There is no change in the behavior.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 devtools/linux-uapi.sh | 96 +++++++++++++++++++++++-------------------
 1 file changed, 53 insertions(+), 43 deletions(-)

diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index dc2f8bb36e..05f3ddf87c 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -11,7 +11,6 @@ base_path="kernel/linux/uapi/"
 version=""
 file=""
 check_headers=0
-errors=0
 
 print_usage()
 {
@@ -91,7 +90,35 @@ fixup_includes()
 	done
 }
 
-check_header() {
+update_all()
+{
+	local current_version=$(< $base_path/version)
+
+	if [ -n "$version" ]; then
+		if version_older_than "$version" "$current_version"; then
+			echo "Headers already up to date ($current_version >= $version)"
+			version=$current_version
+		else
+			update_headers
+		fi
+	else
+		echo "Version not specified, using current version ($current_version)"
+		version=$current_version
+	fi
+
+	if [ -n "$file" ]; then
+		import_header $file
+	fi
+
+	for filename in $(find $base_path -name "*.h" -type f); do
+		fixup_includes $filename
+	done
+
+	echo $version > $base_path/version
+}
+
+check_header()
+{
 	echo -n "Checking $1... "
 
 	if ! diff -q $1 $2 >/dev/null; then
@@ -105,6 +132,28 @@ check_header() {
 	return 0
 }
 
+check_all()
+{
+	local errors=0
+
+	tmpheader="$(mktemp -t dpdk.checkuapi.XXXXXX)"
+	trap "rm -f '$tmpheader'" INT
+
+	echo "Checking imported headers for version $version"
+	for filename in $(find $base_path -name "*.h" -type f); do
+		header=${filename#$base_path}
+		download_header $header $tmpheader
+		fixup_includes $tmpheader
+		check_header $filename $tmpheader || errors=$((errors+1))
+	done
+	echo "$errors error(s) found"
+
+	rm -f $tmpheader
+	trap - INT
+
+	return $errors
+}
+
 while getopts i:u:ch opt ; do
 	case $opt in
 		i ) file=$OPTARG ;;
@@ -123,49 +172,10 @@ fi
 
 cd $(dirname $0)/..
 
-current_version=$(< $base_path/version)
-
-if [ -n "$version" ]; then
-	if version_older_than "$version" "$current_version"; then
-		echo "Headers already up to date ($current_version >= $version)"
-		version=$current_version
-	else
-		update_headers
-	fi
-else
-	echo "Version not specified, using current version ($current_version)"
-	version=$current_version
-fi
-
-if [ -n "$file" ]; then
-	import_header $file
-fi
-
-for filename in $(find $base_path -name "*.h" -type f); do
-	fixup_includes $filename
-done
-
-echo $version > $base_path/version
+update_all
 
 if [ $check_headers -eq 0 ]; then
 	exit 0
 fi
 
-tmpheader="$(mktemp -t dpdk.checkuapi.XXXXXX)"
-trap "rm -f '$tmpheader'" INT
-
-echo "Checking imported headers for version $version"
-
-for filename in $(find $base_path -name "*.h" -type f); do
-	header=${filename#$base_path}
-	download_header $header $tmpheader
-	fixup_includes $tmpheader
-	check_header $filename $tmpheader || errors=$((errors+1))
-done
-
-echo "$errors error(s) found"
-
-rm -f $tmpheader
-trap - INT
-
-exit $errors
+check_all
-- 
2.47.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/6] devtools: remove unused variables in uAPI script
  2025-08-27  8:21 [PATCH 0/6] devtools: improve Linux uAPI script Thomas Monjalon
                   ` (2 preceding siblings ...)
  2025-08-27  8:21 ` [PATCH 3/6] devtools: move uAPI processing into functions Thomas Monjalon
@ 2025-08-27  8:21 ` Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 5/6] devtools: make uAPI check exclusive to other options Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 6/6] devtools: add quiet mode in uAPI script Thomas Monjalon
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2025-08-27  8:21 UTC (permalink / raw)
  To: dev; +Cc: Maxime Coquelin

Some local variables were not used in the function update_headers()
of the Linux uAPI script.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 devtools/linux-uapi.sh | 2 --
 1 file changed, 2 deletions(-)

diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index 05f3ddf87c..654c4a8c25 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -42,8 +42,6 @@ download_header()
 update_headers()
 {
 	local header
-	local url
-	local path
 
 	echo "Updating to $version"
 	for filename in $(find $base_path -name "*.h" -type f); do
-- 
2.47.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/6] devtools: make uAPI check exclusive to other options
  2025-08-27  8:21 [PATCH 0/6] devtools: improve Linux uAPI script Thomas Monjalon
                   ` (3 preceding siblings ...)
  2025-08-27  8:21 ` [PATCH 4/6] devtools: remove unused variables in uAPI script Thomas Monjalon
@ 2025-08-27  8:21 ` Thomas Monjalon
  2025-08-27  8:21 ` [PATCH 6/6] devtools: add quiet mode in uAPI script Thomas Monjalon
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2025-08-27  8:21 UTC (permalink / raw)
  To: dev; +Cc: Maxime Coquelin

When doing a check of Linux uAPI headers,
it is better to not fix them before.
Also, it does not make sense to check just after doing an update,
as the check would just repeat the same update process.
That's why a check is now run alone without any update.

The current version has to be retrieved in all cases,
so it is moved at the beginning of any processing.

If the check option (-c) is used with an import (-i) or an upgrade (-u),
an error is raised.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 devtools/linux-uapi.sh | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index 654c4a8c25..0986b668de 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -10,7 +10,7 @@ base_url="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/pla
 base_path="kernel/linux/uapi/"
 version=""
 file=""
-check_headers=0
+check_headers=false
 
 print_usage()
 {
@@ -90,8 +90,6 @@ fixup_includes()
 
 update_all()
 {
-	local current_version=$(< $base_path/version)
-
 	if [ -n "$version" ]; then
 		if version_older_than "$version" "$current_version"; then
 			echo "Headers already up to date ($current_version >= $version)"
@@ -156,7 +154,7 @@ while getopts i:u:ch opt ; do
 	case $opt in
 		i ) file=$OPTARG ;;
 		u ) version=$OPTARG ;;
-		c ) check_headers=1 ;;
+		c ) check_headers=true ;;
 		h ) print_usage ; exit 0 ;;
 		? ) print_usage ; exit 1 ;;
 	esac
@@ -167,13 +165,17 @@ if [ $# -ne 0 ]; then
 	print_usage
 	exit 1
 fi
+if $check_headers && [ -n "$file" -o -n "$version" ]; then
+	echo "The option -c is incompatible with -i and -u"
+	exit 1
+fi
 
 cd $(dirname $0)/..
+current_version=$(cat $base_path/version)
 
-update_all
-
-if [ $check_headers -eq 0 ]; then
-	exit 0
+if $check_headers; then
+	version=$current_version
+	check_all
+else
+	update_all
 fi
-
-check_all
-- 
2.47.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 6/6] devtools: add quiet mode in uAPI script
  2025-08-27  8:21 [PATCH 0/6] devtools: improve Linux uAPI script Thomas Monjalon
                   ` (4 preceding siblings ...)
  2025-08-27  8:21 ` [PATCH 5/6] devtools: make uAPI check exclusive to other options Thomas Monjalon
@ 2025-08-27  8:21 ` Thomas Monjalon
  5 siblings, 0 replies; 7+ messages in thread
From: Thomas Monjalon @ 2025-08-27  8:21 UTC (permalink / raw)
  To: dev; +Cc: Maxime Coquelin

Most messages from the Linux uAPI script are not useful
when running the script in a regular fashion.
The quiet mode (option -q) is added to output only error messages if any.

Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
---
 devtools/linux-uapi.sh | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index 0986b668de..9f9f08035f 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -11,6 +11,7 @@ base_path="kernel/linux/uapi/"
 version=""
 file=""
 check_headers=false
+quiet=false
 
 print_usage()
 {
@@ -43,7 +44,7 @@ update_headers()
 {
 	local header
 
-	echo "Updating to $version"
+	$quiet || echo "Updating to $version"
 	for filename in $(find $base_path -name "*.h" -type f); do
 		header=${filename#$base_path}
 		download_header $header $filename
@@ -65,7 +66,7 @@ import_header()
 	for include in $(sed -ne 's/^#include <\(.*\)>$/\1/p' $path); do
 		if [ ! -f "$base_path$include" ]; then
 			read -p "Import $include (y/n): " import && [ "$import" = 'y' ] || continue
-			echo "Importing $include for $path"
+			$quiet || echo "Importing $include for $path"
 			import_header "$include"
 		fi
 	done
@@ -92,13 +93,13 @@ update_all()
 {
 	if [ -n "$version" ]; then
 		if version_older_than "$version" "$current_version"; then
-			echo "Headers already up to date ($current_version >= $version)"
+			$quiet || echo "Headers already up to date ($current_version >= $version)"
 			version=$current_version
 		else
 			update_headers
 		fi
 	else
-		echo "Version not specified, using current version ($current_version)"
+		$quiet || echo "Version not specified, using current version ($current_version)"
 		version=$current_version
 	fi
 
@@ -115,14 +116,14 @@ update_all()
 
 check_header()
 {
-	echo -n "Checking $1... "
+	$quiet || echo -n "Checking $1... "
 
 	if ! diff -q $1 $2 >/dev/null; then
-		echo "KO"
-		diff -u $1 $2
+		$quiet || echo "KO"
+		$quiet || diff -u $1 $2
 		return 1
 	else
-		echo "OK"
+		$quiet || echo "OK"
 	fi
 
 	return 0
@@ -135,14 +136,16 @@ check_all()
 	tmpheader="$(mktemp -t dpdk.checkuapi.XXXXXX)"
 	trap "rm -f '$tmpheader'" INT
 
-	echo "Checking imported headers for version $version"
+	$quiet || echo "Checking imported headers for version $version"
 	for filename in $(find $base_path -name "*.h" -type f); do
 		header=${filename#$base_path}
 		download_header $header $tmpheader
 		fixup_includes $tmpheader
 		check_header $filename $tmpheader || errors=$((errors+1))
 	done
-	echo "$errors error(s) found"
+	if [ $errors -ne 0 ] || ! $quiet; then
+		echo "$errors error(s) found in Linux uAPI"
+	fi
 
 	rm -f $tmpheader
 	trap - INT
@@ -150,11 +153,12 @@ check_all()
 	return $errors
 }
 
-while getopts i:u:ch opt ; do
+while getopts i:u:cqh opt ; do
 	case $opt in
 		i ) file=$OPTARG ;;
 		u ) version=$OPTARG ;;
 		c ) check_headers=true ;;
+		q ) quiet=true ;;
 		h ) print_usage ; exit 0 ;;
 		? ) print_usage ; exit 1 ;;
 	esac
-- 
2.47.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-08-27  8:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-27  8:21 [PATCH 0/6] devtools: improve Linux uAPI script Thomas Monjalon
2025-08-27  8:21 ` [PATCH 1/6] devtools: remove superfluous curly braces in " Thomas Monjalon
2025-08-27  8:21 ` [PATCH 2/6] devtools: remove superfluous fallbacks " Thomas Monjalon
2025-08-27  8:21 ` [PATCH 3/6] devtools: move uAPI processing into functions Thomas Monjalon
2025-08-27  8:21 ` [PATCH 4/6] devtools: remove unused variables in uAPI script Thomas Monjalon
2025-08-27  8:21 ` [PATCH 5/6] devtools: make uAPI check exclusive to other options Thomas Monjalon
2025-08-27  8:21 ` [PATCH 6/6] devtools: add quiet mode in uAPI script Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).