michael@0: #!/usr/bin/env python michael@0: michael@0: # Copyright (c) 2012 Google Inc. All rights reserved. michael@0: # Use of this source code is governed by a BSD-style license that can be michael@0: # found in the LICENSE file. michael@0: michael@0: """ michael@0: Verifies build of an executable with C++ define specified by a gyp define, and michael@0: the use of the environment during regeneration when the gyp file changes. michael@0: """ michael@0: michael@0: import os michael@0: import TestGyp michael@0: michael@0: env_stack = [] michael@0: michael@0: michael@0: def PushEnv(): michael@0: env_copy = os.environ.copy() michael@0: env_stack.append(env_copy) michael@0: michael@0: def PopEnv(): michael@0: os.eniron=env_stack.pop() michael@0: michael@0: # Regenerating build files when a gyp file changes is currently only supported michael@0: # by the make and Android generators. michael@0: test = TestGyp.TestGyp(formats=['make', 'android']) michael@0: michael@0: try: michael@0: PushEnv() michael@0: os.environ['CFLAGS'] = '-O0' michael@0: test.run_gyp('cflags.gyp') michael@0: finally: michael@0: # We clear the environ after calling gyp. When the auto-regeneration happens, michael@0: # the same define should be reused anyway. Reset to empty string first in michael@0: # case the platform doesn't support unsetenv. michael@0: PopEnv() michael@0: michael@0: test.build('cflags.gyp') michael@0: michael@0: expect = """\ michael@0: Using no optimization flag michael@0: """ michael@0: test.run_built_executable('cflags', stdout=expect) michael@0: michael@0: test.sleep() michael@0: michael@0: try: michael@0: PushEnv() michael@0: os.environ['CFLAGS'] = '-O2' michael@0: test.run_gyp('cflags.gyp') michael@0: finally: michael@0: # We clear the environ after calling gyp. When the auto-regeneration happens, michael@0: # the same define should be reused anyway. Reset to empty string first in michael@0: # case the platform doesn't support unsetenv. michael@0: PopEnv() michael@0: michael@0: test.build('cflags.gyp') michael@0: michael@0: expect = """\ michael@0: Using an optimization flag michael@0: """ michael@0: test.run_built_executable('cflags', stdout=expect) michael@0: michael@0: test.pass_test()