Skip to contentSkip to conversation

regression: checkpatch.pl fails when called via symlink

PATCH In review Jani Nikula 4 participants 10 messages Oct 22, 2014 – Oct 24, 2014 Checkpatch

lore
Share & tools
lore
#0 lore raw

Since commit 66b47b4a9dad00e45c049d79966de9a3a1f4d337

Author: Kees Cook <[email protected]>
Date:   Mon Oct 13 15:51:57 2014 -0700

checkpatch: look for common misspellings

checkpatch.pl dies with

checkpatch.pl: Can't open /path/to/spelling.txt for reading: No such file or directory

if it's called through a symlink in /path/to/checkpatch.pl pointing at the actual script.

Please fail graciously, and just ignore spelling if you can't find spelling.txt. Or better yet, follow the links if you can.

Thanks,
Jani.

Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
maintainer
#1 lore raw
Quoted 8 lines · Jani Nikula

Since commit 66b47b4a9dad00e45c049d79966de9a3a1f4d337

Author: Kees Cook <[email protected]>
Date:   Mon Oct 13 15:51:57 2014 -0700

checkpatch: look for common misspellings

checkpatch.pl dies with

Quoted 7 lines

checkpatch.pl: Can't open /path/to/spelling.txt for reading: No such file or directory

if it's called through a symlink in /path/to/checkpatch.pl pointing at the actual script.

Please fail graciously, and just ignore spelling if you can't find spelling.txt. Or better yet, follow the links if you can.

I agree it should fail better, but I'm also curious. Why you want to use a symlink?

#2 lore raw
Quoted 11 lines · Joe Perches
Quoted 10 lines · Jani Nikula

Since commit 66b47b4a9dad00e45c049d79966de9a3a1f4d337

Author: Kees Cook <[email protected]>
Date:   Mon Oct 13 15:51:57 2014 -0700

checkpatch: look for common misspellings

checkpatch.pl dies with

checkpatch.pl: Can't open /path/to/spelling.txt for reading: No such file or directory

Quoted 8 lines
Quoted 5 lines

if it's called through a symlink in /path/to/checkpatch.pl pointing at the actual script.

Please fail graciously, and just ignore spelling if you can't find spelling.txt. Or better yet, follow the links if you can.

I agree it should fail better, but I'm also curious. Why you want to use a symlink?

Simply because I think having $HOME/bin in $PATH and a symlink there is better than the alternatives.

I don't want to add scripts to $PATH because there's so much cruft. I don't want to copy checkpatch.pl (and now spelling.txt) because I generally want it to stay up-to-date. I don't want to use an alias because some maintainer scripts would break. I don't want to use a full path because it's tedious, and potentially different on different machines.

Reference: http://xkcd.com/1172/

BR,
Jani.

Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
maintainer
#3 lore raw
Quoted 12 lines · Jani Nikula
Quoted 11 lines · Joe Perches
Quoted 10 lines · Jani Nikula

Since commit 66b47b4a9dad00e45c049d79966de9a3a1f4d337

Author: Kees Cook <[email protected]>
Date:   Mon Oct 13 15:51:57 2014 -0700

checkpatch: look for common misspellings
checkpatch.pl dies with
checkpatch.pl: Can't open /path/to/spelling.txt for reading: No such file or directory

if it's called through a symlink in /path/to/checkpatch.pl pointing at the actual script.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Please fail graciously, and just ignore spelling if you can't find spelling.txt. Or better yet, follow the links if you can.

I agree it should fail better, but I'm also curious. Why you want to use a symlink?

Simply because I think having $HOME/bin in $PATH and a symlink there is better than the alternatives.

[]

Quoted 1 line

Reference: http://xkcd.com/1172/

:)

Try this:

 scripts/checkpatch.pl | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)
scripts/checkpatch.pl +21 -17
index d94f5d8..a6354ec 100755
@@ -7,10 +7,11 @@
 
 use strict;
 use POSIX;
+use File::Basename;
+use Cwd 'abs_path';
 
 my $P = $0;
-$P =~ s@(.*)/@@g;
-my $D = $1;
+my $D = dirname(abs_path($P));
 
 my $V = '0.32';
 
@@ -438,26 +439,29 @@ our $allowed_asm_includes = qr{(?x:
 
 # Load common spelling mistakes and build regular expression list.
 my $misspellings;
-my @spelling_list;
 my %spelling_fix;
-open(my $spelling, '<', $spelling_file)
-    or die "$P: Can't open $spelling_file for reading: $!\n";
-while (<$spelling>) {
-	my $line = $_;
 
-	$line =~ s/\s*\n?$//g;
-	$line =~ s/^\s*//g;
+if (open(my $spelling, '<', $spelling_file)) {
+	my @spelling_list;
+	while (<$spelling>) {
+		my $line = $_;
 
-	next if ($line =~ m/^\s*#/);
-	next if ($line =~ m/^\s*$/);
+		$line =~ s/\s*\n?$//g;
+		$line =~ s/^\s*//g;
 
-	my ($suspect, $fix) = split(/\|\|/, $line);
+		next if ($line =~ m/^\s*#/);
+		next if ($line =~ m/^\s*$/);
+
+		my ($suspect, $fix) = split(/\|\|/, $line);
 
-	push(@spelling_list, $suspect);
-	$spelling_fix{$suspect} = $fix;
+		push(@spelling_list, $suspect);
+		$spelling_fix{$suspect} = $fix;
+	}
+	close($spelling);
+	$misspellings = join("|", @spelling_list);
+} else {
+	warn "No typos will be found - file '$spelling_file': $!\n";
 }
-close($spelling);
-$misspellings = join("|", @spelling_list);
 
 sub build_types {
 	my $mods = "(?x:  \n" . join("|\n  ", @modifierList) . "\n)";
@@ -2246,7 +2250,7 @@ sub process {
 		}
 
 # Check for various typo / spelling mistakes
-		if ($in_commit_log || $line =~ /^\+/) {
+		if (defined($misspellings) && ($in_commit_log || $line =~ /^\+/)) {
 			while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) {
 				my $typo = $1;
 				my $typo_fix = $spelling_fix{lc($typo)};
author Tested-by
#4 lore raw
Quoted 19 lines · Joe Perches
Quoted 18 lines · Jani Nikula
Quoted 16 lines · Joe Perches
Quoted 7 lines · Jani Nikula

Since commit 66b47b4a9dad00e45c049d79966de9a3a1f4d337

Author: Kees Cook <[email protected]>
Date:   Mon Oct 13 15:51:57 2014 -0700

checkpatch: look for common misspellings
checkpatch.pl dies with
checkpatch.pl: Can't open /path/to/spelling.txt for reading: No such file or directory

Quoted 5 lines

if it's called through a symlink in /path/to/checkpatch.pl pointing at the actual script.

Please fail graciously, and just ignore spelling if you can't find spelling.txt. Or better yet, follow the links if you can.

I agree it should fail better, but I'm also curious. Why you want to use a symlink?

Quoted 8 lines
Quoted 2 lines

Simply because I think having $HOME/bin in $PATH and a symlink there is better than the alternatives.

[]

Quoted 1 line

Reference: http://xkcd.com/1172/

:)

Try this:

Thanks,
Jani.

Quoted 77 lines
 scripts/checkpatch.pl | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)
scripts/checkpatch.pl +21 -17
index d94f5d8..a6354ec 100755
@@ -7,10 +7,11 @@
 
 use strict;
 use POSIX;
+use File::Basename;
+use Cwd 'abs_path';
 
 my $P = $0;
-$P =~ s@(.*)/@@g;
-my $D = $1;
+my $D = dirname(abs_path($P));
 
 my $V = '0.32';
 
@@ -438,26 +439,29 @@ our $allowed_asm_includes = qr{(?x:
 
 # Load common spelling mistakes and build regular expression list.
 my $misspellings;
-my @spelling_list;
 my %spelling_fix;
-open(my $spelling, '<', $spelling_file)
-    or die "$P: Can't open $spelling_file for reading: $!\n";
-while (<$spelling>) {
-	my $line = $_;
 
-	$line =~ s/\s*\n?$//g;
-	$line =~ s/^\s*//g;
+if (open(my $spelling, '<', $spelling_file)) {
+	my @spelling_list;
+	while (<$spelling>) {
+		my $line = $_;
 
-	next if ($line =~ m/^\s*#/);
-	next if ($line =~ m/^\s*$/);
+		$line =~ s/\s*\n?$//g;
+		$line =~ s/^\s*//g;
 
-	my ($suspect, $fix) = split(/\|\|/, $line);
+		next if ($line =~ m/^\s*#/);
+		next if ($line =~ m/^\s*$/);
+
+		my ($suspect, $fix) = split(/\|\|/, $line);
 
-	push(@spelling_list, $suspect);
-	$spelling_fix{$suspect} = $fix;
+		push(@spelling_list, $suspect);
+		$spelling_fix{$suspect} = $fix;
+	}
+	close($spelling);
+	$misspellings = join("|", @spelling_list);
+} else {
+	warn "No typos will be found - file '$spelling_file': $!\n";
 }
-close($spelling);
-$misspellings = join("|", @spelling_list);
 
 sub build_types {
 	my $mods = "(?x:  \n" . join("|\n  ", @modifierList) . "\n)";
@@ -2246,7 +2250,7 @@ sub process {
 		}
 
 # Check for various typo / spelling mistakes
-		if ($in_commit_log || $line =~ /^\+/) {
+		if (defined($misspellings) && ($in_commit_log || $line =~ /^\+/)) {
 			while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) {
 				my $typo = $1;
 				my $typo_fix = $spelling_fix{lc($typo)};
Signature · 1 line
Jani Nikula, Intel Open Source Technology Center
maintainer
#5 lore raw

PATCH 1/1 checkpatch: fix use via symlink, make missing spelling file non-fatal

In reply to Jani Nikula

Commit 66b47b4a9dad ("checkpatch: look for common misspellings") made it difficult to use checkpatch via a symlink.

Fix that and make a missing spelling.txt file non-fatal. Emit a warning when the spelling.txt file can not be opened.

Reference: http://xkcd.com/1172/

---
 scripts/checkpatch.pl | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)
scripts/checkpatch.pl +21 -17
index d94f5d8..a6354ec 100755
@@ -7,10 +7,11 @@
 
 use strict;
 use POSIX;
+use File::Basename;
+use Cwd 'abs_path';
 
 my $P = $0;
-$P =~ s@(.*)/@@g;
-my $D = $1;
+my $D = dirname(abs_path($P));
 
 my $V = '0.32';
 
@@ -438,26 +439,29 @@ our $allowed_asm_includes = qr{(?x:
 
 # Load common spelling mistakes and build regular expression list.
 my $misspellings;
-my @spelling_list;
 my %spelling_fix;
-open(my $spelling, '<', $spelling_file)
-    or die "$P: Can't open $spelling_file for reading: $!\n";
-while (<$spelling>) {
-	my $line = $_;
 
-	$line =~ s/\s*\n?$//g;
-	$line =~ s/^\s*//g;
+if (open(my $spelling, '<', $spelling_file)) {
+	my @spelling_list;
+	while (<$spelling>) {
+		my $line = $_;
 
-	next if ($line =~ m/^\s*#/);
-	next if ($line =~ m/^\s*$/);
+		$line =~ s/\s*\n?$//g;
+		$line =~ s/^\s*//g;
 
-	my ($suspect, $fix) = split(/\|\|/, $line);
+		next if ($line =~ m/^\s*#/);
+		next if ($line =~ m/^\s*$/);
+
+		my ($suspect, $fix) = split(/\|\|/, $line);
 
-	push(@spelling_list, $suspect);
-	$spelling_fix{$suspect} = $fix;
+		push(@spelling_list, $suspect);
+		$spelling_fix{$suspect} = $fix;
+	}
+	close($spelling);
+	$misspellings = join("|", @spelling_list);
+} else {
+	warn "No typos will be found - file '$spelling_file': $!\n";
 }
-close($spelling);
-$misspellings = join("|", @spelling_list);
 
 sub build_types {
 	my $mods = "(?x:  \n" . join("|\n  ", @modifierList) . "\n)";
@@ -2246,7 +2250,7 @@ sub process {
 		}
 
 # Check for various typo / spelling mistakes
-		if ($in_commit_log || $line =~ /^\+/) {
+		if (defined($misspellings) && ($in_commit_log || $line =~ /^\+/)) {
 			while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:$|[^a-z@])/gi) {
 				my $typo = $1;
 				my $typo_fix = $spelling_fix{lc($typo)};
Reviewed-by on v1 1/1
#6 lore raw

Re: [PATCH] checkpatch: fix use via symlink, make missing spelling file non-fatal

Quoted 11 lines · Joe Perches

Commit 66b47b4a9dad ("checkpatch: look for common misspellings") made it difficult to use checkpatch via a symlink.

Fix that and make a missing spelling.txt file non-fatal. Emit a warning when the spelling.txt file can not be opened.

Reference: http://xkcd.com/1172/

Thanks for fixing this. :)

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security
maintainer
#7 lore raw

Re: [PATCH] checkpatch: fix use via symlink, make missing spelling file non-fatal

In reply to Joe Perches

On Thu, Oct 23, 2014 at 10:29:11AM -0700, Joe Perches wrote:

[...]

scripts/checkpatch.pl line 14

Quoted 4 lines

my $P = $0;
-$P =~ s@(.*)/@@g;

scripts/checkpatch.pl +1 -1
-my $D = $1;
+my $D = dirname(abs_path($P));

That changes the value of $P, I don't know if that is intended:

  my $D = dirname(abs_path($0));

or

  my $D = abs_path($1);

perhaps to keep $P as it was.

-apw

maintainer
#8 lore raw

Re: [PATCH] checkpatch: fix use via symlink, make missing spelling file non-fatal

Quoted 10 lines · Andy Whitcroft

On Thu, Oct 23, 2014 at 10:29:11AM -0700, Joe Perches wrote:

[...]

scripts/checkpatch.pl line 14

Quoted 4 lines

my $P = $0;
-$P =~ s@(.*)/@@g;

scripts/checkpatch.pl +1 -1
-my $D = $1;
+my $D = dirname(abs_path($P));

That changes the value of $P, I don't know if that is intended:

Quoted 7 lines
  my $D = dirname(abs_path($0));

or

  my $D = abs_path($1);

perhaps to keep $P as it was.

I did it to show the executable passed on the cmdline better.

It changes --help and some warn/die messages.

It's not particularly important either way.

maintainer Acked-by
#9 lore raw

Re: [PATCH] checkpatch: fix use via symlink, make missing spelling file non-fatal

Quoted 17 lines · Joe Perches
Quoted 16 lines · Andy Whitcroft

On Thu, Oct 23, 2014 at 10:29:11AM -0700, Joe Perches wrote:

[...]

scripts/checkpatch.pl line 14

Quoted 4 lines

my $P = $0;
-$P =~ s@(.*)/@@g;

scripts/checkpatch.pl +1 -1
-my $D = $1;
+my $D = dirname(abs_path($P));

That changes the value of $P, I don't know if that is intended:

  my $D = dirname(abs_path($0));

or

  my $D = abs_path($1);
Quoted 7 lines
Quoted 1 line

perhaps to keep $P as it was.

I did it to show the executable passed on the cmdline better.

It changes --help and some warn/die messages.

It's not particularly important either way.

If it was intended then great. Either way is fine with me.

-apw