Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / gyp / test / cflags / gyptest-cflags.py
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 """
8 Verifies the use of the environment during regeneration when the gyp file
9 changes, specifically via build of an executable with C preprocessor
10 definition specified by CFLAGS.
11
12 In this test, gyp and build both run in same local environment.
13 """
14
15 import TestGyp
16
17 # CPPFLAGS works in ninja but not make; CFLAGS works in both
18 FORMATS = ('make', 'ninja')
19
20 test = TestGyp.TestGyp(formats=FORMATS)
21
22 # First set CFLAGS to blank in case the platform doesn't support unsetenv.
23 with TestGyp.LocalEnv({'CFLAGS': '',
24                        'GYP_CROSSCOMPILE': '1'}):
25   test.run_gyp('cflags.gyp')
26   test.build('cflags.gyp')
27
28 expect = """FOO not defined\n"""
29 test.run_built_executable('cflags', stdout=expect)
30 test.run_built_executable('cflags_host', stdout=expect)
31
32 test.sleep()
33
34 with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1',
35                        'GYP_CROSSCOMPILE': '1'}):
36   test.run_gyp('cflags.gyp')
37   test.build('cflags.gyp')
38
39 expect = """FOO defined\n"""
40 test.run_built_executable('cflags', stdout=expect)
41
42 # Environment variables shouldn't influence the flags for the host.
43 expect = """FOO not defined\n"""
44 test.run_built_executable('cflags_host', stdout=expect)
45
46 test.sleep()
47
48 with TestGyp.LocalEnv({'CFLAGS': ''}):
49   test.run_gyp('cflags.gyp')
50   test.build('cflags.gyp')
51
52 expect = """FOO not defined\n"""
53 test.run_built_executable('cflags', stdout=expect)
54
55 test.sleep()
56
57 with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1'}):
58   test.run_gyp('cflags.gyp')
59   test.build('cflags.gyp')
60
61 expect = """FOO defined\n"""
62 test.run_built_executable('cflags', stdout=expect)
63
64 test.pass_test()