| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Does one of the following depending on the --mode argument: | 6 """Does one of the following depending on the --mode argument: |
| 7 check Verifies all the inputs exist, touches the file specified with | 7 check Verifies all the inputs exist, touches the file specified with |
| 8 --result and exits. | 8 --result and exits. |
| 9 hashtable Puts a manifest file and hard links each of the inputs into the | 9 hashtable Puts a manifest file and hard links each of the inputs into the |
| 10 output directory. | 10 output directory. |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 """Always uses a temporary directory.""" | 365 """Always uses a temporary directory.""" |
| 366 try: | 366 try: |
| 367 outdir = tempfile.mkdtemp(prefix='isolate') | 367 outdir = tempfile.mkdtemp(prefix='isolate') |
| 368 recreate_tree( | 368 recreate_tree( |
| 369 outdir, indir, dictfiles.keys(), run_test_from_archive.HARDLINK) | 369 outdir, indir, dictfiles.keys(), run_test_from_archive.HARDLINK) |
| 370 cwd = os.path.join(outdir, relative_cwd) | 370 cwd = os.path.join(outdir, relative_cwd) |
| 371 if not os.path.isdir(cwd): | 371 if not os.path.isdir(cwd): |
| 372 os.makedirs(cwd) | 372 os.makedirs(cwd) |
| 373 if read_only: | 373 if read_only: |
| 374 run_test_from_archive.make_writable(outdir, True) | 374 run_test_from_archive.make_writable(outdir, True) |
| 375 if not cmd: |
| 376 print 'No command to run' |
| 377 return 1 |
| 375 cmd = trace_inputs.fix_python_path(cmd) | 378 cmd = trace_inputs.fix_python_path(cmd) |
| 376 logging.info('Running %s, cwd=%s' % (cmd, cwd)) | 379 logging.info('Running %s, cwd=%s' % (cmd, cwd)) |
| 377 return subprocess.call(cmd, cwd=cwd) | 380 return subprocess.call(cmd, cwd=cwd) |
| 378 finally: | 381 finally: |
| 379 run_test_from_archive.rmtree(outdir) | 382 run_test_from_archive.rmtree(outdir) |
| 380 | 383 |
| 381 | 384 |
| 382 def MODEtrace( | 385 def MODEtrace( |
| 383 _outdir, indir, _dictfiles, _read_only, cmd, relative_cwd, resultfile): | 386 _outdir, indir, _dictfiles, _read_only, cmd, relative_cwd, resultfile): |
| 384 """Shortcut to use trace_inputs.py properly. | 387 """Shortcut to use trace_inputs.py properly. |
| 385 | 388 |
| 386 It constructs the equivalent of dictfiles. It is hardcoded to base the | 389 It constructs the equivalent of dictfiles. It is hardcoded to base the |
| 387 checkout at src/. | 390 checkout at src/. |
| 388 """ | 391 """ |
| 389 logging.info('Running %s, cwd=%s' % (cmd, os.path.join(indir, relative_cwd))) | 392 logging.info('Running %s, cwd=%s' % (cmd, os.path.join(indir, relative_cwd))) |
| 390 if resultfile: | 393 if resultfile: |
| 391 # Guesswork here. | 394 # Guesswork here. |
| 392 product_dir = os.path.dirname(resultfile) | 395 product_dir = os.path.dirname(resultfile) |
| 393 if product_dir and indir: | 396 if product_dir and indir: |
| 394 product_dir = os.path.relpath(product_dir, indir) | 397 product_dir = os.path.relpath(product_dir, indir) |
| 395 else: | 398 else: |
| 396 product_dir = None | 399 product_dir = None |
| 400 if not cmd: |
| 401 print 'No command to run' |
| 402 return 1 |
| 397 return trace_inputs.trace_inputs( | 403 return trace_inputs.trace_inputs( |
| 398 '%s.log' % resultfile, | 404 '%s.log' % resultfile, |
| 399 cmd, | 405 cmd, |
| 400 indir, | 406 indir, |
| 401 relative_cwd, | 407 relative_cwd, |
| 402 product_dir, | 408 product_dir, |
| 403 False) | 409 False) |
| 404 | 410 |
| 405 | 411 |
| 406 def get_valid_modes(): | 412 def get_valid_modes(): |
| 407 """Returns the modes that can be used.""" | 413 """Returns the modes that can be used.""" |
| 408 return sorted( | 414 return sorted( |
| 409 i[4:] for i in dir(sys.modules[__name__]) if i.startswith('MODE')) | 415 i[4:] for i in dir(sys.modules[__name__]) if i.startswith('MODE')) |
| 410 | 416 |
| 411 | 417 |
| 412 def main(): | 418 def main(): |
| 413 default_variables = ['OS=%s' % trace_inputs.get_flavor()] | 419 default_variables = ['OS=%s' % trace_inputs.get_flavor()] |
| 414 if sys.platform in ('win32', 'cygwin'): | 420 if sys.platform in ('win32', 'cygwin'): |
| 415 default_variables.append('EXECUTABLE_SUFFIX=.exe') | 421 default_variables.append('EXECUTABLE_SUFFIX=.exe') |
| 416 else: | 422 else: |
| 417 default_variables.append('EXECUTABLE_SUFFIX=') | 423 default_variables.append('EXECUTABLE_SUFFIX=') |
| 418 valid_modes = get_valid_modes() | 424 valid_modes = get_valid_modes() |
| 419 parser = optparse.OptionParser( | 425 parser = optparse.OptionParser( |
| 420 usage='%prog [options] [.isolate file]', | 426 usage='%prog [options] [.isolate file]', |
| 421 description=sys.modules[__name__].__doc__) | 427 description=sys.modules[__name__].__doc__) |
| 422 parser.format_description = lambda *_: parser.description | 428 parser.format_description = lambda *_: parser.description |
| 423 parser.add_option( | 429 parser.add_option( |
| 424 '-v', '--verbose', | 430 '-v', '--verbose', |
| 425 action='count', | 431 action='count', |
| 426 default=2 if 'ISOLATE_DEBUG' in os.environ else 0, | 432 default=int(os.environ.get('ISOLATE_DEBUG', 0)), |
| 427 help='Use multiple times') | 433 help='Use multiple times') |
| 428 parser.add_option( | 434 parser.add_option( |
| 429 '-m', '--mode', | 435 '-m', '--mode', |
| 430 choices=valid_modes, | 436 choices=valid_modes, |
| 431 help='Determines the action to be taken: %s' % ', '.join(valid_modes)) | 437 help='Determines the action to be taken: %s' % ', '.join(valid_modes)) |
| 432 parser.add_option( | 438 parser.add_option( |
| 433 '-r', '--result', | 439 '-r', '--result', |
| 434 metavar='FILE', | 440 metavar='FILE', |
| 435 help='Result file to store the json manifest') | 441 help='Result file to store the json manifest') |
| 436 parser.add_option( | 442 parser.add_option( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 command, | 523 command, |
| 518 relative_dir, | 524 relative_dir, |
| 519 options.result) | 525 options.result) |
| 520 except run_test_from_archive.MappingError, e: | 526 except run_test_from_archive.MappingError, e: |
| 521 print >> sys.stderr, str(e) | 527 print >> sys.stderr, str(e) |
| 522 return 1 | 528 return 1 |
| 523 | 529 |
| 524 | 530 |
| 525 if __name__ == '__main__': | 531 if __name__ == '__main__': |
| 526 sys.exit(main()) | 532 sys.exit(main()) |
| OLD | NEW |