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 make_global_settings can be used to override the 7 compiler settings. 8 """ 9 10 import TestGyp 11 import os 12 import copy 13 import sys 14 from string import Template 15 16 17 if sys.platform == 'win32': 18 # cross compiling not support by ninja on windows 19 # and make not supported on windows at all. 20 sys.exit(0) 21 22 test = TestGyp.TestGyp(formats=['ninja', 'make']) 23 24 gypfile = 'compiler-global-settings.gyp' 25 26 replacements = { 'PYTHON': '/usr/bin/python', 'PWD': os.getcwd()} 27 28 # Process the .in gyp file to produce the final gyp file 29 # since we need to include absolute paths in the make_global_settings 30 # section. 31 replacements['TOOLSET'] = 'target' 32 s = Template(open(gypfile + '.in').read()) 33 output = open(gypfile, 'w') 34 output.write(s.substitute(replacements)) 35 output.close() 36 37 old_env = dict(os.environ) 38 os.environ['GYP_CROSSCOMPILE'] = '1' 39 test.run_gyp(gypfile) 40 os.environ.clear() 41 os.environ.update(old_env) 42 43 test.build(gypfile) 44 test.must_contain_all_lines(test.stdout(), ['my_cc.py', 'my_cxx.py', 'FOO']) 45 46 # Same again but with the host toolset. 47 replacements['TOOLSET'] = 'host' 48 s = Template(open(gypfile + '.in').read()) 49 output = open(gypfile, 'w') 50 output.write(s.substitute(replacements)) 51 output.close() 52 53 old_env = dict(os.environ) 54 os.environ['GYP_CROSSCOMPILE'] = '1' 55 test.run_gyp(gypfile) 56 os.environ.clear() 57 os.environ.update(old_env) 58 59 test.build(gypfile) 60 test.must_contain_all_lines(test.stdout(), ['my_cc.py', 'my_cxx.py', 'BAR']) 61 62 # Check that CC_host overrides make_global_settings 63 old_env = dict(os.environ) 64 os.environ['CC_host'] = '%s %s/my_cc.py SECRET' % (replacements['PYTHON'], 65 replacements['PWD']) 66 test.run_gyp(gypfile) 67 os.environ.clear() 68 os.environ.update(old_env) 69 70 test.build(gypfile) 71 test.must_contain_all_lines(test.stdout(), ['SECRET', 'my_cxx.py', 'BAR']) 72 73 test.pass_test() 74