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 variables 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': ''}):
49  test.run_gyp('cflags.gyp')
50  test.build('cflags.gyp')
51
52expect = """FOO not defined\n"""
53test.run_built_executable('cflags', stdout=expect)
54
55test.sleep()
56
57with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1'}):
58  test.run_gyp('cflags.gyp')
59  test.build('cflags.gyp')
60
61expect = """FOO defined\n"""
62test.run_built_executable('cflags', stdout=expect)
63
64test.pass_test()
65