OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 # Copyright (c) 2015 Google Inc. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """ |
| 8 Test that RelativePath(s, d) doesn't return a path starting with '..' when |
| 9 s is textually below d, but is also a symlink to a file that is not below d. |
| 10 |
| 11 Returning .. in this case would break the Ninja generator in such a case, |
| 12 because it computes output directories by concatenating paths, and concat'ing |
| 13 a path starting with .. can unexpectedly erase other parts of the path. It's |
| 14 difficult to test this directly since the test harness assumes toplevel_dir is |
| 15 the root of the repository, but this test should at least verify that the |
| 16 required behavior doesn't change. |
| 17 """ |
| 18 |
| 19 import TestGyp |
| 20 import os |
| 21 import sys |
| 22 import tempfile |
| 23 |
| 24 if sys.platform != 'win32': |
| 25 test = TestGyp.TestGyp() |
| 26 |
| 27 # Copy hello.gyp and hello.c to temporary named files, which will then be |
| 28 # symlinked back and processed. Note that we don't ask gyp to touch the |
| 29 # original files at all; they are only there as source material for the copy. |
| 30 # That's why hello.gyp references symlink_hello.c instead of hello.c. |
| 31 with tempfile.NamedTemporaryFile() as gyp_file: |
| 32 with tempfile.NamedTemporaryFile() as c_file: |
| 33 with open('hello.gyp') as orig_gyp_file: |
| 34 gyp_file.write(orig_gyp_file.read()) |
| 35 gyp_file.flush() |
| 36 with open('hello.c') as orig_c_file: |
| 37 c_file.write(orig_c_file.read()) |
| 38 c_file.flush() |
| 39 # We need to flush the files because we want to read them before closing |
| 40 # them, since when they are closed they will be deleted. |
| 41 |
| 42 # Don't proceed with the test on a system that doesn't let you read from |
| 43 # a still-open temporary file. |
| 44 if os.path.getsize(gyp_file.name) == 0: |
| 45 raise OSError("Copy to temporary file didn't work.") |
| 46 |
| 47 symlink_gyp = test.built_file_path('symlink_hello.gyp') |
| 48 symlink_c = test.built_file_path('symlink_hello.c') |
| 49 outdir = os.path.dirname(symlink_gyp) |
| 50 |
| 51 # Make sure the outdir exists. |
| 52 try: |
| 53 os.makedirs(outdir) |
| 54 except OSError: |
| 55 if not os.path.isdir(outdir): |
| 56 raise |
| 57 os.symlink(gyp_file.name, symlink_gyp) |
| 58 os.symlink(c_file.name, symlink_c) |
| 59 |
| 60 # Run gyp on the symlinked files. |
| 61 test.run_gyp(symlink_gyp, chdir=outdir) |
| 62 test.build(symlink_gyp, chdir=outdir) |
| 63 test.run_built_executable('symlink_hello', stdout="Hello, world!\n", |
| 64 chdir=outdir) |
| 65 |
| 66 test.pass_test() |
| 67 |
OLD | NEW |