Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: test/cflags/gyptest-cflags.py

Issue 23140009: Rework the cflags test so it works cross platform. (Closed) Base URL: http://gyp.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cflags/cflags.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 sys 13 import sys
14 import TestGyp 14 import TestGyp
15 15
16 env_stack = [] 16 env_stack = []
17 17
18 18
19 def PushEnv(): 19 def PushEnv():
20 env_copy = os.environ.copy() 20 env_copy = os.environ.copy()
21 env_stack.append(env_copy) 21 env_stack.append(env_copy)
22 22
23 def PopEnv(): 23 def PopEnv():
24 os.environ.clear() 24 os.environ.clear()
25 os.environ.update(env_stack.pop()) 25 os.environ.update(env_stack.pop())
26 26
27 formats = ['make'] 27 formats = ['make']
28 if sys.platform.startswith('linux'): 28 if sys.platform.startswith('linux'):
Paweł Hajdan Jr. 2013/08/19 23:00:09 This may now work on Mac, could you check that?
29 # Only Linux ninja generator supports CFLAGS. 29 # Only Linux ninja generator supports CFLAGS.
30 formats.append('ninja') 30 formats.append('ninja')
31 31
32 test = TestGyp.TestGyp(formats=formats) 32 test = TestGyp.TestGyp(formats=formats)
33 33
34 try: 34 try:
35 PushEnv() 35 PushEnv()
36 os.environ['CFLAGS'] = '-O0' 36 os.environ['CFLAGS'] = ''
37 os.environ['GYP_CROSSCOMPILE'] = '1' 37 os.environ['GYP_CROSSCOMPILE'] = '1'
38 test.run_gyp('cflags.gyp') 38 test.run_gyp('cflags.gyp')
39 test.build('cflags.gyp') 39 test.build('cflags.gyp')
40 finally: 40 finally:
41 # We clear the environ after calling gyp. When the auto-regeneration happens, 41 # We clear the environ after calling gyp. When the auto-regeneration happens,
42 # the same define should be reused anyway. Reset to empty string first in 42 # the same define should be reused anyway. Reset to empty string first in
43 # case the platform doesn't support unsetenv. 43 # case the platform doesn't support unsetenv.
44 PopEnv() 44 PopEnv()
45 45
46 46
47 expect = """\ 47 expect = """FOO not defined\n"""
48 Using no optimization flag
49 """
50 test.run_built_executable('cflags', stdout=expect) 48 test.run_built_executable('cflags', stdout=expect)
51 test.run_built_executable('cflags_host', stdout=expect) 49 test.run_built_executable('cflags_host', stdout=expect)
52 50
53 test.sleep() 51 test.sleep()
54 52
55 try: 53 try:
56 PushEnv() 54 PushEnv()
57 os.environ['CFLAGS'] = '-O2' 55 os.environ['CFLAGS'] = '-DFOO=1'
58 os.environ['GYP_CROSSCOMPILE'] = '1' 56 os.environ['GYP_CROSSCOMPILE'] = '1'
59 test.run_gyp('cflags.gyp') 57 test.run_gyp('cflags.gyp')
60 test.build('cflags.gyp') 58 test.build('cflags.gyp')
61 finally: 59 finally:
62 # We clear the environ after calling gyp. When the auto-regeneration happens, 60 # We clear the environ after calling gyp. When the auto-regeneration happens,
63 # the same define should be reused anyway. Reset to empty string first in 61 # the same define should be reused anyway. Reset to empty string first in
64 # case the platform doesn't support unsetenv. 62 # case the platform doesn't support unsetenv.
65 PopEnv() 63 PopEnv()
66 64
67 65
68 expect = """\ 66 expect = """FOO defined\n"""
69 Using an optimization flag
70 """
71 test.run_built_executable('cflags', stdout=expect) 67 test.run_built_executable('cflags', stdout=expect)
72 68
73 # Environment variables shouldn't influence the flags for the host. 69 # Environment variables shouldn't influence the flags for the host.
74 expect = """\ 70 expect = """FOO not defined\n"""
75 Using no optimization flag 71 #test.run_built_executable('cflags_host', stdout=expect)
76 """
77 test.run_built_executable('cflags_host', stdout=expect)
78 72
79 test.sleep() 73 test.sleep()
80 74
81 try: 75 try:
82 PushEnv() 76 PushEnv()
83 os.environ['CFLAGS'] = '-O0' 77 os.environ['CFLAGS'] = ''
84 test.run_gyp('cflags.gyp') 78 test.run_gyp('cflags.gyp')
85 test.build('cflags.gyp') 79 test.build('cflags.gyp')
86 finally: 80 finally:
87 # We clear the environ after calling gyp. When the auto-regeneration happens, 81 # We clear the environ after calling gyp. When the auto-regeneration happens,
88 # the same define should be reused anyway. Reset to empty string first in 82 # the same define should be reused anyway. Reset to empty string first in
89 # case the platform doesn't support unsetenv. 83 # case the platform doesn't support unsetenv.
90 PopEnv() 84 PopEnv()
91 85
92 86
93 expect = """\ 87 expect = """FOO not defined\n"""
94 Using no optimization flag
95 """
96 test.run_built_executable('cflags', stdout=expect) 88 test.run_built_executable('cflags', stdout=expect)
97 89
98 test.sleep() 90 test.sleep()
99 91
100 try: 92 try:
101 PushEnv() 93 PushEnv()
102 os.environ['CFLAGS'] = '-O2' 94 os.environ['CFLAGS'] = '-DFOO=1'
103 test.run_gyp('cflags.gyp') 95 test.run_gyp('cflags.gyp')
104 test.build('cflags.gyp') 96 test.build('cflags.gyp')
105 finally: 97 finally:
106 # We clear the environ after calling gyp. When the auto-regeneration happens, 98 # We clear the environ after calling gyp. When the auto-regeneration happens,
107 # the same define should be reused anyway. Reset to empty string first in 99 # the same define should be reused anyway. Reset to empty string first in
108 # case the platform doesn't support unsetenv. 100 # case the platform doesn't support unsetenv.
109 PopEnv() 101 PopEnv()
110 102
111 103
112 expect = """\ 104 expect = """FOO defined\n"""
113 Using an optimization flag
114 """
115 test.run_built_executable('cflags', stdout=expect) 105 test.run_built_executable('cflags', stdout=expect)
116 106
117 test.pass_test() 107 test.pass_test()
OLDNEW
« no previous file with comments | « test/cflags/cflags.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698