Skip to contentSkip to conversation

devtools: check uAPI headers inclusions

PATCH In review David Marchand 2 participants 3 messages Nov 3 – Nov 19

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devtools: check uAPI headers inclusions

Imported Linux kernel uAPI headers must be included before any other header to avoid a system-installed header being read instead.

Add a check that runs after every operation to catch files where Linux uapi includes are preceded by other includes.

---
 devtools/linux-uapi.sh | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
devtools/linux-uapi.sh +25 -0
index 3f804685aa..d03b43a0aa 100755
@@ -138,6 +138,29 @@ check_header()
 	return 0
 }
 
+check_include_order()
+{
+	local errors=0
+
+	$quiet || echo "Checking uapi/linux inclusion order"
+	for filename in $(git grep -l '#include <uapi/linux/' ':!devtools/linux-uapi.sh' \
+			':!doc/guides/contributing/linux_uapi.rst' ':!kernel/linux/uapi/'); do
+		last_uapi=$(grep -n '#include <uapi/linux/' "$filename" | tail -1 | cut -d: -f1)
+		first_other=$(grep -n '^#include' "$filename" | grep -v 'uapi/linux/' |
+			head -1 | cut -d: -f1)
+		if [ -z "$first_other" ] || [ "$first_other" -gt "$last_uapi" ]; then
+			continue;
+		fi
+		$quiet || echo "$filename: uapi headers must be included before other headers"
+		errors=$((errors + 1))
+	done
+	if [ $errors -ne 0 ] || ! $quiet; then
+		echo "$errors error(s) found in uapi inclusion order"
+	fi
+
+	return $errors
+}
+
 check_all()
 {
 	local errors=0
@@ -192,3 +215,5 @@ if $check_headers; then
 else
 	update_all
 fi
+
+check_include_order
Signature · 1 line
2.56.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · David Marchand

Imported Linux kernel uAPI headers must be included before any other header to avoid a system-installed header being read instead.

Quoted 8 lines

Add a check that runs after every operation to catch files where Linux uapi includes are preceded by other includes.

---
 devtools/linux-uapi.sh | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Thanks,
Maxime

author Applied
#2 lore raw
Quoted 10 lines · Maxime Coquelin
Quoted 8 lines · David Marchand

Imported Linux kernel uAPI headers must be included before any other header to avoid a system-installed header being read instead.

Add a check that runs after every operation to catch files where Linux uapi includes are preceded by other includes.

Applied, thanks.

Signature · 1 line
David Marchand