| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Utility functions for Windows builds. | 5 """Utility functions for Windows builds. |
| 6 | 6 |
| 7 This file is copied to the build directory as part of toolchain setup and | 7 This file is copied to the build directory as part of toolchain setup and |
| 8 is used to set up calls to tools used by the build that need wrappers. | 8 is used to set up calls to tools used by the build that need wrappers. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import codecs |
| 12 import filecmp |
| 11 import os | 13 import os |
| 12 import re | 14 import re |
| 13 import shutil | 15 import shutil |
| 14 import subprocess | 16 import subprocess |
| 15 import stat | 17 import stat |
| 16 import string | 18 import string |
| 17 import sys | 19 import sys |
| 18 | 20 |
| 19 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 21 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 20 | 22 |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 not line.startswith('Microsoft (R) Macro Assembler') and | 286 not line.startswith('Microsoft (R) Macro Assembler') and |
| 285 not line.startswith(' Assembling: ') and | 287 not line.startswith(' Assembling: ') and |
| 286 line): | 288 line): |
| 287 print line | 289 print line |
| 288 return popen.returncode | 290 return popen.returncode |
| 289 | 291 |
| 290 def ExecRcWrapper(self, arch, *args): | 292 def ExecRcWrapper(self, arch, *args): |
| 291 """Filter logo banner from invocations of rc.exe. Older versions of RC | 293 """Filter logo banner from invocations of rc.exe. Older versions of RC |
| 292 don't support the /nologo flag.""" | 294 don't support the /nologo flag.""" |
| 293 env = self._GetEnv(arch) | 295 env = self._GetEnv(arch) |
| 296 #print args |
| 294 popen = subprocess.Popen(args, shell=True, env=env, | 297 popen = subprocess.Popen(args, shell=True, env=env, |
| 295 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | 298 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 296 out, _ = popen.communicate() | 299 out, _ = popen.communicate() |
| 297 for line in out.splitlines(): | 300 for line in out.splitlines(): |
| 298 if (not line.startswith('Microsoft (R) Windows (R) Resource Compiler') and | 301 if (not line.startswith('Microsoft (R) Windows (R) Resource Compiler') and |
| 299 not line.startswith('Copy' + 'right (C' + | 302 not line.startswith('Copy' + 'right (C' + |
| 300 ') Microsoft Corporation') and | 303 ') Microsoft Corporation') and |
| 301 line): | 304 line): |
| 302 print line | 305 print line |
| 303 return popen.returncode | 306 final_result = popen.returncode |
| 307 |
| 308 ppargs = ['c:\\src\\hack\\res\pptest.exe'] |
| 309 ppargs += [a for a in args if a.startswith('-I') or a.startswith('-D')] |
| 310 rcfile = args[-1] # FIXME assumes .rc file is last |
| 311 |
| 312 # convert utf-16 to ascii if needed |
| 313 rcfiledata = open(rcfile, 'rb').read() |
| 314 rcfile = rcfile + '%d.utf8.rc' % os.getpid() # if one rc is used twice |
| 315 wrote_utf8 = False |
| 316 if rcfiledata.startswith(codecs.BOM_UTF16_LE): |
| 317 try: |
| 318 rcfiledata = rcfiledata[2:].decode('utf-16le').encode('utf-8') |
| 319 wrote_utf8 = True |
| 320 except e: |
| 321 print >> sys.stderr, e |
| 322 with open(rcfile, 'wb') as f: |
| 323 f.write(rcfiledata) |
| 324 |
| 325 ppargs.append(rcfile) |
| 326 |
| 327 ppargs += ['|', 'c:\\src\\hack\\res\\rc.exe'] |
| 328 # Make sure rc-relative resources can be found: |
| 329 ppargs.append("/cd" + os.path.dirname(rcfile)) |
| 330 resflag = args[-2] # FIXME assumes .res file is 2nd-to-last |
| 331 assert resflag.startswith('/fo') |
| 332 resfile = resflag[3:] |
| 333 resfile2 = resfile + '2' |
| 334 resflag = '/fo' + os.path.abspath(resfile2) |
| 335 ppargs.append(resflag) |
| 336 if wrote_utf8: |
| 337 ppargs.append('/utf-8') |
| 338 #print 'asdfasdfa', ppargs |
| 339 # MS rc.exe searches for files referenced from .rc files relative to -I |
| 340 # flags in addition to the pwd, so -I flags need to be passed both to |
| 341 # pptest and rc :-/ |
| 342 ppargs += [a for a in args if a.startswith('-I')] |
| 343 subprocess.check_call(ppargs, shell=True, env=env) |
| 344 assert filecmp.cmp(resfile, resfile2) |
| 345 |
| 346 return final_result |
| 304 | 347 |
| 305 def ExecActionWrapper(self, arch, rspfile, *dirname): | 348 def ExecActionWrapper(self, arch, rspfile, *dirname): |
| 306 """Runs an action command line from a response file using the environment | 349 """Runs an action command line from a response file using the environment |
| 307 for |arch|. If |dirname| is supplied, use that as the working directory.""" | 350 for |arch|. If |dirname| is supplied, use that as the working directory.""" |
| 308 env = self._GetEnv(arch) | 351 env = self._GetEnv(arch) |
| 309 # TODO(scottmg): This is a temporary hack to get some specific variables | 352 # TODO(scottmg): This is a temporary hack to get some specific variables |
| 310 # through to actions that are set after GN-time. http://crbug.com/333738. | 353 # through to actions that are set after GN-time. http://crbug.com/333738. |
| 311 for k, v in os.environ.iteritems(): | 354 for k, v in os.environ.iteritems(): |
| 312 if k not in env: | 355 if k not in env: |
| 313 env[k] = v | 356 env[k] = v |
| 314 args = open(rspfile).read() | 357 args = open(rspfile).read() |
| 315 dirname = dirname[0] if dirname else None | 358 dirname = dirname[0] if dirname else None |
| 316 return subprocess.call(args, shell=True, env=env, cwd=dirname) | 359 return subprocess.call(args, shell=True, env=env, cwd=dirname) |
| 317 | 360 |
| 318 def ExecClCompile(self, project_dir, selected_files): | 361 def ExecClCompile(self, project_dir, selected_files): |
| 319 """Executed by msvs-ninja projects when the 'ClCompile' target is used to | 362 """Executed by msvs-ninja projects when the 'ClCompile' target is used to |
| 320 build selected C/C++ files.""" | 363 build selected C/C++ files.""" |
| 321 project_dir = os.path.relpath(project_dir, BASE_DIR) | 364 project_dir = os.path.relpath(project_dir, BASE_DIR) |
| 322 selected_files = selected_files.split(';') | 365 selected_files = selected_files.split(';') |
| 323 ninja_targets = [os.path.join(project_dir, filename) + '^^' | 366 ninja_targets = [os.path.join(project_dir, filename) + '^^' |
| 324 for filename in selected_files] | 367 for filename in selected_files] |
| 325 cmd = ['ninja.exe'] | 368 cmd = ['ninja.exe'] |
| 326 cmd.extend(ninja_targets) | 369 cmd.extend(ninja_targets) |
| 327 return subprocess.call(cmd, shell=True, cwd=BASE_DIR) | 370 return subprocess.call(cmd, shell=True, cwd=BASE_DIR) |
| 328 | 371 |
| 329 if __name__ == '__main__': | 372 if __name__ == '__main__': |
| 330 sys.exit(main(sys.argv[1:])) | 373 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |