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 """Utility functions for Windows builds. | 7 """Utility functions for Windows builds. |
8 | 8 |
9 These functions are executed via gyp-win-tool when using the ninja generator. | 9 These functions are executed via gyp-win-tool when using the ninja generator. |
10 """ | 10 """ |
11 | 11 |
| 12 from __future__ import print_function |
| 13 |
12 import os | 14 import os |
13 import re | 15 import re |
14 import shutil | 16 import shutil |
15 import subprocess | 17 import subprocess |
16 import stat | 18 import stat |
17 import string | 19 import string |
18 import sys | 20 import sys |
19 | 21 |
20 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 22 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
21 | 23 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 link = subprocess.Popen([args[0].replace('/', '\\')] + list(args[1:]), | 121 link = subprocess.Popen([args[0].replace('/', '\\')] + list(args[1:]), |
120 shell=True, | 122 shell=True, |
121 env=env, | 123 env=env, |
122 stdout=subprocess.PIPE, | 124 stdout=subprocess.PIPE, |
123 stderr=subprocess.STDOUT) | 125 stderr=subprocess.STDOUT) |
124 out, _ = link.communicate() | 126 out, _ = link.communicate() |
125 for line in out.splitlines(): | 127 for line in out.splitlines(): |
126 if (not line.startswith(' Creating library ') and | 128 if (not line.startswith(' Creating library ') and |
127 not line.startswith('Generating code') and | 129 not line.startswith('Generating code') and |
128 not line.startswith('Finished generating code')): | 130 not line.startswith('Finished generating code')): |
129 print line | 131 print(line) |
130 return link.returncode | 132 return link.returncode |
131 | 133 |
132 def ExecLinkWithManifests(self, arch, embed_manifest, out, ldcmd, resname, | 134 def ExecLinkWithManifests(self, arch, embed_manifest, out, ldcmd, resname, |
133 mt, rc, intermediate_manifest, *manifests): | 135 mt, rc, intermediate_manifest, *manifests): |
134 """A wrapper for handling creating a manifest resource and then executing | 136 """A wrapper for handling creating a manifest resource and then executing |
135 a link command.""" | 137 a link command.""" |
136 # The 'normal' way to do manifests is to have link generate a manifest | 138 # The 'normal' way to do manifests is to have link generate a manifest |
137 # based on gathering dependencies from the object files, then merge that | 139 # based on gathering dependencies from the object files, then merge that |
138 # manifest with other manifests supplied as sources, convert the merged | 140 # manifest with other manifests supplied as sources, convert the merged |
139 # manifest to a resource, and then *relink*, including the compiled | 141 # manifest to a resource, and then *relink*, including the compiled |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 # Merge the intermediate one with ours to .assert.manifest, then check | 180 # Merge the intermediate one with ours to .assert.manifest, then check |
179 # that .assert.manifest is identical to ours. | 181 # that .assert.manifest is identical to ours. |
180 subprocess.check_call( | 182 subprocess.check_call( |
181 '%(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo ' | 183 '%(python)s gyp-win-tool manifest-wrapper %(arch)s %(mt)s -nologo ' |
182 '-manifest %(out)s.manifest %(intermediate_manifest)s ' | 184 '-manifest %(out)s.manifest %(intermediate_manifest)s ' |
183 '-out:%(out)s.assert.manifest' % variables) | 185 '-out:%(out)s.assert.manifest' % variables) |
184 assert_manifest = '%(out)s.assert.manifest' % variables | 186 assert_manifest = '%(out)s.assert.manifest' % variables |
185 our_manifest = '%(out)s.manifest' % variables | 187 our_manifest = '%(out)s.manifest' % variables |
186 # Load and normalize the manifests. mt.exe sometimes removes whitespace, | 188 # Load and normalize the manifests. mt.exe sometimes removes whitespace, |
187 # and sometimes doesn't unfortunately. | 189 # and sometimes doesn't unfortunately. |
188 with open(our_manifest, 'rb') as our_f: | 190 with open(our_manifest, 'r') as our_f: |
189 with open(assert_manifest, 'rb') as assert_f: | 191 with open(assert_manifest, 'r') as assert_f: |
190 our_data = our_f.read().translate(None, string.whitespace) | 192 our_data = our_f.read().translate(None, string.whitespace) |
191 assert_data = assert_f.read().translate(None, string.whitespace) | 193 assert_data = assert_f.read().translate(None, string.whitespace) |
192 if our_data != assert_data: | 194 if our_data != assert_data: |
193 os.unlink(out) | 195 os.unlink(out) |
194 def dump(filename): | 196 def dump(filename): |
195 sys.stderr.write('%s\n-----\n' % filename) | 197 print(filename, file=sys.stderr) |
196 with open(filename, 'rb') as f: | 198 print('-----', file=sys.stderr) |
197 sys.stderr.write(f.read() + '\n-----\n') | 199 with open(filename, 'r') as f: |
| 200 print(f.read(), file=sys.stderr) |
| 201 print('-----', file=sys.stderr) |
198 dump(intermediate_manifest) | 202 dump(intermediate_manifest) |
199 dump(our_manifest) | 203 dump(our_manifest) |
200 dump(assert_manifest) | 204 dump(assert_manifest) |
201 sys.stderr.write( | 205 sys.stderr.write( |
202 'Linker generated manifest "%s" added to final manifest "%s" ' | 206 'Linker generated manifest "%s" added to final manifest "%s" ' |
203 '(result in "%s"). ' | 207 '(result in "%s"). ' |
204 'Were /MANIFEST switches used in #pragma statements? ' % ( | 208 'Were /MANIFEST switches used in #pragma statements? ' % ( |
205 intermediate_manifest, our_manifest, assert_manifest)) | 209 intermediate_manifest, our_manifest, assert_manifest)) |
206 return 1 | 210 return 1 |
207 | 211 |
208 def ExecManifestWrapper(self, arch, *args): | 212 def ExecManifestWrapper(self, arch, *args): |
209 """Run manifest tool with environment set. Strip out undesirable warning | 213 """Run manifest tool with environment set. Strip out undesirable warning |
210 (some XML blocks are recognized by the OS loader, but not the manifest | 214 (some XML blocks are recognized by the OS loader, but not the manifest |
211 tool).""" | 215 tool).""" |
212 env = self._GetEnv(arch) | 216 env = self._GetEnv(arch) |
213 popen = subprocess.Popen(args, shell=True, env=env, | 217 popen = subprocess.Popen(args, shell=True, env=env, |
214 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 218 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
215 out, _ = popen.communicate() | 219 out, _ = popen.communicate() |
216 for line in out.splitlines(): | 220 for line in out.splitlines(): |
217 if line and 'manifest authoring warning 81010002' not in line: | 221 if line and 'manifest authoring warning 81010002' not in line: |
218 print line | 222 print(line) |
219 return popen.returncode | 223 return popen.returncode |
220 | 224 |
221 def ExecManifestToRc(self, arch, *args): | 225 def ExecManifestToRc(self, arch, *args): |
222 """Creates a resource file pointing a SxS assembly manifest. | 226 """Creates a resource file pointing a SxS assembly manifest. |
223 |args| is tuple containing path to resource file, path to manifest file | 227 |args| is tuple containing path to resource file, path to manifest file |
224 and resource name which can be "1" (for executables) or "2" (for DLLs).""" | 228 and resource name which can be "1" (for executables) or "2" (for DLLs).""" |
225 manifest_path, resource_path, resource_name = args | 229 manifest_path, resource_path, resource_name = args |
226 with open(resource_path, 'wb') as output: | 230 with open(resource_path, 'w') as output: |
227 output.write('#include <windows.h>\n%s RT_MANIFEST "%s"' % ( | 231 output.write('#include <windows.h>\n%s RT_MANIFEST "%s"' % ( |
228 resource_name, | 232 resource_name, |
229 os.path.abspath(manifest_path).replace('\\', '/'))) | 233 os.path.abspath(manifest_path).replace('\\', '/'))) |
230 | 234 |
231 def ExecMidlWrapper(self, arch, outdir, tlb, h, dlldata, iid, proxy, idl, | 235 def ExecMidlWrapper(self, arch, outdir, tlb, h, dlldata, iid, proxy, idl, |
232 *flags): | 236 *flags): |
233 """Filter noisy filenames output from MIDL compile step that isn't | 237 """Filter noisy filenames output from MIDL compile step that isn't |
234 quietable via command line flags. | 238 quietable via command line flags. |
235 """ | 239 """ |
236 args = ['midl', '/nologo'] + list(flags) + [ | 240 args = ['midl', '/nologo'] + list(flags) + [ |
(...skipping 11 matching lines...) Expand all Loading... |
248 # Filter junk out of stdout, and write filtered versions. Output we want | 252 # Filter junk out of stdout, and write filtered versions. Output we want |
249 # to filter is pairs of lines that look like this: | 253 # to filter is pairs of lines that look like this: |
250 # Processing C:\Program Files (x86)\Microsoft SDKs\...\include\objidl.idl | 254 # Processing C:\Program Files (x86)\Microsoft SDKs\...\include\objidl.idl |
251 # objidl.idl | 255 # objidl.idl |
252 lines = out.splitlines() | 256 lines = out.splitlines() |
253 prefixes = ('Processing ', '64 bit Processing ') | 257 prefixes = ('Processing ', '64 bit Processing ') |
254 processing = set(os.path.basename(x) | 258 processing = set(os.path.basename(x) |
255 for x in lines if x.startswith(prefixes)) | 259 for x in lines if x.startswith(prefixes)) |
256 for line in lines: | 260 for line in lines: |
257 if not line.startswith(prefixes) and line not in processing: | 261 if not line.startswith(prefixes) and line not in processing: |
258 print line | 262 print(line) |
259 return popen.returncode | 263 return popen.returncode |
260 | 264 |
261 def ExecAsmWrapper(self, arch, *args): | 265 def ExecAsmWrapper(self, arch, *args): |
262 """Filter logo banner from invocations of asm.exe.""" | 266 """Filter logo banner from invocations of asm.exe.""" |
263 env = self._GetEnv(arch) | 267 env = self._GetEnv(arch) |
264 popen = subprocess.Popen(args, shell=True, env=env, | 268 popen = subprocess.Popen(args, shell=True, env=env, |
265 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 269 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
266 out, _ = popen.communicate() | 270 out, _ = popen.communicate() |
267 for line in out.splitlines(): | 271 for line in out.splitlines(): |
268 if (not line.startswith('Copyright (C) Microsoft Corporation') and | 272 if (not line.startswith('Copyright (C) Microsoft Corporation') and |
269 not line.startswith('Microsoft (R) Macro Assembler') and | 273 not line.startswith('Microsoft (R) Macro Assembler') and |
270 not line.startswith(' Assembling: ') and | 274 not line.startswith(' Assembling: ') and |
271 line): | 275 line): |
272 print line | 276 print(line) |
273 return popen.returncode | 277 return popen.returncode |
274 | 278 |
275 def ExecRcWrapper(self, arch, *args): | 279 def ExecRcWrapper(self, arch, *args): |
276 """Filter logo banner from invocations of rc.exe. Older versions of RC | 280 """Filter logo banner from invocations of rc.exe. Older versions of RC |
277 don't support the /nologo flag.""" | 281 don't support the /nologo flag.""" |
278 env = self._GetEnv(arch) | 282 env = self._GetEnv(arch) |
279 popen = subprocess.Popen(args, shell=True, env=env, | 283 popen = subprocess.Popen(args, shell=True, env=env, |
280 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 284 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
281 out, _ = popen.communicate() | 285 out, _ = popen.communicate() |
282 for line in out.splitlines(): | 286 for line in out.splitlines(): |
283 if (not line.startswith('Microsoft (R) Windows (R) Resource Compiler') and | 287 if (not line.startswith('Microsoft (R) Windows (R) Resource Compiler') and |
284 not line.startswith('Copyright (C) Microsoft Corporation') and | 288 not line.startswith('Copyright (C) Microsoft Corporation') and |
285 line): | 289 line): |
286 print line | 290 print(line) |
287 return popen.returncode | 291 return popen.returncode |
288 | 292 |
289 def ExecActionWrapper(self, arch, rspfile, *dir): | 293 def ExecActionWrapper(self, arch, rspfile, *dir): |
290 """Runs an action command line from a response file using the environment | 294 """Runs an action command line from a response file using the environment |
291 for |arch|. If |dir| is supplied, use that as the working directory.""" | 295 for |arch|. If |dir| is supplied, use that as the working directory.""" |
292 env = self._GetEnv(arch) | 296 env = self._GetEnv(arch) |
293 # TODO(scottmg): This is a temporary hack to get some specific variables | 297 # TODO(scottmg): This is a temporary hack to get some specific variables |
294 # through to actions that are set after gyp-time. http://crbug.com/333738. | 298 # through to actions that are set after gyp-time. http://crbug.com/333738. |
295 for k, v in os.environ.iteritems(): | 299 for k, v in os.environ.items(): |
296 if k not in env: | 300 if k not in env: |
297 env[k] = v | 301 env[k] = v |
298 args = open(rspfile).read() | 302 args = open(rspfile).read() |
299 dir = dir[0] if dir else None | 303 dir = dir[0] if dir else None |
300 return subprocess.call(args, shell=True, env=env, cwd=dir) | 304 return subprocess.call(args, shell=True, env=env, cwd=dir) |
301 | 305 |
302 def ExecClCompile(self, project_dir, selected_files): | 306 def ExecClCompile(self, project_dir, selected_files): |
303 """Executed by msvs-ninja projects when the 'ClCompile' target is used to | 307 """Executed by msvs-ninja projects when the 'ClCompile' target is used to |
304 build selected C/C++ files.""" | 308 build selected C/C++ files.""" |
305 project_dir = os.path.relpath(project_dir, BASE_DIR) | 309 project_dir = os.path.relpath(project_dir, BASE_DIR) |
306 selected_files = selected_files.split(';') | 310 selected_files = selected_files.split(';') |
307 ninja_targets = [os.path.join(project_dir, filename) + '^^' | 311 ninja_targets = [os.path.join(project_dir, filename) + '^^' |
308 for filename in selected_files] | 312 for filename in selected_files] |
309 cmd = ['ninja.exe'] | 313 cmd = ['ninja.exe'] |
310 cmd.extend(ninja_targets) | 314 cmd.extend(ninja_targets) |
311 return subprocess.call(cmd, shell=True, cwd=BASE_DIR) | 315 return subprocess.call(cmd, shell=True, cwd=BASE_DIR) |
312 | 316 |
313 if __name__ == '__main__': | 317 if __name__ == '__main__': |
314 sys.exit(main(sys.argv[1:])) | 318 sys.exit(main(sys.argv[1:])) |
OLD | NEW |