Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Unified Diff: test/symlinks/gyptest-symlinks.py

Issue 1365163002: Make the ninja generator handle symlinked paths correctly. (Closed) Base URL: https://chromium.googlesource.com/external/gyp@master
Patch Set: Revert CPPFLAGS_host, they will be moved to a separate CL. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pylib/gyp/generator/ninja.py ('k') | test/symlinks/hello.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/symlinks/gyptest-symlinks.py
diff --git a/test/symlinks/gyptest-symlinks.py b/test/symlinks/gyptest-symlinks.py
new file mode 100755
index 0000000000000000000000000000000000000000..eb63d2671c0da2b4025f739117b5898eee6b32fb
--- /dev/null
+++ b/test/symlinks/gyptest-symlinks.py
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2015 Google Inc. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Test that RelativePath(s, d) doesn't return a path starting with '..' when
+s is textually below d, but is also a symlink to a file that is not below d.
+
+Returning .. in this case would break the Ninja generator in such a case,
+because it computes output directories by concatenating paths, and concat'ing
+a path starting with .. can unexpectedly erase other parts of the path. It's
+difficult to test this directly since the test harness assumes toplevel_dir is
+the root of the repository, but this test should at least verify that the
+required behavior doesn't change.
+"""
+
+import TestGyp
+import os
+import sys
+import tempfile
+
+if sys.platform != 'win32':
+ test = TestGyp.TestGyp()
+
+ sys.path.insert(0, os.path.join(test._cwd, 'pylib'))
+ import gyp.common
scottmg 2015/09/24 22:12:16 oh, what's this for?
lindleyf 2015/09/24 22:15:50 Good catch, I think that's left over from a previo
+
+ # Copy hello.gyp and hello.c to temporary named files, which will then be
+ # symlinked back and processed. Note that we don't ask gyp to touch the
+ # original files at all; they are only there as source material for the copy.
+ # That's why hello.gyp references symlink_hello.c instead of hello.c.
+ with tempfile.NamedTemporaryFile() as gyp_file:
+ with tempfile.NamedTemporaryFile() as c_file:
+ with open('hello.gyp') as orig_gyp_file:
+ gyp_file.write(orig_gyp_file.read())
+ gyp_file.flush()
+ with open('hello.c') as orig_c_file:
+ c_file.write(orig_c_file.read())
+ c_file.flush()
+ # We need to flush the files because we want to read them before closing
+ # them, since when they are closed they will be deleted.
+
+ # Don't proceed with the test on a system that doesn't let you read from
+ # a still-open temporary file.
+ if os.path.getsize(gyp_file.name) == 0:
+ raise OSError("Copy to temporary file didn't work.")
+
+ symlink_gyp = test.built_file_path('symlink_hello.gyp')
+ symlink_c = test.built_file_path('symlink_hello.c')
+ outdir = os.path.dirname(symlink_gyp)
+
+ # Make sure the outdir exists.
+ try:
+ os.makedirs(outdir)
+ except OSError:
+ if not os.path.isdir(outdir):
+ raise
+ os.symlink(gyp_file.name, symlink_gyp)
+ os.symlink(c_file.name, symlink_c)
+
+ # Run gyp on the symlinked files.
+ test.run_gyp(symlink_gyp, chdir=outdir)
+ test.build(symlink_gyp, chdir=outdir)
+ test.run_built_executable('symlink_hello', stdout="Hello, world!\n",
+ chdir=outdir)
+
+ test.pass_test()
+
« no previous file with comments | « pylib/gyp/generator/ninja.py ('k') | test/symlinks/hello.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698