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 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. | 9 the use of the environment during regeneration when the gyp file changes. |
10 """ | 10 """ |
11 | 11 |
12 import os | 12 import os |
13 import TestGyp | 13 import TestGyp |
14 | 14 |
15 env_stack = [] | |
16 | |
17 | |
18 def PushEnv(): | |
19 env_copy = os.environ.copy() | |
20 env_stack.append(env_copy) | |
21 | |
22 def PopEnv(): | |
23 os.eniron=env_stack.pop() | |
Nils Barth (inactive)
2014/04/08 08:56:32
Ow, notice the typos?
os.eniron (not os.en*v*iron)
| |
24 | 15 |
25 # Regenerating build files when a gyp file changes is currently only supported | 16 # Regenerating build files when a gyp file changes is currently only supported |
26 # by the make generator. | 17 # by the make generator. |
27 test = TestGyp.TestGyp(formats=['make']) | 18 test = TestGyp.TestGyp(formats=['make']) |
28 | 19 |
29 try: | 20 # We reset the environ after calling gyp. When the auto-regeneration happens, |
30 PushEnv() | 21 # the same define should be reused anyway. |
31 os.environ['CXXFLAGS'] = '-O0' | 22 with TestGyp.LocalEnv({'CXXFLAGS': '-O0'}): |
32 test.run_gyp('cxxflags.gyp') | 23 test.run_gyp('cxxflags.gyp') |
33 finally: | |
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 | 24 |
39 test.build('cxxflags.gyp') | 25 test.build('cxxflags.gyp') |
40 | 26 |
41 expect = """\ | 27 expect = """\ |
42 Using no optimization flag | 28 Using no optimization flag |
43 """ | 29 """ |
44 test.run_built_executable('cxxflags', stdout=expect) | 30 test.run_built_executable('cxxflags', stdout=expect) |
45 | 31 |
46 test.sleep() | 32 test.sleep() |
47 | 33 |
48 try: | 34 with TestGyp.LocalEnv({'CXXFLAGS': '-O2'}): |
49 PushEnv() | |
50 os.environ['CXXFLAGS'] = '-O2' | |
51 test.run_gyp('cxxflags.gyp') | 35 test.run_gyp('cxxflags.gyp') |
52 finally: | |
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 | 36 |
58 test.build('cxxflags.gyp') | 37 test.build('cxxflags.gyp') |
59 | 38 |
60 expect = """\ | 39 expect = """\ |
61 Using an optimization flag | 40 Using an optimization flag |
62 """ | 41 """ |
63 test.run_built_executable('cxxflags', stdout=expect) | 42 test.run_built_executable('cxxflags', stdout=expect) |
64 | 43 |
65 test.pass_test() | 44 test.pass_test() |
OLD | NEW |