Chromium Code Reviews| 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..0867f1e24f855de05dd12174683dcc6925d9179d |
| --- /dev/null |
| +++ b/test/symlinks/gyptest-symlinks.py |
| @@ -0,0 +1,70 @@ |
| +#!/usr/bin/env python |
| + |
| +# Copyright (c) 2012 Google Inc. All rights reserved. |
|
Nico
2015/08/31 17:35:23
2015
lindleyf
2015/08/31 18:14:57
Done.
|
| +# 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 |
| + |
| +test = TestGyp.TestGyp() |
| + |
| +sys.path.insert(0, os.path.join(test._cwd, 'pylib')) |
| +import gyp.common |
| + |
| +# 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. |
| +try: |
| + gyp_file = tempfile.NamedTemporaryFile() |
|
Nico
2015/08/31 17:35:23
Use
with tempfile.NamedTemporaryFile() as gyp_fil
|
| + c_file = tempfile.NamedTemporaryFile() |
| + |
| + with open('hello.gyp') as orig_gyp_file: |
| + gyp_file.write(orig_gyp_file.read()) |
| + gyp_file.flush() |
|
Nico
2015/08/31 17:35:23
the with block closes the file which should flush
lindleyf
2015/08/31 18:14:57
Yes. The temporary file will be deleted when it is
|
| + with open('hello.c') as orig_c_file: |
| + c_file.write(orig_c_file.read()) |
| + c_file.flush() |
|
Nico
2015/08/31 17:35:23
same question
lindleyf
2015/08/31 18:14:58
Acknowledged.
|
| + |
| + 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) |
| + |
| + 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) |
| + |
| + test.run_gyp(symlink_gyp) |
| + |
| + test.build(symlink_gyp) |
| + |
| + test.run_built_executable('symlink_hello', stdout="Hello, world!\n") |
| + |
| + test.pass_test() |
| + |
| +except OSError as e: |
| + print >> sys.stderr, "gytest-symlinks.py warning: {0}".format(e) |
| + test.pass_test() # os.symlink may not be supported on all platforms. |
|
Nico
2015/08/31 17:35:23
Instead of this, put the test body into a
if sys.
Nico
2015/08/31 18:33:35
this wasn't addressed
lindleyf
2015/08/31 19:02:41
Missed that, done. Note that I'm not entirely conf
|
| + |