OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 | |
3 # Copyright (c) 2012 Google Inc. All rights reserved. | |
Nico
2015/08/31 17:35:23
2015
lindleyf
2015/08/31 18:14:57
Done.
| |
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 test = TestGyp.TestGyp() | |
25 | |
26 sys.path.insert(0, os.path.join(test._cwd, 'pylib')) | |
27 import gyp.common | |
28 | |
29 # Copy hello.gyp and hello.c to temporary named files, which will then be | |
30 # symlinked back and processed. Note that we don't ask gyp to touch the original | |
31 # files at all; they are only there as source material for the copy. That's why | |
32 # hello.gyp references symlink_hello.c instead of hello.c. | |
33 try: | |
34 gyp_file = tempfile.NamedTemporaryFile() | |
Nico
2015/08/31 17:35:23
Use
with tempfile.NamedTemporaryFile() as gyp_fil
| |
35 c_file = tempfile.NamedTemporaryFile() | |
36 | |
37 with open('hello.gyp') as orig_gyp_file: | |
38 gyp_file.write(orig_gyp_file.read()) | |
39 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
| |
40 with open('hello.c') as orig_c_file: | |
41 c_file.write(orig_c_file.read()) | |
42 c_file.flush() | |
Nico
2015/08/31 17:35:23
same question
lindleyf
2015/08/31 18:14:58
Acknowledged.
| |
43 | |
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 try: | |
52 os.makedirs(outdir) | |
53 except OSError: | |
54 if not os.path.isdir(outdir): | |
55 raise | |
56 os.symlink(gyp_file.name, symlink_gyp) | |
57 os.symlink(c_file.name, symlink_c) | |
58 | |
59 test.run_gyp(symlink_gyp) | |
60 | |
61 test.build(symlink_gyp) | |
62 | |
63 test.run_built_executable('symlink_hello', stdout="Hello, world!\n") | |
64 | |
65 test.pass_test() | |
66 | |
67 except OSError as e: | |
68 print >> sys.stderr, "gytest-symlinks.py warning: {0}".format(e) | |
69 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
| |
70 | |
OLD | NEW |