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"""
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# Same again but with the host toolset.
47replacements['TOOLSET'] = 'host'
48s = Template(open(gypfile + '.in').read())
49output = open(gypfile, 'w')
50output.write(s.substitute(replacements))
51output.close()
52
53old_env = dict(os.environ)
54os.environ['GYP_CROSSCOMPILE'] = '1'
55test.run_gyp(gypfile)
56os.environ.clear()
57os.environ.update(old_env)
58
59test.build(gypfile)
60test.must_contain_all_lines(test.stdout(), ['my_cc.py', 'my_cxx.py', 'BAR'])
61
62test.pass_test()
63