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.
6 Verifies that the user can override the compiler and linker using
7 CC/CXX/NM/READELF environment variables.
15 here = os.path.dirname(os.path.abspath(__file__))
17 if sys.platform == 'win32':
18 # cross compiling not supported by ninja on windows
19 # and make not supported on windows at all.
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']:
29 def CheckCompiler(test, gypfile, check_for, run_gyp):
34 test.must_contain_all_lines(test.stdout(), check_for)
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).
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
47 test.formats = ['ninja-some_flavor']
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']
56 # Check that CC, CXX, NM, READELF, set target compiler
57 env = {'CC': 'python %s/my_cc.py FOO' % here,
58 'CXX': 'python %s/my_cxx.py FOO' % here,
59 'NM': 'python %s/my_nm.py' % here,
60 'READELF': 'python %s/my_readelf.py' % here}
62 with TestGyp.LocalEnv(env):
63 CheckCompiler(test, 'compiler-shared-lib.gyp', expected, True)
64 test.must_contain(test.built_file_path('RAN_MY_NM'), 'RAN_MY_NM')
65 test.must_contain(test.built_file_path('RAN_MY_READELF'), 'RAN_MY_READELF')
66 test.unlink(test.built_file_path('RAN_MY_NM'))
67 test.unlink(test.built_file_path('RAN_MY_READELF'))
69 # Run the same tests once the eviron has been restored. The generated
70 # projects should have embedded all the settings in the project files so the
71 # results should be the same.
72 CheckCompiler(test, 'compiler-shared-lib.gyp', expected, False)
73 test.must_contain(test.built_file_path('RAN_MY_NM'), 'RAN_MY_NM')
74 test.must_contain(test.built_file_path('RAN_MY_READELF'), 'RAN_MY_READELF')
77 TestTargetOverideSharedLib()