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

Side by Side Diff: mojo/tools/mopy/transitive_hash.py

Issue 718773002: Make mojob.py test succeed on Windows. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
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 logging 6 import logging
7 import platform
6 import subprocess 8 import subprocess
7 import sys 9 import sys
8 10
9 # pylint: disable=E0611 11 # pylint: disable=E0611
10 from hashlib import sha256 12 from hashlib import sha256
11 # pylint: enable=E0611 13 # pylint: enable=E0611
12 from os.path import basename, realpath 14 from os.path import basename, realpath
13 15
14 _logging = logging.getLogger() 16 _logging = logging.getLogger()
15 17
16 # pylint: disable=C0301 18 # pylint: disable=C0301
17 # Based on/taken from 19 # Based on/taken from
18 # http://code.activestate.com/recipes/578231-probably-the-fastest-memoization- decorator-in-the-/ 20 # http://code.activestate.com/recipes/578231-probably-the-fastest-memoization- decorator-in-the-/
19 # (with cosmetic changes). 21 # (with cosmetic changes).
20 # pylint: enable=C0301 22 # pylint: enable=C0301
21 def _memoize(f): 23 def _memoize(f):
22 """Memoization decorator for a function taking a single argument.""" 24 """Memoization decorator for a function taking a single argument."""
23 class Memoize(dict): 25 class Memoize(dict):
24 def __missing__(self, key): 26 def __missing__(self, key):
25 rv = self[key] = f(key) 27 rv = self[key] = f(key)
26 return rv 28 return rv
27 return Memoize().__getitem__ 29 return Memoize().__getitem__
28 30
29 @_memoize 31 @_memoize
30 def _file_hash(filename): 32 def _file_hash(filename):
31 """Returns a string representing the hash of the given file.""" 33 """Returns a string representing the hash of the given file."""
32 _logging.debug("Hashing %s ...", filename) 34 _logging.debug("Hashing %s ...", filename)
33 rv = subprocess.check_output(['sha256sum', '-b', filename]).split(None, 1)[0] 35 with open(filename, mode='rb') as f:
34 _logging.debug(" => %s", rv) 36 m = hashlib.sha256()
35 return rv 37 while True:
38 block = f.read(4096)
39 if not block:
40 break
41 m.update(block)
42 _logging.debug(" => %s", m.hexdigest())
43 return m.hexdigest()
36 44
37 @_memoize 45 @_memoize
38 def _get_dependencies(filename): 46 def _get_dependencies(filename):
39 """Returns a list of filenames for files that the given file depends on.""" 47 """Returns a list of filenames for files that the given file depends on."""
48 if platform.system() == 'Windows':
49 # There's no ldd on Windows. We can try to bundle or require depends, but
50 # given that we're not supporting component build this seems low priority.
51 return []
40 _logging.debug("Getting dependencies for %s ...", filename) 52 _logging.debug("Getting dependencies for %s ...", filename)
41 lines = subprocess.check_output(['ldd', filename]).splitlines() 53 lines = subprocess.check_output(['ldd', filename]).splitlines()
42 rv = [] 54 rv = []
43 for line in lines: 55 for line in lines:
44 i = line.find('/') 56 i = line.find('/')
45 if i < 0: 57 if i < 0:
46 _logging.debug(" => no file found in line: %s", line) 58 _logging.debug(" => no file found in line: %s", line)
47 continue 59 continue
48 rv.append(line[i:].split(None, 1)[0]) 60 rv.append(line[i:].split(None, 1)[0])
49 _logging.debug(" => %s", rv) 61 _logging.debug(" => %s", rv)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 for filename in argv[1:]: 96 for filename in argv[1:]:
85 try: 97 try:
86 print transitive_hash(filename), filename 98 print transitive_hash(filename), filename
87 except subprocess.CalledProcessError: 99 except subprocess.CalledProcessError:
88 print "ERROR", filename 100 print "ERROR", filename
89 rv = 1 101 rv = 1
90 return rv 102 return rv
91 103
92 if __name__ == '__main__': 104 if __name__ == '__main__':
93 sys.exit(main(sys.argv)) 105 sys.exit(main(sys.argv))
OLDNEW
« mojo/tools/mojob.py ('K') | « mojo/tools/mojob.py ('k') | mojo/tools/test_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698