1#!/usr/bin/env python
2
3# Copyright (c) 2012 Google Inc. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""
8Verifies the use of the environment during regeneration when the gyp file
9changes, specifically via build of an executable with C preprocessor
10definition specified by CFLAGS.
11
12In this test, gyp and build both run in same local environment.
13"""
14
15import TestGyp
16
17# CPPFLAGS works in ninja but not make; CFLAGS works in both
18FORMATS = ('make', 'ninja')
19
20test = TestGyp.TestGyp(formats=FORMATS)
21
22# First set CFLAGS to blank in case the platform doesn't support unsetenv.
23with TestGyp.LocalEnv({'CFLAGS': '',
24                       'GYP_CROSSCOMPILE': '1'}):
25  test.run_gyp('cflags.gyp')
26  test.build('cflags.gyp')
27
28expect = """FOO not defined\n"""
29test.run_built_executable('cflags', stdout=expect)
30test.run_built_executable('cflags_host', stdout=expect)
31
32test.sleep()
33
34with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1',
35                       'GYP_CROSSCOMPILE': '1'}):
36  test.run_gyp('cflags.gyp')
37  test.build('cflags.gyp')
38
39expect = """FOO defined\n"""
40test.run_built_executable('cflags', stdout=expect)
41
42# Environment variable CFLAGS shouldn't influence the flags for the host.
43expect = """FOO not defined\n"""
44test.run_built_executable('cflags_host', stdout=expect)
45
46test.sleep()
47
48with TestGyp.LocalEnv({'CFLAGS_host': '-DFOO=1',
49                       'GYP_CROSSCOMPILE': '1'}):
50  test.run_gyp('cflags.gyp')
51  test.build('cflags.gyp')
52
53# Environment variable CFLAGS_host should influence the flags for the host.
54expect = """FOO defined\n"""
55test.run_built_executable('cflags_host', stdout=expect)
56
57test.sleep()
58
59with TestGyp.LocalEnv({'CFLAGS': ''}):
60  test.run_gyp('cflags.gyp')
61  test.build('cflags.gyp')
62
63expect = """FOO not defined\n"""
64test.run_built_executable('cflags', stdout=expect)
65
66test.sleep()
67
68with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1'}):
69  test.run_gyp('cflags.gyp')
70  test.build('cflags.gyp')
71
72expect = """FOO defined\n"""
73test.run_built_executable('cflags', stdout=expect)
74
75test.pass_test()
76