Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Unified Diff: mojo/tools/mopy/transitive_hash.py

Issue 728783003: Add infrastructure to run tests on android. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Follow review Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/tools/mopy/memoize.py ('k') | mojo/tools/test_runner.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/tools/mopy/transitive_hash.py
diff --git a/mojo/tools/mopy/transitive_hash.py b/mojo/tools/mopy/transitive_hash.py
index 48b6a60b21898fafd36a8c5a7bd41ef18168a3fb..740892b27c4b8db431c10e8fb46c8fe984b70620 100644
--- a/mojo/tools/mopy/transitive_hash.py
+++ b/mojo/tools/mopy/transitive_hash.py
@@ -2,7 +2,6 @@
# 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
@@ -13,36 +12,12 @@ from hashlib import sha256
# pylint: enable=E0611
from os.path import basename, realpath
-_logging = logging.getLogger()
-
-# pylint: disable=C0301
-# Based on/taken from
-# http://code.activestate.com/recipes/578231-probably-the-fastest-memoization-decorator-in-the-/
-# (with cosmetic changes).
-# pylint: enable=C0301
-def _memoize(f):
- """Memoization decorator for a function taking a single argument."""
- class Memoize(dict):
- def __missing__(self, key):
- rv = self[key] = f(key)
- return rv
- return Memoize().__getitem__
+from mopy.file_hash import file_hash
+from mopy.memoize import memoize
-@_memoize
-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:
- m = hashlib.sha256()
- while True:
- block = f.read(4096)
- if not block:
- break
- m.update(block)
- _logging.debug(" => %s", m.hexdigest())
- return m.hexdigest()
+_logging = logging.getLogger()
-@_memoize
+@memoize
def _get_dependencies(filename):
"""Returns a list of filenames for files that the given file depends on."""
if platform.system() == 'Windows':
@@ -69,7 +44,7 @@ def transitive_hash(filename):
to_hash = [filename]
while to_hash:
current_filename = realpath(to_hash.pop())
- current_hash = _file_hash(current_filename)
+ current_hash = file_hash(current_filename)
if current_hash in hashes:
_logging.debug("Already seen %s (%s) ...", current_filename, current_hash)
continue
« no previous file with comments | « mojo/tools/mopy/memoize.py ('k') | mojo/tools/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698