CChenX / gyp

Automatically exported from code.google.com/p/gyp
0 stars 0 forks source link

ninja can't handle output directories that are symlinks #314

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
$ pwd
/var/cache/distfiles/target/chrome-src-internal/src
$ ls -ld c
lrwxrwxrwx 1 chrome-bot portage 60 2012-12-14 15:43 c -> 
/var/cache/chromeos-chrome/chrome-src-internal/src/out_lumpy
$ ninja -C c/Release chrome
ninja: Entering directory `c/Release'
ninja: error: '../../chrome/app/chrome_exe_main_aura.cc', needed by 
'obj/chrome/app/chrome.chrome_exe_main_aura.o', missing and no known rule to 
make it
$ ls -l chrome/app/chrome_exe_main_aura.cc
-rw-r--r-- 1 chrome-bot portage 608 2012-12-12 19:34 
chrome/app/chrome_exe_main_aura.cc

The problem here is that Ninja is looking in 
/var/cache/chromeos-chrome/chrome-src-internal/chrome/app/chrome_exe_main_aura.c
c (relative to the output directory) when it should be looking at 
/var/cache/distfiles/target/chrome-src-internal/src/chrome/app/chrome_exe_main_a
ura.cc (relative to the source directory.)

Original issue reported on code.google.com by davidjames@chromium.org on 15 Dec 2012 at 12:07

GoogleCodeExporter commented 9 years ago
This is because your output directory is a symlink.

I hear that using `sudo mount --bind /path/to/out /work/chrome/src/out` instead 
of a symlink can work around this (but apparently this doesn't work well in 
chroots).

So that's a possible workaround.

This patch lets ninja detect when the output directory is a symlink and makes 
it write absolute paths in this case (from gutschke@), but it needs a test:

diff a/tools/gyp/pylib/gyp/generator/ninja.py 
b/tools/gyp/pylib/gyp/generator/ninja.py
--- a/tools/gyp/pylib/gyp/generator/ninja.py
+++ b/tools/gyp/pylib/gyp/generator/ninja.py
@@ -108,7 +108,14 @@ def InvertRelativePath(path):
   # Only need to handle relative paths into subdirectories for now.
   assert '..' not in path, path
   depth = len(path.split(os.path.sep))
-  return os.path.sep.join(['..'] * depth)
+  inverse_path = os.path.sep.join(['..'] * depth)
+  if os.path.samefile(os.path.join(path, inverse_path), os.getcwd()):
+    return inverse_path
+  else:
+    # Symbolic links prevent us from computing a relative inverse path.
+    # Return the current directory instead, as it provides an equivalent
+    # absolute path.
+    return os.getcwd()

Original comment by thakis@chromium.org on 15 Dec 2012 at 5:07

GoogleCodeExporter commented 9 years ago
Hi Nico,

The patch above does not work for me. However, I've attached a new patch that 
works and I've verified confirmed allows me to compile ninja with symlinks in 
the Chrome OS chroot. Please see the attached patch.

Original comment by davidjames@google.com on 20 Dec 2012 at 6:52

Attachments:

GoogleCodeExporter commented 9 years ago
davidjames fixes this in gyp r1555.

Original comment by thakis@chromium.org on 26 Dec 2012 at 4:50