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

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

Issue 878933003: Move the apptest runner and parts of mopy to the public SDK. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 months 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/print_process_error.py ('k') | mojo/tools/mopy/version.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
deleted file mode 100644
index 740892b27c4b8db431c10e8fb46c8fe984b70620..0000000000000000000000000000000000000000
--- a/mojo/tools/mopy/transitive_hash.py
+++ /dev/null
@@ -1,80 +0,0 @@
-# Copyright 2014 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import logging
-import platform
-import subprocess
-import sys
-
-# pylint: disable=E0611
-from hashlib import sha256
-# pylint: enable=E0611
-from os.path import basename, realpath
-
-from mopy.file_hash import file_hash
-from mopy.memoize import memoize
-
-_logging = logging.getLogger()
-
-@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 = []
- for line in lines:
- i = line.find('/')
- if i < 0:
- _logging.debug(" => no file found in line: %s", line)
- continue
- rv.append(line[i:].split(None, 1)[0])
- _logging.debug(" => %s", rv)
- return rv
-
-def transitive_hash(filename):
- """Returns a string that represents the "transitive" hash of the given
- file. The transitive hash is a hash of the file and all the shared libraries
- on which it depends (done in an order-independent way)."""
- hashes = set()
- to_hash = [filename]
- while to_hash:
- current_filename = realpath(to_hash.pop())
- current_hash = file_hash(current_filename)
- if current_hash in hashes:
- _logging.debug("Already seen %s (%s) ...", current_filename, current_hash)
- continue
- _logging.debug("Haven't seen %s (%s) ...", current_filename, current_hash)
- hashes.add(current_hash)
- to_hash.extend(_get_dependencies(current_filename))
- return sha256('|'.join(sorted(hashes))).hexdigest()
-
-def main(argv):
- logging.basicConfig()
- # Uncomment to debug:
- # _logging.setLevel(logging.DEBUG)
-
- if len(argv) < 2:
- print """\
-Usage: %s [file] ...
-
-Prints the \"transitive\" hash of each (executable) file. The transitive
-hash is a hash of the file and all the shared libraries on which it
-depends (done in an order-independent way).""" % basename(argv[0])
- return 0
-
- rv = 0
- for filename in argv[1:]:
- try:
- print transitive_hash(filename), filename
- except subprocess.CalledProcessError:
- print "ERROR", filename
- rv = 1
- return rv
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv))
« no previous file with comments | « mojo/tools/mopy/print_process_error.py ('k') | mojo/tools/mopy/version.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698