Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame^] | 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 | # The xcode generator chokes on the 'host' toolset. Skip the rest of |
| 47 | # this test (cf. https://code.google.com/p/gyp/issues/detail?id=454). |
| 48 | if test.format == 'xcode-ninja': |
| 49 | test.pass_test() |
| 50 | |
| 51 | # Same again but with the host toolset. |
| 52 | replacements['TOOLSET'] = 'host' |
| 53 | s = Template(open(gypfile + '.in').read()) |
| 54 | output = open(gypfile, 'w') |
| 55 | output.write(s.substitute(replacements)) |
| 56 | output.close() |
| 57 | |
| 58 | old_env = dict(os.environ) |
| 59 | os.environ['GYP_CROSSCOMPILE'] = '1' |
| 60 | test.run_gyp(gypfile) |
| 61 | os.environ.clear() |
| 62 | os.environ.update(old_env) |
| 63 | |
| 64 | test.build(gypfile) |
| 65 | test.must_contain_all_lines(test.stdout(), ['my_cc.py', 'my_cxx.py', 'BAR']) |
| 66 | |
| 67 | # Check that CC_host overrides make_global_settings |
| 68 | old_env = dict(os.environ) |
| 69 | os.environ['CC_host'] = '%s %s/my_cc.py SECRET' % (replacements['PYTHON'], |
| 70 | replacements['PWD']) |
| 71 | test.run_gyp(gypfile) |
| 72 | os.environ.clear() |
| 73 | os.environ.update(old_env) |
| 74 | |
| 75 | test.build(gypfile) |
| 76 | test.must_contain_all_lines(test.stdout(), ['SECRET', 'my_cxx.py', 'BAR']) |
| 77 | |
| 78 | test.pass_test() |