blob: d58fc7c2f995d617fc28a7697b6ff3cd494a1113 [file] [log] [blame]
Ben Murdoch097c5b22016-05-18 11:27:45 +01001#!/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"""
6Verifies that make_global_settings can be used to override the
7compiler settings.
8"""
9
10import TestGyp
11import os
12import copy
13import sys
14from string import Template
15
16
17if 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
22test = TestGyp.TestGyp(formats=['ninja', 'make'])
23
24gypfile = 'compiler-global-settings.gyp'
25
26replacements = { '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.
31replacements['TOOLSET'] = 'target'
32s = Template(open(gypfile + '.in').read())
33output = open(gypfile, 'w')
34output.write(s.substitute(replacements))
35output.close()
36
37old_env = dict(os.environ)
38os.environ['GYP_CROSSCOMPILE'] = '1'
39test.run_gyp(gypfile)
40os.environ.clear()
41os.environ.update(old_env)
42
43test.build(gypfile)
44test.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).
48if test.format == 'xcode-ninja':
49 test.pass_test()
50
51# Same again but with the host toolset.
52replacements['TOOLSET'] = 'host'
53s = Template(open(gypfile + '.in').read())
54output = open(gypfile, 'w')
55output.write(s.substitute(replacements))
56output.close()
57
58old_env = dict(os.environ)
59os.environ['GYP_CROSSCOMPILE'] = '1'
60test.run_gyp(gypfile)
61os.environ.clear()
62os.environ.update(old_env)
63
64test.build(gypfile)
65test.must_contain_all_lines(test.stdout(), ['my_cc.py', 'my_cxx.py', 'BAR'])
66
67# Check that CC_host overrides make_global_settings
68old_env = dict(os.environ)
69os.environ['CC_host'] = '%s %s/my_cc.py SECRET' % (replacements['PYTHON'],
70 replacements['PWD'])
71test.run_gyp(gypfile)
72os.environ.clear()
73os.environ.update(old_env)
74
75test.build(gypfile)
76test.must_contain_all_lines(test.stdout(), ['SECRET', 'my_cxx.py', 'BAR'])
77
78test.pass_test()