Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import hashlib | 5 import hashlib |
| 6 import logging | 6 import logging |
| 7 import platform | 7 import platform |
| 8 import subprocess | 8 import subprocess |
| 9 import sys | 9 import sys |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 rv = [] | 54 rv = [] |
| 55 for line in lines: | 55 for line in lines: |
| 56 i = line.find('/') | 56 i = line.find('/') |
| 57 if i < 0: | 57 if i < 0: |
| 58 _logging.debug(" => no file found in line: %s", line) | 58 _logging.debug(" => no file found in line: %s", line) |
| 59 continue | 59 continue |
| 60 rv.append(line[i:].split(None, 1)[0]) | 60 rv.append(line[i:].split(None, 1)[0]) |
| 61 _logging.debug(" => %s", rv) | 61 _logging.debug(" => %s", rv) |
| 62 return rv | 62 return rv |
| 63 | 63 |
| 64 def transitive_hash(filename): | 64 def transitive_hash(filename, transitive=True): |
|
viettrungluu
2014/11/20 17:32:24
Move _file_hash() into its own file and use that i
qsr
2014/11/21 13:51:46
Done.
| |
| 65 """Returns a string that represents the "transitive" hash of the given | 65 """Returns a string that represents the "transitive" hash of the given |
| 66 file. The transitive hash is a hash of the file and all the shared libraries | 66 file. The transitive hash is a hash of the file and all the shared libraries |
| 67 on which it depends (done in an order-independent way).""" | 67 on which it depends (done in an order-independent way).""" |
| 68 hashes = set() | 68 hashes = set() |
| 69 to_hash = [filename] | 69 to_hash = [filename] |
| 70 while to_hash: | 70 while to_hash: |
| 71 current_filename = realpath(to_hash.pop()) | 71 current_filename = realpath(to_hash.pop()) |
| 72 current_hash = _file_hash(current_filename) | 72 current_hash = _file_hash(current_filename) |
| 73 if current_hash in hashes: | 73 if current_hash in hashes: |
| 74 _logging.debug("Already seen %s (%s) ...", current_filename, current_hash) | 74 _logging.debug("Already seen %s (%s) ...", current_filename, current_hash) |
| 75 continue | 75 continue |
| 76 _logging.debug("Haven't seen %s (%s) ...", current_filename, current_hash) | 76 _logging.debug("Haven't seen %s (%s) ...", current_filename, current_hash) |
| 77 hashes.add(current_hash) | 77 hashes.add(current_hash) |
| 78 to_hash.extend(_get_dependencies(current_filename)) | 78 if transitive: |
| 79 to_hash.extend(_get_dependencies(current_filename)) | |
| 79 return sha256('|'.join(sorted(hashes))).hexdigest() | 80 return sha256('|'.join(sorted(hashes))).hexdigest() |
| 80 | 81 |
| 81 def main(argv): | 82 def main(argv): |
| 82 logging.basicConfig() | 83 logging.basicConfig() |
| 83 # Uncomment to debug: | 84 # Uncomment to debug: |
| 84 # _logging.setLevel(logging.DEBUG) | 85 # _logging.setLevel(logging.DEBUG) |
| 85 | 86 |
| 86 if len(argv) < 2: | 87 if len(argv) < 2: |
| 87 print """\ | 88 print """\ |
| 88 Usage: %s [file] ... | 89 Usage: %s [file] ... |
| 89 | 90 |
| 90 Prints the \"transitive\" hash of each (executable) file. The transitive | 91 Prints the \"transitive\" hash of each (executable) file. The transitive |
| 91 hash is a hash of the file and all the shared libraries on which it | 92 hash is a hash of the file and all the shared libraries on which it |
| 92 depends (done in an order-independent way).""" % basename(argv[0]) | 93 depends (done in an order-independent way).""" % basename(argv[0]) |
| 93 return 0 | 94 return 0 |
| 94 | 95 |
| 95 rv = 0 | 96 rv = 0 |
| 96 for filename in argv[1:]: | 97 for filename in argv[1:]: |
| 97 try: | 98 try: |
| 98 print transitive_hash(filename), filename | 99 print transitive_hash(filename), filename |
| 99 except subprocess.CalledProcessError: | 100 except subprocess.CalledProcessError: |
| 100 print "ERROR", filename | 101 print "ERROR", filename |
| 101 rv = 1 | 102 rv = 1 |
| 102 return rv | 103 return rv |
| 103 | 104 |
| 104 if __name__ == '__main__': | 105 if __name__ == '__main__': |
| 105 sys.exit(main(sys.argv)) | 106 sys.exit(main(sys.argv)) |
| OLD | NEW |