OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 Google Inc. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 """ | 5 """ |
6 Verifies that the user can override the compiler and linker using CC/CXX/LD | 6 Verifies that the user can override the compiler and linker using CC/CXX/LD |
7 environment variables. | 7 environment variables. |
8 """ | 8 """ |
9 | 9 |
10 import TestGyp | 10 import TestGyp |
11 import os | 11 import os |
12 import copy | 12 import copy |
13 import sys | 13 import sys |
14 | 14 |
15 here = os.path.dirname(os.path.abspath(__file__)) | 15 here = os.path.dirname(os.path.abspath(__file__)) |
16 | 16 |
17 if sys.platform == 'win32': | 17 if sys.platform == 'win32': |
18 # cross compiling not support by ninja on windows | 18 # cross compiling not support by ninja on windows |
19 # and make not supported on windows at all. | 19 # and make not supported on windows at all. |
20 sys.exit(0) | 20 sys.exit(0) |
21 | 21 |
22 # Clear any existing compiler related env vars. | 22 # Clear any existing compiler related env vars. |
23 for key in 'CC', 'CXX', 'LD', 'CC_host', 'CXX_host', 'LD_host': | 23 for key in ['CC', 'CXX', 'LINK', 'CC_host', 'CXX_host', 'LINK_host']: |
24 if key in os.environ: | 24 if key in os.environ: |
25 del os.environ[key] | 25 del os.environ[key] |
26 | 26 |
27 | 27 |
28 def CheckCompiler(test, gypfile, check_for, run_gyp): | 28 def CheckCompiler(test, gypfile, check_for, run_gyp): |
29 if run_gyp: | 29 if run_gyp: |
30 test.run_gyp(gypfile) | 30 test.run_gyp(gypfile) |
31 test.build(gypfile) | 31 test.build(gypfile) |
32 | 32 |
33 # We can't test to presence of my_ld.py in the output since | 33 # We can't test to presence of my_ld.py in the output since |
34 # ninja will use CXX_target as the linker regardless | 34 # ninja will use CXX_target as the linker regardless |
35 test.must_contain_all_lines(test.stdout(), check_for) | 35 test.must_contain_all_lines(test.stdout(), check_for) |
36 | 36 |
37 | 37 |
38 test = TestGyp.TestGyp(formats=['ninja', 'make']) | 38 test = TestGyp.TestGyp(formats=['ninja', 'make']) |
39 | 39 |
40 def TestTargetOveride(): | 40 def TestTargetOveride(): |
| 41 expected = ['my_cc.py', 'my_cxx.py', 'FOO' ] |
| 42 global test |
| 43 if test.format != 'ninja': # ninja just uses $CC / $CXX as linker. |
| 44 expected.append('FOO_LINK') |
| 45 |
41 # Check that CC, CXX and LD set target compiler | 46 # Check that CC, CXX and LD set target compiler |
42 oldenv = os.environ.copy() | 47 oldenv = os.environ.copy() |
43 try: | 48 try: |
44 os.environ['CC'] = 'python %s/my_cc.py FOO' % here | 49 os.environ['CC'] = 'python %s/my_cc.py FOO' % here |
45 os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here | 50 os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here |
46 os.environ['LD'] = 'python %s/my_ld.py FOO_LINK' % here | 51 os.environ['LINK'] = 'python %s/my_ld.py FOO_LINK' % here |
47 | 52 |
48 CheckCompiler(test, 'compiler.gyp', | 53 CheckCompiler(test, 'compiler.gyp', expected, |
49 ['my_cc.py', 'my_cxx.py', 'FOO', 'FOO_LINK'], | |
50 True) | 54 True) |
51 finally: | 55 finally: |
52 os.environ.clear() | 56 os.environ.clear() |
53 os.environ.update(oldenv) | 57 os.environ.update(oldenv) |
54 | 58 |
55 # Run the same tests once the eviron has been restored. The | 59 # Run the same tests once the eviron has been restored. The |
56 # generated should have embedded all the settings in the | 60 # generated should have embedded all the settings in the |
57 # project files so the results should be the same. | 61 # project files so the results should be the same. |
58 CheckCompiler(test, 'compiler.gyp', | 62 CheckCompiler(test, 'compiler.gyp', expected, |
59 ['my_cc.py', 'my_cxx.py', 'FOO', 'FOO_LINK'], | |
60 False) | 63 False) |
61 | 64 |
62 def TestTargetOverideCompilerOnly(): | 65 def TestTargetOverideCompilerOnly(): |
63 # Same test again but with that CC, CXX and not LD | 66 # Same test again but with that CC, CXX and not LD |
64 oldenv = os.environ.copy() | 67 oldenv = os.environ.copy() |
65 try: | 68 try: |
66 os.environ['CC'] = 'python %s/my_cc.py FOO' % here | 69 os.environ['CC'] = 'python %s/my_cc.py FOO' % here |
67 os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here | 70 os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here |
68 | 71 |
69 CheckCompiler(test, 'compiler.gyp', | 72 CheckCompiler(test, 'compiler.gyp', |
70 ['my_cc.py', 'my_cxx.py', 'FOO'], | 73 ['my_cc.py', 'my_cxx.py', 'FOO'], |
71 True) | 74 True) |
72 finally: | 75 finally: |
73 os.environ.clear() | 76 os.environ.clear() |
74 os.environ.update(oldenv) | 77 os.environ.update(oldenv) |
75 | 78 |
76 # Run the same tests once the eviron has been restored. The | 79 # Run the same tests once the eviron has been restored. The |
77 # generated should have embedded all the settings in the | 80 # generated should have embedded all the settings in the |
78 # project files so the results should be the same. | 81 # project files so the results should be the same. |
79 CheckCompiler(test, 'compiler.gyp', | 82 CheckCompiler(test, 'compiler.gyp', |
80 ['my_cc.py', 'my_cxx.py', 'FOO'], | 83 ['my_cc.py', 'my_cxx.py', 'FOO'], |
81 False) | 84 False) |
82 | 85 |
83 | 86 |
84 def TestHostOveride(): | 87 def TestHostOveride(): |
| 88 expected = ['my_cc.py', 'my_cxx.py', 'HOST' ] |
| 89 global test |
| 90 if test.format != 'ninja': # ninja just uses $CC / $CXX as linker. |
| 91 expected.append('HOST_LINK') |
| 92 |
85 # Check that CC_host sets host compilee | 93 # Check that CC_host sets host compilee |
86 oldenv = os.environ.copy() | 94 oldenv = os.environ.copy() |
87 try: | 95 try: |
88 os.environ['CC_host'] = 'python %s/my_cc.py HOST' % here | 96 os.environ['CC_host'] = 'python %s/my_cc.py HOST' % here |
89 os.environ['CXX_host'] = 'python %s/my_cxx.py HOST' % here | 97 os.environ['CXX_host'] = 'python %s/my_cxx.py HOST' % here |
90 os.environ['LD_host'] = 'python %s/my_ld.py HOST_LINK' % here | 98 os.environ['LINK_host'] = 'python %s/my_ld.py HOST_LINK' % here |
91 CheckCompiler(test, 'compiler-host.gyp', | 99 CheckCompiler(test, 'compiler-host.gyp', expected, True) |
92 ['my_cc.py', 'my_cxx.py', 'HOST', 'HOST_LINK'], | |
93 True) | |
94 finally: | 100 finally: |
95 os.environ.clear() | 101 os.environ.clear() |
96 os.environ.update(oldenv) | 102 os.environ.update(oldenv) |
97 | 103 |
98 # Run the same tests once the eviron has been restored. The | 104 # Run the same tests once the eviron has been restored. The |
99 # generated should have embedded all the settings in the | 105 # generated should have embedded all the settings in the |
100 # project files so the results should be the same. | 106 # project files so the results should be the same. |
101 CheckCompiler(test, 'compiler-host.gyp', | 107 CheckCompiler(test, 'compiler-host.gyp', expected, False) |
102 ['my_cc.py', 'my_cxx.py', 'HOST', 'HOST_LINK'], | |
103 False) | |
104 | 108 |
105 | 109 |
106 TestTargetOveride() | 110 TestTargetOveride() |
107 TestTargetOverideCompilerOnly() | 111 TestTargetOverideCompilerOnly() |
108 TestHostOveride() | 112 TestHostOveride() |
109 | 113 |
110 test.pass_test() | 114 test.pass_test() |
OLD | NEW |