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

Side by Side Diff: build/toolchain/win/setup_toolchain.py

Issue 2287603003: Move gyp-win-tool to the GN Windows toolchain. (Closed)
Patch Set: fix Created 4 years, 3 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
« no previous file with comments | « build/toolchain/win/midl.gni ('k') | build/toolchain/win/tool_wrapper.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 # 4 #
5 # Copies the given "win tool" (which the toolchain uses to wrap compiler 5 # Copies the given "win tool" (which the toolchain uses to wrap compiler
6 # invocations) and the environment blocks for the 32-bit and 64-bit builds on 6 # invocations) and the environment blocks for the 32-bit and 64-bit builds on
7 # Windows to the build directory. 7 # Windows to the build directory.
8 # 8 #
9 # The arguments are the visual studio install location and the location of the 9 # The arguments are the visual studio install location and the location of the
10 # win tool. The script assumes that the root build directory is the current dir 10 # win tool. The script assumes that the root build directory is the current dir
(...skipping 28 matching lines...) Expand all
39 env = {} 39 env = {}
40 # This occasionally happens and leads to misleading SYSTEMROOT error messages 40 # This occasionally happens and leads to misleading SYSTEMROOT error messages
41 # if not caught here. 41 # if not caught here.
42 if output_of_set.count('=') == 0: 42 if output_of_set.count('=') == 0:
43 raise Exception('Invalid output_of_set. Value is:\n%s' % output_of_set) 43 raise Exception('Invalid output_of_set. Value is:\n%s' % output_of_set)
44 for line in output_of_set.splitlines(): 44 for line in output_of_set.splitlines():
45 for envvar in envvars_to_save: 45 for envvar in envvars_to_save:
46 if re.match(envvar + '=', line.lower()): 46 if re.match(envvar + '=', line.lower()):
47 var, setting = line.split('=', 1) 47 var, setting = line.split('=', 1)
48 if envvar == 'path': 48 if envvar == 'path':
49 # Our own rules (for running gyp-win-tool) and other actions in 49 # Our own rules (for running tool_wrapper.py) and other actions in
50 # Chromium rely on python being in the path. Add the path to this 50 # Chromium rely on python being in the path. Add the path to this
51 # python here so that if it's not in the path when ninja is run 51 # python here so that if it's not in the path when ninja is run
52 # later, python will still be found. 52 # later, python will still be found.
53 setting = os.path.dirname(sys.executable) + os.pathsep + setting 53 setting = os.path.dirname(sys.executable) + os.pathsep + setting
54 env[var.upper()] = setting 54 env[var.upper()] = setting
55 break 55 break
56 if sys.platform in ('win32', 'cygwin'): 56 if sys.platform in ('win32', 'cygwin'):
57 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): 57 for required in ('SYSTEMROOT', 'TEMP', 'TMP'):
58 if required not in env: 58 if required not in env:
59 raise Exception('Environment variable "%s" ' 59 raise Exception('Environment variable "%s" '
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 Briefly this is a list of key=value\0, terminated by an additional \0. See 140 Briefly this is a list of key=value\0, terminated by an additional \0. See
141 CreateProcess documentation for more details.""" 141 CreateProcess documentation for more details."""
142 block = '' 142 block = ''
143 nul = '\0' 143 nul = '\0'
144 for key, value in envvar_dict.iteritems(): 144 for key, value in envvar_dict.iteritems():
145 block += key + '=' + value + nul 145 block += key + '=' + value + nul
146 block += nul 146 block += nul
147 return block 147 return block
148 148
149 149
150 def _CopyTool(source_path):
151 """Copies the given tool to the current directory, including a warning not
152 to edit it."""
153 with open(source_path) as source_file:
154 tool_source = source_file.readlines()
155
156 # Add header and write it out to the current directory (which should be the
157 # root build dir). Don't write the file if a matching file already exists
158 # because that causes a cascade of unnecessary rebuilds.
159 match = False
160 contents = ''.join([tool_source[0],
161 '# Generated by setup_toolchain.py do not edit.\n']
162 + tool_source[1:])
163 out_path = 'gyp-win-tool'
164 try:
165 with open(out_path, 'rb') as read_tool_file:
166 existing_contents = read_tool_file.read()
167 if existing_contents == contents:
168 match = True
169 except:
170 pass
171 if not match:
172 with open(out_path, 'wb') as write_tool_file:
173 write_tool_file.write(contents)
174
175
176 def main(): 150 def main():
177 if len(sys.argv) != 7: 151 if len(sys.argv) != 6:
178 print('Usage setup_toolchain.py ' 152 print('Usage setup_toolchain.py '
179 '<visual studio path> <win tool path> <win sdk path> ' 153 '<visual studio path> <win sdk path> '
180 '<runtime dirs> <target_cpu> <include prefix>') 154 '<runtime dirs> <target_cpu> <include prefix>')
181 sys.exit(2) 155 sys.exit(2)
182 tool_source = sys.argv[2] 156 win_sdk_path = sys.argv[2]
183 win_sdk_path = sys.argv[3] 157 runtime_dirs = sys.argv[3]
184 runtime_dirs = sys.argv[4] 158 target_cpu = sys.argv[4]
185 target_cpu = sys.argv[5] 159 include_prefix = sys.argv[5]
186 include_prefix = sys.argv[6]
187
188 _CopyTool(tool_source)
189 160
190 cpus = ('x86', 'x64') 161 cpus = ('x86', 'x64')
191 assert target_cpu in cpus 162 assert target_cpu in cpus
192 vc_bin_dir = '' 163 vc_bin_dir = ''
193 include = '' 164 include = ''
194 165
195 # TODO(scottmg|goma): Do we need an equivalent of 166 # TODO(scottmg|goma): Do we need an equivalent of
196 # ninja_use_custom_environment_files? 167 # ninja_use_custom_environment_files?
197 168
198 for cpu in cpus: 169 for cpu in cpus:
(...skipping 24 matching lines...) Expand all
223 with open('environment.winrt_' + cpu, 'wb') as f: 194 with open('environment.winrt_' + cpu, 'wb') as f:
224 f.write(env_block) 195 f.write(env_block)
225 196
226 assert vc_bin_dir 197 assert vc_bin_dir
227 print 'vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir) 198 print 'vc_bin_dir = ' + gn_helpers.ToGNString(vc_bin_dir)
228 assert include 199 assert include
229 print 'include_flags = ' + gn_helpers.ToGNString(include) 200 print 'include_flags = ' + gn_helpers.ToGNString(include)
230 201
231 if __name__ == '__main__': 202 if __name__ == '__main__':
232 main() 203 main()
OLDNEW
« no previous file with comments | « build/toolchain/win/midl.gni ('k') | build/toolchain/win/tool_wrapper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698