diff options
author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-11 20:52:45 +0000 |
---|---|---|
committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-11 20:52:45 +0000 |
commit | 0e83fbe7af5fceb4214c7c5bceffdcaf75506b16 (patch) | |
tree | fe0b4134fe2ebcaeecdd0de17ea70b32707ffec9 /native_client_sdk | |
parent | 3583de60e578768acc01083e77d499a9be12ad6b (diff) | |
download | chromium_src-0e83fbe7af5fceb4214c7c5bceffdcaf75506b16.zip chromium_src-0e83fbe7af5fceb4214c7c5bceffdcaf75506b16.tar.gz chromium_src-0e83fbe7af5fceb4214c7c5bceffdcaf75506b16.tar.bz2 |
[NaCl SDK] Fix create_nmf test failure on mac builder.
The /var directory on a mac is actually a symlink to /private/var. Normally
this isn't relevant.
One create_nmf_test changes to this directory, and calls os.path.abspath(''),
which returns '/private/var/...', and later uses os.path.relpath to find the
relative path to a file in that directory tree.
This fails to do the right thing, because relpath only uses the path name (not
the filesystem) to determine relative paths.
The fix here is to use os.path.realpath to create a canonical path whenever we
want a relative path. I've also removed other calls to os.path.abspath that
really should be os.path.realpath.
BUG=none
R=bradnelson@google.com, sbc@chromium.org, bradnelson@chromium.org
TEST=create_nmf_test.py
Review URL: https://codereview.chromium.org/195493003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256307 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rwxr-xr-x | native_client_sdk/src/tools/create_nmf.py | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/native_client_sdk/src/tools/create_nmf.py b/native_client_sdk/src/tools/create_nmf.py index 2f7ec35..b19b7d0 100755 --- a/native_client_sdk/src/tools/create_nmf.py +++ b/native_client_sdk/src/tools/create_nmf.py @@ -90,8 +90,27 @@ def PosixRelPath(path, start): e.g. For Windows: "foo\\bar\\baz.blah", "foo" => "bar/baz.blah" For Mac/Linux: "foo/bar/baz.blah", "foo" => "bar/baz.blah" + + NOTE: This function uses os.path.realpath to create a canonical path for + |path| and |start|. + """ + real_path = os.path.realpath(path) + real_start = os.path.realpath(start) + return MakePosixPath(os.path.relpath(real_path, real_start)) + + +def DirectoryTreeContainsFile(dirname, filename): + """Returns True if a file is in a directory, or any of that directory's + subdirectories recursively. + + e.g. + DirectoryTreeContainsFile("foo", "foo/quux.txt") => True + DirectoryTreeContainsFile("foo", "foo/bar/baz/blah.txt") => True + DirectoryTreeContainsFile("foo", "bar/blah.txt") => False """ - return MakePosixPath(os.path.relpath(path, start)) + real_dirname = os.path.realpath(dirname) + real_filename = os.path.realpath(filename) + return real_filename.startswith(real_dirname) def MakeDir(dirname): @@ -253,19 +272,18 @@ class NmfUtils(object): arch_to_main_dir = {} for main_file in main_nexes: arch, _ = ParseElfHeader(main_file) - main_dir = os.path.dirname(os.path.abspath(main_file)) + main_dir = os.path.dirname(main_file) main_dir = PosixRelPath(main_dir, self.nmf_root) if main_dir == '.': main_dir = '' arch_to_main_dir[arch] = main_dir for arch_file in self.needed.itervalues(): - path = os.path.normcase(os.path.abspath(arch_file.path)) prefix = '' - if os.path.abspath(path).startswith(os.path.abspath(self.nmf_root)): + if DirectoryTreeContainsFile(self.nmf_root, arch_file.path): # This file is already in the nmf_root tree, so it does not need to be # staged. Just make the URL relative to the .nmf. - url = PosixRelPath(path, self.nmf_root) + url = PosixRelPath(arch_file.path, self.nmf_root) else: # This file is outside of the nmf_root subtree, so it needs to be # staged. Its path should be relative to the main .nexe with the same @@ -295,8 +313,8 @@ class NmfUtils(object): source = arch_file.path destination = os.path.join(destination_dir, arch_file.url) - if (os.path.normcase(os.path.abspath(source)) == - os.path.normcase(os.path.abspath(destination))): + if (os.path.normcase(os.path.realpath(source)) == + os.path.normcase(os.path.realpath(destination))): continue # make sure target dir exists |