Skip to contentSkip to conversation

devtools: fix SPDX tag check

PATCH Superseded Thomas Monjalon 4 participants 11 messages Apr 29 – May 17

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devtools: fix SPDX tag check

If a file has no SPDX tag and is not filtered out by no_license_list, there will be an error when using its path containing a slash in the sed command delimited with slashes.

It is fixed by using the pipe character as sed command delimiter.

Fixes b99a3b8aa989 ("license: standardize SPDX tag")
---
 devtools/check-spdx-tag.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
devtools/check-spdx-tag.sh +1 -1
index 2390941c74..f0fcddf0d3 100755
@@ -41,7 +41,7 @@ check_spdx() {
     files_without_spdx=$(cat $tmpfile)
     git grep -LE '(/\*|#|;|\.\.) *SPDX-License-Identifier: [A-Z(]' -- $no_license_list > $tmpfile
     for file in $files_without_spdx ; do
-	sed -i "/^$file$/d" $tmpfile
+	sed -i "\|^$file$|d" $tmpfile
     done
 
     warnings=$(($warnings + $(wc -l < $tmpfile)))
Signature · 1 line
2.53.0
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · On Wed, 29 Apr 2026 15:09:35 +0200 Thomas Monjalon <[email protected]> wrote:

If a file has no SPDX tag and is not filtered out by no_license_list, there will be an error when using its path containing a slash in the sed command delimited with slashes.

Quoted 8 lines

It is fixed by using the pipe character as sed command delimiter.

Fixes b99a3b8aa989 ("license: standardize SPDX tag")

---

Acked-by on v1 1/1
#2 lore raw
In reply to Thomas Monjalon
Quoted 5 lines · Thomas Monjalon

If a file has no SPDX tag and is not filtered out by no_license_list, there will be an error when using its path containing a slash in the sed command delimited with slashes.

Quoted 7 lines

It is fixed by using the pipe character as sed command delimiter.

Fixes b99a3b8aa989 ("license: standardize SPDX tag")
Signature · 1 line
David Marchand
author Applied
#3 lore raw
Quoted 6 lines
Quoted 6 lines

If a file has no SPDX tag and is not filtered out by no_license_list, there will be an error when using its path containing a slash in the sed command delimited with slashes.

It is fixed by using the pipe character as sed command delimiter.

Quoted 7 lines
Quoted 5 lines
Fixes b99a3b8aa989 ("license: standardize SPDX tag")

Applied

#4 lore raw
In reply to Thomas Monjalon

Patch definitely improves the situation, but after a quick prompt Gemini suggested | grep -vF "$files_without_spdx" for safe filtering (man page confirms that patterns can be separated with newlines).

#5 lore raw

29/04/2026 18:17, Marat Khalili:

Quoted 1 line

Patch definitely improves the situation, but after a quick prompt Gemini suggested | grep -vF "$files_without_spdx" for safe filtering (man page confirms that patterns can be separated with newlines).

Yes grep looks simpler than sed for this filter.
I'll send a v2 with your suggestion.
Thank you

#6 lore raw

PATCH v2 1/1 devtools: fix SPDX tag check

In reply to Thomas Monjalon

If a file has no SPDX tag and is not filtered out by no_license_list, there will be an error when using its path containing a slash in the sed command delimited with slashes.

It could be fixed by using another character as sed command delimiter. The chosen fix is to use grep instead of sed.

Fixes b99a3b8aa989 ("license: standardize SPDX tag")

---
v1: replace / with |
v2: use grep instead of sed (Marat's suggestion)

---
 devtools/check-spdx-tag.sh | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
devtools/check-spdx-tag.sh +2 -4
index 2390941c74..41fc1fe01d 100755
@@ -39,10 +39,8 @@ check_spdx() {
     fi
 
     files_without_spdx=$(cat $tmpfile)
-    git grep -LE '(/\*|#|;|\.\.) *SPDX-License-Identifier: [A-Z(]' -- $no_license_list > $tmpfile
-    for file in $files_without_spdx ; do
-	sed -i "/^$file$/d" $tmpfile
-    done
+    git grep -LE '(/\*|#|;|\.\.) *SPDX-License-Identifier: [A-Z(]' -- $no_license_list |
+    grep -vF "$files_without_spdx" > $tmpfile
 
     warnings=$(($warnings + $(wc -l < $tmpfile)))
     $quiet || cat $tmpfile
Signature · 1 line
2.53.0
Acked-by on v2 1/1
#7 lore raw
Quoted 18 lines
devtools/check-spdx-tag.sh +2 -5
index 2390941c74..41fc1fe01d 100755
@@ -39,10 +39,8 @@ check_spdx() {
     fi
 
     files_without_spdx=$(cat $tmpfile)
-    git grep -LE '(/\*|#|;|\.\.) *SPDX-License-Identifier: [A-Z(]' -- $no_license_list > $tmpfile
-    for file in $files_without_spdx ; do
-	sed -i "/^$file$/d" $tmpfile
-    done
+    git grep -LE '(/\*|#|;|\.\.) *SPDX-License-Identifier: [A-Z(]' -- $no_license_list |
+    grep -vF "$files_without_spdx" > $tmpfile
 
     warnings=$(($warnings + $(wc -l < $tmpfile)))
     $quiet || cat $tmpfile
--
Quoted 1 line

2.53.0

Sorry for forgetting to mention it right away, some kind of sentinel or if condition is needed if $files_without_spdx can be empty, don't know how realistic it is in practice and whether other parts are ready to handle this case. E.g. files_without_spdx=$(echo //sentinel; cat $tmpfile). I hope it won't make the whole thing too complicated and not worth it.

Otherwise,

#8 lore raw

30/04/2026 15:30, Marat Khalili:

Quoted 15 lines
Quoted 15 lines
devtools/check-spdx-tag.sh +2 -4
index 2390941c74..41fc1fe01d 100755
@@ -39,10 +39,8 @@ check_spdx() {
     fi
 
     files_without_spdx=$(cat $tmpfile)
-    git grep -LE '(/\*|#|;|\.\.) *SPDX-License-Identifier: [A-Z(]' -- $no_license_list > $tmpfile
-    for file in $files_without_spdx ; do
-	sed -i "/^$file$/d" $tmpfile
-    done
+    git grep -LE '(/\*|#|;|\.\.) *SPDX-License-Identifier: [A-Z(]' -- $no_license_list |
+    grep -vF "$files_without_spdx" > $tmpfile
 
Quoted 10 lines
Quoted 4 lines
devtools/check-spdx-tag.sh +0 -1
     warnings=$(($warnings + $(wc -l < $tmpfile)))
     $quiet || cat $tmpfile
--

2.53.0

Sorry for forgetting to mention it right away, some kind of sentinel or if condition is needed if $files_without_spdx can be empty, don't know how realistic it is in practice and whether other parts are ready to handle this case. E.g. files_without_spdx=$(echo //sentinel; cat $tmpfile). I hope it won't make the whole thing too complicated and not worth it.

Sorry I don't understand the need for a sentinel. The script is working fine with an empty files_without_spdx.

#9 lore raw
Quoted 2 lines

Sorry I don't understand the need for a sentinel. The script is working fine with an empty files_without_spdx.

It may filter out everything instead of nothing in that case.

#10 lore raw

01/05/2026 11:55, Marat Khalili:

Quoted 4 lines
Quoted 2 lines

Sorry I don't understand the need for a sentinel. The script is working fine with an empty files_without_spdx.

It may filter out everything instead of nothing in that case.

OK you're right.
So it becomes complex.
The first solution with sed looks better.