OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 Google Inc. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 """ | |
6 Verifies that the user can override the compiler and linker using | |
7 CC/CXX/NM/READELF environment variables. | |
8 """ | |
9 | |
10 import TestGyp | |
11 import os | |
12 import copy | |
13 import sys | |
14 | |
15 here = os.path.dirname(os.path.abspath(__file__)) | |
16 | |
17 if sys.platform == 'win32': | |
18 # cross compiling not support by ninja on windows | |
Nico
2014/08/27 14:27:05
*supported
Dimi Shahbaz
2014/08/27 18:25:51
Done. (And fixed in adjacent file where I copied t
| |
19 # and make not supported on windows at all. | |
20 sys.exit(0) | |
21 | |
22 # Clear any existing compiler related env vars. | |
23 for key in ['CC', 'CXX', 'LINK', 'CC_host', 'CXX_host', 'LINK_host', | |
24 'NM_target', 'READELF_target']: | |
25 if key in os.environ: | |
26 del os.environ[key] | |
27 | |
28 | |
29 def CheckCompiler(test, gypfile, check_for, run_gyp): | |
30 if run_gyp: | |
31 test.run_gyp(gypfile) | |
32 test.build(gypfile) | |
33 | |
34 test.must_contain_all_lines(test.stdout(), check_for) | |
35 | |
36 | |
37 test = TestGyp.TestGyp(formats=['ninja']) | |
38 # Must set the test format to something with a flavor (the part after the '-') | |
39 # in order to test the desired behavior. Since we want to run a non-host | |
40 # toolchain, we have to set the flavor to something that the ninja generator | |
41 # doesn't know about, so it doesn't default to the host-specific tools (e.g., | |
42 # 'otool' on mac to generate the .TOC). | |
43 # | |
44 # Note that we can't just pass format=['ninja-some_toolchain'] to the | |
45 # constructor above, because then this test wouldn't be recognized as a ninja | |
46 # format test. | |
47 test.formats = ['ninja-some_toolchain'] | |
48 | |
49 | |
50 def TestTargetOverideSharedLib(): | |
51 # The std output from nm and readelf is redirected to files, so we can't | |
52 # expect their output to appear. Instead, check for the files they create to | |
53 # see if they actually ran. | |
54 expected = ['my_cc.py', 'my_cxx.py', 'FOO'] | |
55 | |
56 # Check that CC, CXX, NM_target, READELF_target, set target compiler | |
57 oldenv = os.environ.copy() | |
58 try: | |
59 os.environ['CC'] = 'python %s/my_cc.py FOO' % here | |
60 os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here | |
61 os.environ['NM'] = 'python %s/my_nm.py' % here | |
62 os.environ['READELF'] = 'python %s/my_readelf.py' % here | |
63 | |
64 CheckCompiler(test, 'compiler-shared-lib.gyp', expected, True) | |
65 test.must_contain(test.built_file_path('RAN_MY_NM'), 'RAN_MY_NM') | |
66 test.must_contain(test.built_file_path('RAN_MY_READELF'), 'RAN_MY_READELF') | |
Nico
2014/08/27 14:27:05
this is going to fail on os x
Dimi Shahbaz
2014/08/27 18:25:51
it does pass on mac, and the key is that the forma
| |
67 test.unlink(test.built_file_path('RAN_MY_NM')) | |
68 test.unlink(test.built_file_path('RAN_MY_READELF')) | |
69 finally: | |
70 os.environ.clear() | |
71 os.environ.update(oldenv) | |
Nico
2014/08/27 14:27:05
I think we have a context manager for environment
Dimi Shahbaz
2014/08/27 18:25:51
Yup, very nice.
| |
72 | |
73 # Run the same tests once the eviron has been restored. The | |
74 # generated should have embedded all the settings in the | |
75 # project files so the results should be the same. | |
76 CheckCompiler(test, 'compiler-shared-lib.gyp', expected, False) | |
77 test.must_contain(test.built_file_path('RAN_MY_NM'), 'RAN_MY_NM') | |
78 test.must_contain(test.built_file_path('RAN_MY_READELF'), 'RAN_MY_READELF') | |
79 | |
80 | |
81 TestTargetOverideSharedLib() | |
82 test.pass_test() | |
OLD | NEW |