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 build of an executable with C++ define specified by a gyp define, and 9 the use of the environment during regeneration when the gyp file changes. 10 """ 11 12 import os 13 import sys 14 import TestGyp 15 16 env_stack = [] 17 18 19 def PushEnv(): 20 env_copy = os.environ.copy() 21 env_stack.append(env_copy) 22 23 def PopEnv(): 24 os.eniron=env_stack.pop() 25 26 formats = ['make'] 27 if sys.platform.startswith('linux'): 28 # Only Linux ninja generator supports CFLAGS. 29 formats.append('ninja') 30 31 test = TestGyp.TestGyp(formats=formats) 32 33 try: 34 PushEnv() 35 os.environ['CFLAGS'] = '-O0' 36 test.run_gyp('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 test.build('cflags.gyp') 44 45 expect = """\ 46 Using no optimization flag 47 """ 48 test.run_built_executable('cflags', stdout=expect) 49 50 test.sleep() 51 52 try: 53 PushEnv() 54 os.environ['CFLAGS'] = '-O2' 55 test.run_gyp('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 test.build('cflags.gyp') 63 64 expect = """\ 65 Using an optimization flag 66 """ 67 test.run_built_executable('cflags', stdout=expect) 68 69 test.pass_test() 70