| 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 supported 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', 'LINK', 'CC_host', 'CXX_host', 'LINK_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 | |
| 34 # ninja will use CXX_target as the linker regardless | |
| 35 test.must_contain_all_lines(test.stdout(), check_for) | 33 test.must_contain_all_lines(test.stdout(), check_for) |
| 36 | 34 |
| 37 | 35 |
| 38 test = TestGyp.TestGyp(formats=['ninja', 'make']) | 36 test = TestGyp.TestGyp(formats=['ninja', 'make']) |
| 39 | 37 |
| 40 def TestTargetOveride(): | 38 def TestTargetOveride(): |
| 41 expected = ['my_cc.py', 'my_cxx.py', 'FOO' ] | 39 expected = ['my_cc.py', 'my_cxx.py', 'FOO' ] |
| 42 if test.format != 'ninja': # ninja just uses $CC / $CXX as linker. | 40 if test.format != 'ninja': # ninja just uses $CC / $CXX as linker. |
| 43 expected.append('FOO_LINK') | 41 expected.append('FOO_LINK') |
| 44 | 42 |
| 45 # Check that CC, CXX and LD set target compiler | 43 # Check that CC, CXX and LD set target compiler |
| 46 oldenv = os.environ.copy() | 44 oldenv = os.environ.copy() |
| 47 try: | 45 try: |
| 48 os.environ['CC'] = 'python %s/my_cc.py FOO' % here | 46 os.environ['CC'] = 'python %s/my_cc.py FOO' % here |
| 49 os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here | 47 os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here |
| 50 os.environ['LINK'] = 'python %s/my_ld.py FOO_LINK' % here | 48 os.environ['LINK'] = 'python %s/my_ld.py FOO_LINK' % here |
| 51 | 49 |
| 52 CheckCompiler(test, 'compiler.gyp', expected, | 50 CheckCompiler(test, 'compiler-exe.gyp', expected, True) |
| 53 True) | |
| 54 finally: | 51 finally: |
| 55 os.environ.clear() | 52 os.environ.clear() |
| 56 os.environ.update(oldenv) | 53 os.environ.update(oldenv) |
| 57 | 54 |
| 58 # Run the same tests once the eviron has been restored. The | 55 # Run the same tests once the eviron has been restored. The |
| 59 # generated should have embedded all the settings in the | 56 # generated should have embedded all the settings in the |
| 60 # project files so the results should be the same. | 57 # project files so the results should be the same. |
| 61 CheckCompiler(test, 'compiler.gyp', expected, | 58 CheckCompiler(test, 'compiler-exe.gyp', expected, False) |
| 62 False) | 59 |
| 63 | 60 |
| 64 def TestTargetOverideCompilerOnly(): | 61 def TestTargetOverideCompilerOnly(): |
| 65 # Same test again but with that CC, CXX and not LD | 62 # Same test again but with that CC, CXX and not LD |
| 66 oldenv = os.environ.copy() | 63 oldenv = os.environ.copy() |
| 67 try: | 64 try: |
| 68 os.environ['CC'] = 'python %s/my_cc.py FOO' % here | 65 os.environ['CC'] = 'python %s/my_cc.py FOO' % here |
| 69 os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here | 66 os.environ['CXX'] = 'python %s/my_cxx.py FOO' % here |
| 70 | 67 |
| 71 CheckCompiler(test, 'compiler.gyp', | 68 CheckCompiler(test, 'compiler-exe.gyp', |
| 72 ['my_cc.py', 'my_cxx.py', 'FOO'], | 69 ['my_cc.py', 'my_cxx.py', 'FOO'], |
| 73 True) | 70 True) |
| 74 finally: | 71 finally: |
| 75 os.environ.clear() | 72 os.environ.clear() |
| 76 os.environ.update(oldenv) | 73 os.environ.update(oldenv) |
| 77 | 74 |
| 78 # Run the same tests once the eviron has been restored. The | 75 # Run the same tests once the eviron has been restored. The |
| 79 # generated should have embedded all the settings in the | 76 # generated should have embedded all the settings in the |
| 80 # project files so the results should be the same. | 77 # project files so the results should be the same. |
| 81 CheckCompiler(test, 'compiler.gyp', | 78 CheckCompiler(test, 'compiler-exe.gyp', |
| 82 ['my_cc.py', 'my_cxx.py', 'FOO'], | 79 ['my_cc.py', 'my_cxx.py', 'FOO'], |
| 83 False) | 80 False) |
| 84 | 81 |
| 85 | 82 |
| 86 def TestHostOveride(): | 83 def TestHostOveride(): |
| 87 expected = ['my_cc.py', 'my_cxx.py', 'HOST' ] | 84 expected = ['my_cc.py', 'my_cxx.py', 'HOST' ] |
| 88 if test.format != 'ninja': # ninja just uses $CC / $CXX as linker. | 85 if test.format != 'ninja': # ninja just uses $CC / $CXX as linker. |
| 89 expected.append('HOST_LINK') | 86 expected.append('HOST_LINK') |
| 90 | 87 |
| 91 # Check that CC_host sets host compilee | 88 # Check that CC_host sets host compilee |
| (...skipping 11 matching lines...) Expand all Loading... |
| 103 # generated should have embedded all the settings in the | 100 # generated should have embedded all the settings in the |
| 104 # project files so the results should be the same. | 101 # project files so the results should be the same. |
| 105 CheckCompiler(test, 'compiler-host.gyp', expected, False) | 102 CheckCompiler(test, 'compiler-host.gyp', expected, False) |
| 106 | 103 |
| 107 | 104 |
| 108 TestTargetOveride() | 105 TestTargetOveride() |
| 109 TestTargetOverideCompilerOnly() | 106 TestTargetOverideCompilerOnly() |
| 110 TestHostOveride() | 107 TestHostOveride() |
| 111 | 108 |
| 112 test.pass_test() | 109 test.pass_test() |
| OLD | NEW |