Commit 82fdd12b authored by Jacob Keller's avatar Jacob Keller Committed by Masahiro Yamada

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 7e1c0477 ("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: default avatarJacob Keller <jacob.e.keller@intel.com>
Acked-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Tested-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
parent 01bb2515
...@@ -65,13 +65,14 @@ ...@@ -65,13 +65,14 @@
use warnings; use warnings;
use strict; use strict;
use File::Find; use File::Find;
use File::Spec;
my $nm = ($ENV{'NM'} || "nm") . " -p"; my $nm = ($ENV{'NM'} || "nm") . " -p";
my $objdump = ($ENV{'OBJDUMP'} || "objdump") . " -s -j .comment"; my $objdump = ($ENV{'OBJDUMP'} || "objdump") . " -s -j .comment";
my $srctree = ""; my $srctree = File::Spec->curdir();
my $objtree = ""; my $objtree = File::Spec->curdir();
$srctree = "$ENV{'srctree'}/" if (exists($ENV{'srctree'})); $srctree = File::Spec->rel2abs($ENV{'srctree'}) if (exists($ENV{'srctree'}));
$objtree = "$ENV{'objtree'}/" if (exists($ENV{'objtree'})); $objtree = File::Spec->rel2abs($ENV{'objtree'}) if (exists($ENV{'objtree'}));
if ($#ARGV != -1) { if ($#ARGV != -1) {
print STDERR "usage: $0 takes no parameters\n"; print STDERR "usage: $0 takes no parameters\n";
...@@ -231,9 +232,9 @@ sub do_nm ...@@ -231,9 +232,9 @@ sub do_nm
} }
($source = $basename) =~ s/\.o$//; ($source = $basename) =~ s/\.o$//;
if (-e "$source.c" || -e "$source.S") { if (-e "$source.c" || -e "$source.S") {
$source = "$objtree$File::Find::dir/$source"; $source = File::Spec->catfile($objtree, $File::Find::dir, $source)
} else { } else {
$source = "$srctree$File::Find::dir/$source"; $source = File::Spec->catfile($srctree, $File::Find::dir, $source)
} }
if (! -e "$source.c" && ! -e "$source.S") { if (! -e "$source.c" && ! -e "$source.S") {
# No obvious source, exclude the object if it is conglomerate # No obvious source, exclude the object if it is conglomerate
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment