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 build of an executable with C++ define specified by a gyp define, and 9the use of the environment during regeneration when the gyp file changes. 10""" 11 12import os 13import TestGyp 14 15# Regenerating build files when a gyp file changes is currently only supported 16# by the make generator. 17test = TestGyp.TestGyp(formats=['make']) 18 19try: 20 os.environ['GYP_DEFINES'] = 'value=50' 21 test.run_gyp('defines.gyp') 22finally: 23 # We clear the environ after calling gyp. When the auto-regeneration happens, 24 # the same define should be reused anyway. Reset to empty string first in 25 # case the platform doesn't support unsetenv. 26 os.environ['GYP_DEFINES'] = '' 27 del os.environ['GYP_DEFINES'] 28 29test.build('defines.gyp') 30 31expect = """\ 32FOO is defined 33VALUE is 1 342*PAREN_VALUE is 12 35HASH_VALUE is a#1 36""" 37test.run_built_executable('defines', stdout=expect) 38 39# Sleep so that the changed gyp file will have a newer timestamp than the 40# previously generated build files. 41test.sleep() 42test.write('defines.gyp', test.read('defines-env.gyp')) 43 44test.build('defines.gyp', test.ALL) 45 46expect = """\ 47VALUE is 50 48""" 49test.run_built_executable('defines', stdout=expect) 50 51test.pass_test() 52