Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Scans build output directory for .isolated files, calculates their SHA1 | |
| 7 hashes, stores final list in JSON document and then removes *.isolated files | |
| 8 found (to ensure no stale *.isolated stay around on the next build). | |
| 9 | |
| 10 Used to figure out what tests were build in isolated mode to trigger these | |
| 11 tests to run on swarming. | |
| 12 | |
| 13 For more info see: | |
| 14 https://sites.google.com/a/chromium.org/dev/developers/testing/isolated-testing | |
| 15 """ | |
| 16 | |
| 17 import glob | |
| 18 import hashlib | |
| 19 import json | |
| 20 import optparse | |
| 21 import os | |
| 22 import re | |
| 23 import sys | |
| 24 | |
| 25 | |
| 26 def hash_file(filepath): | |
| 27 """Calculates the hash of a file without reading it all in memory at once.""" | |
| 28 digest = hashlib.sha1() | |
| 29 with open(filepath, 'rb') as f: | |
| 30 while True: | |
| 31 chunk = f.read(1024*1024) | |
| 32 if not chunk: | |
| 33 break | |
| 34 digest.update(chunk) | |
| 35 return digest.hexdigest() | |
| 36 | |
| 37 | |
| 38 def main(): | |
| 39 parser = optparse.OptionParser( | |
| 40 usage='%prog --build-dir <path> --output-json <path>', | |
| 41 description=sys.modules[__name__].__doc__) | |
| 42 parser.add_option( | |
| 43 '--build-dir', | |
| 44 help='Path to a directory to search for *.isolated files.') | |
| 45 parser.add_option( | |
| 46 '--output-json', | |
| 47 help='File to dump JSON results into.') | |
| 48 | |
| 49 options, _ = parser.parse_args() | |
| 50 build_dir = options.build_dir | |
|
M-A Ruel
2014/02/28 19:25:02
why, you want so save space on line 60? I'd person
Vadim Sh.
2014/02/28 19:30:04
Okay.. 'for' line didn't fit into 80 chars (and I
| |
| 51 if not build_dir: | |
| 52 parser.error('--build-dir option is required') | |
| 53 output_json = options.output_json | |
| 54 if not output_json: | |
| 55 parser.error('--output-json option is required') | |
| 56 | |
| 57 result = {} | |
| 58 | |
| 59 # Get the file hash values and output the pair. | |
| 60 for filepath in sorted(glob.glob(os.path.join(build_dir, '*.isolated'))): | |
| 61 test_name = os.path.splitext(os.path.basename(filepath))[0] | |
| 62 if re.match(r'^.+?\.\d$', test_name): | |
| 63 # It's a split .isolated file, e.g. foo.0.isolated. Ignore these. | |
| 64 continue | |
| 65 | |
| 66 # TODO(csharp): Remove deletion once the isolate tracked dependencies are | |
| 67 # inputs for the isolated files. | |
| 68 sha1_hash = hash_file(filepath) | |
| 69 os.remove(filepath) | |
| 70 result[test_name] = sha1_hash | |
| 71 | |
| 72 with open(output_json, 'wb') as f: | |
| 73 json.dump(result, f) | |
| 74 | |
| 75 return 0 | |
| 76 | |
| 77 | |
| 78 if __name__ == '__main__': | |
| 79 sys.exit(main()) | |
| OLD | NEW |