Chromium Code Reviews| Index: mojo/tools/mopy/transitive_hash.py |
| diff --git a/mojo/tools/mopy/transitive_hash.py b/mojo/tools/mopy/transitive_hash.py |
| index 6864ae394dcd14e866c80b590037459b7af993aa..b7742432ff2f32137023cc82a03d2e91c94fc3bf 100644 |
| --- a/mojo/tools/mopy/transitive_hash.py |
| +++ b/mojo/tools/mopy/transitive_hash.py |
| @@ -2,7 +2,9 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import hashlib |
| import logging |
| +import platform |
| import subprocess |
| import sys |
| @@ -27,16 +29,25 @@ def _memoize(f): |
| return Memoize().__getitem__ |
| @_memoize |
| -def _file_hash(filename): |
| - """Returns a string representing the hash of the given file.""" |
| - _logging.debug("Hashing %s ...", filename) |
| - rv = subprocess.check_output(['sha256sum', '-b', filename]).split(None, 1)[0] |
| - _logging.debug(" => %s", rv) |
| - return rv |
| +def _file_hash(filename): |
| + """Returns a string representing the hash of the given file.""" |
| + _logging.debug("Hashing %s ...", filename) |
| + with open(filename, mode='rb') as f: |
|
viettrungluu
2014/11/11 18:35:38
What's the performance of this versus running sha2
jam
2014/11/11 20:09:32
it's about 10% faster. probably because it doesn't
|
| + m = hashlib.sha256() |
| + while True: |
| + block = f.read(4096) |
| + if not block: |
| + break |
| + _logging.debug(" => %s", m.hexdigest()) |
| + return m.hexdigest() |
| @_memoize |
| def _get_dependencies(filename): |
| """Returns a list of filenames for files that the given file depends on.""" |
| + if platform.system() == 'Windows': |
| + # There's no ldd on Windows. We can try to bundle or require depends, but |
| + # given that we're not supporting component build this seems low priority. |
| + return [] |
| _logging.debug("Getting dependencies for %s ...", filename) |
| lines = subprocess.check_output(['ldd', filename]).splitlines() |
| rv = [] |