| OLD | NEW |
| 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 |
| 11 import json | 11 import json |
| 12 import platform |
| 12 | 13 |
| 13 | 14 |
| 14 def library_paths(build_dir): | 15 def library_paths(build_dir): |
| 15 for name in os.listdir(build_dir): | 16 for name in os.listdir(build_dir): |
| 16 path = os.path.realpath(os.path.join(build_dir, name)) | 17 path = os.path.realpath(os.path.join(build_dir, name)) |
| 17 if not os.path.isfile(path): | 18 if not os.path.isfile(path): |
| 18 continue | 19 continue |
| 19 | 20 |
| 20 # Only include suffixes we care about: | 21 # Only include suffixes we care about: |
| 21 basename, ext = os.path.splitext(name) | 22 basename, ext = os.path.splitext(name) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 37 except: | 38 except: |
| 38 return None | 39 return None |
| 39 return cache.get(path) | 40 return cache.get(path) |
| 40 | 41 |
| 41 | 42 |
| 42 def compute_path_to_app_id_map(paths, cache, cache_mtime): | 43 def compute_path_to_app_id_map(paths, cache, cache_mtime): |
| 43 path_to_app_id_map = {} | 44 path_to_app_id_map = {} |
| 44 for path in paths: | 45 for path in paths: |
| 45 app_id = get_cached_app_id(path, cache, cache_mtime) | 46 app_id = get_cached_app_id(path, cache, cache_mtime) |
| 46 if not app_id: | 47 if not app_id: |
| 47 logging.info('sha256sum %s' % path) | 48 if platform.system() == 'Darwin': |
| 49 logging.info('shasum -a 256 %s' % path) |
| 50 output = subprocess.check_output(['shasum', '-a', '256', path]) |
| 51 else: |
| 52 logging.info('sha256sum %s' % path) |
| 53 output = subprocess.check_output(['sha256sum', path]) |
| 48 # Example output: | 54 # Example output: |
| 49 # f82a3551478a9a0e010adccd675053b9 png_viewer.mojo | 55 # f82a3551478a9a0e010adccd675053b9 png_viewer.mojo |
| 50 output = subprocess.check_output(['sha256sum', path]) | |
| 51 app_id = output.strip().split()[0] | 56 app_id = output.strip().split()[0] |
| 52 path_to_app_id_map[path] = app_id | 57 path_to_app_id_map[path] = app_id |
| 53 return path_to_app_id_map | 58 return path_to_app_id_map |
| 54 | 59 |
| 55 | 60 |
| 56 def read_app_id_cache(cache_path): | 61 def read_app_id_cache(cache_path): |
| 57 try: | 62 try: |
| 58 with open(cache_path, 'r') as cache_file: | 63 with open(cache_path, 'r') as cache_file: |
| 59 return json.load(cache_file), os.path.getmtime(cache_path) | 64 return json.load(cache_file), os.path.getmtime(cache_path) |
| 60 except: | 65 except: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 125 |
| 121 if os.path.lexists(link_path): | 126 if os.path.lexists(link_path): |
| 122 logging.debug('link already exists %s, replacing' % path) | 127 logging.debug('link already exists %s, replacing' % path) |
| 123 os.unlink(link_path) | 128 os.unlink(link_path) |
| 124 | 129 |
| 125 os.symlink(path, link_path) | 130 os.symlink(path, link_path) |
| 126 | 131 |
| 127 | 132 |
| 128 if __name__ == '__main__': | 133 if __name__ == '__main__': |
| 129 main() | 134 main() |
| OLD | NEW |