| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 | 2 |
| 3 # Copyright (c) 2012 Google Inc. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """ | 7 """ |
| 8 Verifies build of an executable with C++ define specified by a gyp define, and | 8 Verifies the use of the environment during regeneration when the gyp file |
| 9 the use of the environment during regeneration when the gyp file changes. | 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. |
| 10 """ | 13 """ |
| 11 | 14 |
| 12 import os | |
| 13 import sys | |
| 14 import TestGyp | 15 import TestGyp |
| 15 | 16 |
| 16 env_stack = [] | 17 # CPPFLAGS works in ninja but not make; CFLAGS works in both |
| 18 FORMATS = ('make', 'ninja') |
| 17 | 19 |
| 20 test = TestGyp.TestGyp(formats=FORMATS) |
| 18 | 21 |
| 19 def PushEnv(): | 22 # First set CFLAGS to blank in case the platform doesn't support unsetenv. |
| 20 env_copy = os.environ.copy() | 23 with TestGyp.LocalEnv({'CFLAGS': '', |
| 21 env_stack.append(env_copy) | 24 'GYP_CROSSCOMPILE': '1'}): |
| 22 | |
| 23 def PopEnv(): | |
| 24 os.environ.clear() | |
| 25 os.environ.update(env_stack.pop()) | |
| 26 | |
| 27 formats = ['make', 'ninja'] | |
| 28 | |
| 29 test = TestGyp.TestGyp(formats=formats) | |
| 30 | |
| 31 try: | |
| 32 PushEnv() | |
| 33 os.environ['CFLAGS'] = '' | |
| 34 os.environ['GYP_CROSSCOMPILE'] = '1' | |
| 35 test.run_gyp('cflags.gyp') | 25 test.run_gyp('cflags.gyp') |
| 36 test.build('cflags.gyp') | 26 test.build('cflags.gyp') |
| 37 finally: | |
| 38 # We clear the environ after calling gyp. When the auto-regeneration happens, | |
| 39 # the same define should be reused anyway. Reset to empty string first in | |
| 40 # case the platform doesn't support unsetenv. | |
| 41 PopEnv() | |
| 42 | |
| 43 | 27 |
| 44 expect = """FOO not defined\n""" | 28 expect = """FOO not defined\n""" |
| 45 test.run_built_executable('cflags', stdout=expect) | 29 test.run_built_executable('cflags', stdout=expect) |
| 46 test.run_built_executable('cflags_host', stdout=expect) | 30 test.run_built_executable('cflags_host', stdout=expect) |
| 47 | 31 |
| 48 test.sleep() | 32 test.sleep() |
| 49 | 33 |
| 50 try: | 34 with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1', |
| 51 PushEnv() | 35 'GYP_CROSSCOMPILE': '1'}): |
| 52 os.environ['CFLAGS'] = '-DFOO=1' | |
| 53 os.environ['GYP_CROSSCOMPILE'] = '1' | |
| 54 test.run_gyp('cflags.gyp') | 36 test.run_gyp('cflags.gyp') |
| 55 test.build('cflags.gyp') | 37 test.build('cflags.gyp') |
| 56 finally: | |
| 57 # We clear the environ after calling gyp. When the auto-regeneration happens, | |
| 58 # the same define should be reused anyway. Reset to empty string first in | |
| 59 # case the platform doesn't support unsetenv. | |
| 60 PopEnv() | |
| 61 | |
| 62 | 38 |
| 63 expect = """FOO defined\n""" | 39 expect = """FOO defined\n""" |
| 64 test.run_built_executable('cflags', stdout=expect) | 40 test.run_built_executable('cflags', stdout=expect) |
| 65 | 41 |
| 66 # Environment variables shouldn't influence the flags for the host. | 42 # Environment variables shouldn't influence the flags for the host. |
| 67 expect = """FOO not defined\n""" | 43 expect = """FOO not defined\n""" |
| 68 test.run_built_executable('cflags_host', stdout=expect) | 44 test.run_built_executable('cflags_host', stdout=expect) |
| 69 | 45 |
| 70 test.sleep() | 46 test.sleep() |
| 71 | 47 |
| 72 try: | 48 with TestGyp.LocalEnv({'CFLAGS': ''}): |
| 73 PushEnv() | |
| 74 os.environ['CFLAGS'] = '' | |
| 75 test.run_gyp('cflags.gyp') | 49 test.run_gyp('cflags.gyp') |
| 76 test.build('cflags.gyp') | 50 test.build('cflags.gyp') |
| 77 finally: | |
| 78 # We clear the environ after calling gyp. When the auto-regeneration happens, | |
| 79 # the same define should be reused anyway. Reset to empty string first in | |
| 80 # case the platform doesn't support unsetenv. | |
| 81 PopEnv() | |
| 82 | |
| 83 | 51 |
| 84 expect = """FOO not defined\n""" | 52 expect = """FOO not defined\n""" |
| 85 test.run_built_executable('cflags', stdout=expect) | 53 test.run_built_executable('cflags', stdout=expect) |
| 86 | 54 |
| 87 test.sleep() | 55 test.sleep() |
| 88 | 56 |
| 89 try: | 57 with TestGyp.LocalEnv({'CFLAGS': '-DFOO=1'}): |
| 90 PushEnv() | |
| 91 os.environ['CFLAGS'] = '-DFOO=1' | |
| 92 test.run_gyp('cflags.gyp') | 58 test.run_gyp('cflags.gyp') |
| 93 test.build('cflags.gyp') | 59 test.build('cflags.gyp') |
| 94 finally: | |
| 95 # We clear the environ after calling gyp. When the auto-regeneration happens, | |
| 96 # the same define should be reused anyway. Reset to empty string first in | |
| 97 # case the platform doesn't support unsetenv. | |
| 98 PopEnv() | |
| 99 | |
| 100 | 60 |
| 101 expect = """FOO defined\n""" | 61 expect = """FOO defined\n""" |
| 102 test.run_built_executable('cflags', stdout=expect) | 62 test.run_built_executable('cflags', stdout=expect) |
| 103 | 63 |
| 104 test.pass_test() | 64 test.pass_test() |
| OLD | NEW |