2018-07-30 08:54:39

by Charlemagne Lasse

[permalink] [raw]
Subject: checkpatch: SPDX integration breaks --root

Hi,

I am now getting python errors when using --root with checkpatch.pl
and not being inside the linux repository.

$ ./linux-next/scripts/checkpatch.pl --root=/usr/src/linux-next
--strict -f linux-next/Makefile
FAIL: /usr/src
Traceback (most recent call last):
File /usr/src/linux-next/scripts/spdxcheck.py", line 230, in <module>
repo = git.Repo(os.getcwd())
File "/usr/lib/python2.7/dist-packages/git/repo/base.py", line 156, in __init__
raise InvalidGitRepositoryError(epath)
InvalidGitRepositoryError: /usr/src

total: 0 errors, 0 warnings, 0 checks, 1726 lines checked

linux-next/Makefile has no obvious style problems and is ready for submission.


2018-07-30 15:42:10

by Joe Perches

[permalink] [raw]
Subject: Re: checkpatch: SPDX integration breaks --root

On Mon, 2018-07-30 at 10:53 +0200, Charlemagne Lasse wrote:
> Hi,
>
> I am now getting python errors when using --root with checkpatch.pl
> and not being inside the linux repository.
>
> $ ./linux-next/scripts/checkpatch.pl --root=/usr/src/linux-next
> --strict -f linux-next/Makefile
> FAIL: /usr/src
> Traceback (most recent call last):
> File /usr/src/linux-next/scripts/spdxcheck.py", line 230, in <module>
> repo = git.Repo(os.getcwd())
> File "/usr/lib/python2.7/dist-packages/git/repo/base.py", line 156, in __init__
> raise InvalidGitRepositoryError(epath)
> InvalidGitRepositoryError: /usr/src
>
> total: 0 errors, 0 warnings, 0 checks, 1726 lines checked
>
> linux-next/Makefile has no obvious style problems and is ready for submission.

Does this work for you:
---
scripts/checkpatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f25f708cd2a7..f0e6913c5cc1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -852,7 +852,7 @@ 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 -`;
return 0 if ($status ne "");

2018-07-30 15:53:57

by Charlemagne Lasse

[permalink] [raw]
Subject: Re: checkpatch: SPDX integration breaks --root

> Does this work for you:
> ---
> scripts/checkpatch.pl | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index f25f708cd2a7..f0e6913c5cc1 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -852,7 +852,7 @@ 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 -`;
> return 0 if ($status ne "");

No, because $root is a git repository in my case (linux-next to be
exact). The problem here is that spdxcheck is ignoring $root and just
assumes that cwd is a linux git repository. And when it is one but not
a linux git repo then I get following error:

FAIL: "Blob or Tree named 'other' not found"
Traceback (most recent call last):
File "/usr/src/linux-next/scripts/spdxcheck.py", line 234, in <module>
spdx = read_spdxdata(repo)
File "/usr/src/linux-next/scripts/spdxcheck.py", line 41, in read_spdxdata
for el in lictree[d].traverse():
File "/usr/lib/python2.7/dist-packages/git/objects/tree.py", line
298, in __getitem__
return self.join(item)
File "/usr/lib/python2.7/dist-packages/git/objects/tree.py", line 244, in join
raise KeyError(msg % file)
KeyError: "Blob or Tree named 'other' not found"


Still, your change looks good when $root is pointing to an extracted
tarball with the linux sources and not to a full repository

2018-07-30 16:31:42

by Joe Perches

[permalink] [raw]
Subject: Re: checkpatch: SPDX integration breaks --root

On Mon, 2018-07-30 at 17:52 +0200, Charlemagne Lasse wrote:
> > Does this work for you:
> > ---
> > scripts/checkpatch.pl | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index f25f708cd2a7..f0e6913c5cc1 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -852,7 +852,7 @@ 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 -`;
> > return 0 if ($status ne "");
>
> No, because $root is a git repository in my case (linux-next to be
> exact). The problem here is that spdxcheck is ignoring $root and just
> assumes that cwd is a linux git repository. And when it is one but not
> a linux git repo then I get following error:
>
> FAIL: "Blob or Tree named 'other' not found"
> Traceback (most recent call last):
> File "/usr/src/linux-next/scripts/spdxcheck.py", line 234, in <module>
> spdx = read_spdxdata(repo)
> File "/usr/src/linux-next/scripts/spdxcheck.py", line 41, in read_spdxdata
> for el in lictree[d].traverse():
> File "/usr/lib/python2.7/dist-packages/git/objects/tree.py", line
> 298, in __getitem__
> return self.join(item)
> File "/usr/lib/python2.7/dist-packages/git/objects/tree.py", line 244, in join
> raise KeyError(msg % file)
> KeyError: "Blob or Tree named 'other' not found"
>
>
> Still, your change looks good when $root is pointing to an extracted
> tarball with the linux sources and not to a full repository

OK. How about:

though this might not work on a path with spaces
or some such...

---
scripts/checkpatch.pl | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f25f708cd2a7..afb9fb27908c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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;
}

2018-07-31 06:45:48

by Charlemagne Lasse

[permalink] [raw]
Subject: Re: checkpatch: SPDX integration breaks --root

> OK. How about:
>
> though this might not work on a path with spaces
> or some such...
>
> ---
> scripts/checkpatch.pl | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index f25f708cd2a7..afb9fb27908c 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -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;
> }

Thanks, works at least for me. Maybe use

cd "$root_path"

to get it working with paths that include spaces.

Tested-by: Charlemagne Lasse <[email protected]>