• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15env_stack = []
16
17
18def PushEnv():
19  env_copy = os.environ.copy()
20  env_stack.append(env_copy)
21
22def PopEnv():
23  os.eniron=env_stack.pop()
24
25# Regenerating build files when a gyp file changes is currently only supported
26# by the make generator.
27test = TestGyp.TestGyp(formats=['make'])
28
29try:
30  PushEnv()
31  os.environ['CXXFLAGS'] = '-O0'
32  test.run_gyp('cxxflags.gyp')
33finally:
34  # We clear the environ after calling gyp.  When the auto-regeneration happens,
35  # the same define should be reused anyway.  Reset to empty string first in
36  # case the platform doesn't support unsetenv.
37  PopEnv()
38
39test.build('cxxflags.gyp')
40
41expect = """\
42Using no optimization flag
43"""
44test.run_built_executable('cxxflags', stdout=expect)
45
46test.sleep()
47
48try:
49  PushEnv()
50  os.environ['CXXFLAGS'] = '-O2'
51  test.run_gyp('cxxflags.gyp')
52finally:
53  # We clear the environ after calling gyp.  When the auto-regeneration happens,
54  # the same define should be reused anyway.  Reset to empty string first in
55  # case the platform doesn't support unsetenv.
56  PopEnv()
57
58test.build('cxxflags.gyp')
59
60expect = """\
61Using an optimization flag
62"""
63test.run_built_executable('cxxflags', stdout=expect)
64
65test.pass_test()
66