Skip to content

Commit 82fdd12

Browse files
jacob-kellermasahir0y
authored andcommitted
namespace: fix namespace.pl script to support relative paths
The namespace.pl script does not work properly if objtree is not set to an absolute path. The do_nm function is run from within the find function, which changes directories. Because of this, appending objtree, $File::Find::dir, and $source, will return a path which is not valid from the current directory. This used to work when objtree was set to an absolute path when using "make namespacecheck". It appears to have not worked when calling ./scripts/namespace.pl directly. This behavior was changed in 7e1c047 ("kbuild: Use relative path for $(objtree)", 2014-05-14) Rather than fixing the Makefile to set objtree to an absolute path, just fix namespace.pl to work when srctree and objtree are relative. Also fix the script to use an absolute path for these by default. Use the File::Spec module for this purpose. It's been part of perl 5 since 5.005. The curdir() function is used to get the current directory when the objtree and srctree aren't set in the environment. rel2abs() is used to convert possibly relative objtree and srctree environment variables to absolute paths. Finally, the catfile() function is used instead of string appending paths together, since this is more robust when joining paths together. Signed-off-by: Jacob Keller <[email protected]> Acked-by: Randy Dunlap <[email protected]> Tested-by: Randy Dunlap <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 01bb251 commit 82fdd12

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

scripts/namespace.pl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@
6565
use warnings;
6666
use strict;
6767
use File::Find;
68+
use File::Spec;
6869

6970
my $nm = ($ENV{'NM'} || "nm") . " -p";
7071
my $objdump = ($ENV{'OBJDUMP'} || "objdump") . " -s -j .comment";
71-
my $srctree = "";
72-
my $objtree = "";
73-
$srctree = "$ENV{'srctree'}/" if (exists($ENV{'srctree'}));
74-
$objtree = "$ENV{'objtree'}/" if (exists($ENV{'objtree'}));
72+
my $srctree = File::Spec->curdir();
73+
my $objtree = File::Spec->curdir();
74+
$srctree = File::Spec->rel2abs($ENV{'srctree'}) if (exists($ENV{'srctree'}));
75+
$objtree = File::Spec->rel2abs($ENV{'objtree'}) if (exists($ENV{'objtree'}));
7576

7677
if ($#ARGV != -1) {
7778
print STDERR "usage: $0 takes no parameters\n";
@@ -231,9 +232,9 @@ sub do_nm
231232
}
232233
($source = $basename) =~ s/\.o$//;
233234
if (-e "$source.c" || -e "$source.S") {
234-
$source = "$objtree$File::Find::dir/$source";
235+
$source = File::Spec->catfile($objtree, $File::Find::dir, $source)
235236
} else {
236-
$source = "$srctree$File::Find::dir/$source";
237+
$source = File::Spec->catfile($srctree, $File::Find::dir, $source)
237238
}
238239
if (! -e "$source.c" && ! -e "$source.S") {
239240
# No obvious source, exclude the object if it is conglomerate

0 commit comments

Comments
 (0)