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

Side by Side Diff: sky/tools/mojo_cache_linker.py

Issue 868253006: Replace usage of md5 with sha256 for generation of mojo app ids. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse 6 import argparse
7 import logging 7 import logging
8 import os 8 import os
9 import sys 9 import sys
10 import subprocess 10 import subprocess
(...skipping 26 matching lines...) Expand all
37 except: 37 except:
38 return None 38 return None
39 return cache.get(path) 39 return cache.get(path)
40 40
41 41
42 def compute_path_to_app_id_map(paths, cache, cache_mtime): 42 def compute_path_to_app_id_map(paths, cache, cache_mtime):
43 path_to_app_id_map = {} 43 path_to_app_id_map = {}
44 for path in paths: 44 for path in paths:
45 app_id = get_cached_app_id(path, cache, cache_mtime) 45 app_id = get_cached_app_id(path, cache, cache_mtime)
46 if not app_id: 46 if not app_id:
47 logging.info('md5sum %s' % path) 47 logging.info('sha256sum %s' % path)
48 # Example output: 48 # Example output:
49 # f82a3551478a9a0e010adccd675053b9 png_viewer.mojo 49 # f82a3551478a9a0e010adccd675053b9 png_viewer.mojo
50 output = subprocess.check_output(['md5sum', path]) 50 output = subprocess.check_output(['sha256sum', path])
51 app_id = output.strip().split()[0] 51 app_id = output.strip().split()[0]
52 path_to_app_id_map[path] = app_id 52 path_to_app_id_map[path] = app_id
53 return path_to_app_id_map 53 return path_to_app_id_map
54 54
55 55
56 def read_app_id_cache(cache_path): 56 def read_app_id_cache(cache_path):
57 try: 57 try:
58 with open(cache_path, 'r') as cache_file: 58 with open(cache_path, 'r') as cache_file:
59 return json.load(cache_file), os.path.getmtime(cache_path) 59 return json.load(cache_file), os.path.getmtime(cache_path)
60 except: 60 except:
(...skipping 10 matching lines...) Expand all
71 71
72 72
73 # TODO(eseidel): Share logic with tools/android_stack_parser/stack 73 # TODO(eseidel): Share logic with tools/android_stack_parser/stack
74 def main(): 74 def main():
75 logging.basicConfig(level=logging.WARN) 75 logging.basicConfig(level=logging.WARN)
76 parser = argparse.ArgumentParser( 76 parser = argparse.ArgumentParser(
77 description='Builds a directory of app_id symlinks to symbols' 77 description='Builds a directory of app_id symlinks to symbols'
78 ' to match expected dlopen names from mojo_shell\'s NetworkLoader.') 78 ' to match expected dlopen names from mojo_shell\'s NetworkLoader.')
79 parser.add_argument('links_dir', type=str) 79 parser.add_argument('links_dir', type=str)
80 parser.add_argument('build_dir', type=str) 80 parser.add_argument('build_dir', type=str)
81 parser.add_argument('-f', '--force', action='store_true')
82 parser.add_argument('-v', '--verbose', action='store_true')
81 args = parser.parse_args() 83 args = parser.parse_args()
82 84
85 if args.verbose:
86 logging.getLogger().setLevel(logging.INFO)
87
83 if not os.path.isdir(args.links_dir): 88 if not os.path.isdir(args.links_dir):
84 logging.fatal('links_dir: %s is not a directory' % args.links_dir) 89 logging.fatal('links_dir: %s is not a directory' % args.links_dir)
85 sys.exit(1) 90 sys.exit(1)
86 91
87 # Some of the .so files are 100s of megabytes. Cache the md5s to save time. 92 # Some of the .so files are 100s of megabytes. Cache the md5s to save time.
88 cache_path = os.path.join(args.build_dir, '.app_id_cache') 93 cache_path = os.path.join(args.build_dir, '.app_id_cache')
89 cache, cache_mtime = read_app_id_cache(cache_path) 94 cache, cache_mtime = read_app_id_cache(cache_path)
95 if args.force:
96 cache_mtime = None
90 97
91 paths = library_paths(args.build_dir) 98 paths = library_paths(args.build_dir)
92 path_to_app_id_map = compute_path_to_app_id_map(list(paths), 99 path_to_app_id_map = compute_path_to_app_id_map(list(paths),
93 cache, cache_mtime) 100 cache, cache_mtime)
94 101
95 # The cache contains unmodified app-ids. 102 # The cache contains unmodified app-ids.
96 write_app_id_cache(cache_path, path_to_app_id_map) 103 write_app_id_cache(cache_path, path_to_app_id_map)
97 104
98 for path, app_id in path_to_app_id_map.items(): 105 for path, app_id in path_to_app_id_map.items():
99 basename = os.path.basename(path) 106 basename = os.path.basename(path)
(...skipping 13 matching lines...) Expand all
113 120
114 if os.path.lexists(link_path): 121 if os.path.lexists(link_path):
115 logging.debug('link already exists %s, replacing' % path) 122 logging.debug('link already exists %s, replacing' % path)
116 os.unlink(link_path) 123 os.unlink(link_path)
117 124
118 os.symlink(path, link_path) 125 os.symlink(path, link_path)
119 126
120 127
121 if __name__ == '__main__': 128 if __name__ == '__main__':
122 main() 129 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698