checkpatch: fix SPDX license check with --root=<path>
authorJoe Perches <[email protected]>
Wed, 22 Aug 2018 04:58:04 +0000 (21:58 -0700)
committerLinus Torvalds <[email protected]>
Wed, 22 Aug 2018 17:52:49 +0000 (10:52 -0700)
checkpatch uses the in-kernel script spdxcheck.py to validate the specific
license in a file or script.

This check can currently fail for a couple reasons:

o spdxcheck.py assumes the existence of git tree that may not
  exist for a bare source tree from something like a tarball
o the spdxcheck.py must be run from the top level root directory

So add a git existence test and set the subprocess subdirectory.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Joe Perches <[email protected]>
Reported-by: Charlemagne Lasse <[email protected]>
Tested-by: Charlemagne Lasse <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
scripts/checkpatch.pl

index 25adf9811a2cf981644835259604e8d545bfd295..eced9b30399574b89ce66bf75662563bacffc0bb 100755 (executable)
@@ -852,9 +852,10 @@ sub is_maintained_obsolete {
 sub is_SPDX_License_valid {
        my ($license) = @_;
 
-       return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py"));
+       return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/.git"));
 
-       my $status = `echo "$license" | python $root/scripts/spdxcheck.py -`;
+       my $root_path = abs_path($root);
+       my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`;
        return 0 if ($status ne "");
        return 1;
 }