| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 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 """Supports inferring locations of files in default checkout layouts. | 5 """Supports inferring locations of files in default checkout layouts. |
| 6 | 6 |
| 7 These functions allow devtools scripts to work out-of-the-box with regular Mojo | 7 These functions allow devtools scripts to work out-of-the-box with regular Mojo |
| 8 checkouts. | 8 checkouts. |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import collections |
| 11 import os.path | 12 import os.path |
| 12 import sys | 13 import sys |
| 13 | 14 |
| 14 | 15 |
| 15 def find_ancestor_with(relpath): | 16 def find_ancestor_with(relpath): |
| 16 """Returns the lowest ancestor of this file that contains |relpath|.""" | 17 """Returns the lowest ancestor of this file that contains |relpath|.""" |
| 17 cur_dir_path = os.path.abspath(os.path.dirname(__file__)) | 18 cur_dir_path = os.path.abspath(os.path.dirname(__file__)) |
| 18 while True: | 19 while True: |
| 19 if os.path.exists(os.path.join(cur_dir_path, relpath)): | 20 if os.path.exists(os.path.join(cur_dir_path, relpath)): |
| 20 return cur_dir_path | 21 return cur_dir_path |
| 21 | 22 |
| 22 next_dir_path = os.path.dirname(cur_dir_path) | 23 next_dir_path = os.path.dirname(cur_dir_path) |
| 23 if next_dir_path != cur_dir_path: | 24 if next_dir_path != cur_dir_path: |
| 24 cur_dir_path = next_dir_path | 25 cur_dir_path = next_dir_path |
| 25 else: | 26 else: |
| 26 return None | 27 return None |
| 27 | 28 |
| 28 | 29 |
| 29 def infer_mojo_paths(is_android, is_debug, target_cpu): | 30 def infer_paths(is_android, is_debug, target_cpu): |
| 30 """Infers the locations of select build output artifacts in a regular Mojo | 31 """Infers the locations of select build output artifacts in a regular |
| 31 checkout. | 32 Chromium-like checkout. This should grow thinner or disappear as we introduce |
| 33 per-repo config files, see https://github.com/domokit/devtools/issues/28. |
| 32 | 34 |
| 33 Returns: | 35 Returns: |
| 34 Tuple of path dictionary, error message. Only one of the two will be | 36 Defaultdict with the inferred paths. |
| 35 not-None. | |
| 36 """ | 37 """ |
| 37 build_dir = (('android_' if is_android else '') + | 38 build_dir = (('android_' if is_android else '') + |
| 38 (target_cpu + '_' if target_cpu else '') + | 39 (target_cpu + '_' if target_cpu else '') + |
| 39 ('Debug' if is_debug else 'Release')) | 40 ('Debug' if is_debug else 'Release')) |
| 40 out_build_dir = os.path.join('out', build_dir) | 41 out_build_dir = os.path.join('out', build_dir) |
| 41 | 42 |
| 42 root_path = find_ancestor_with(out_build_dir) | 43 root_path = find_ancestor_with(out_build_dir) |
| 44 paths = collections.defaultdict(lambda: None) |
| 43 if not root_path: | 45 if not root_path: |
| 44 return None, ('Failed to find build directory: ' + out_build_dir) | 46 return paths |
| 45 | 47 |
| 46 paths = {} | |
| 47 paths['root'] = root_path | |
| 48 build_dir_path = os.path.join(root_path, out_build_dir) | 48 build_dir_path = os.path.join(root_path, out_build_dir) |
| 49 paths['build'] = build_dir_path | 49 paths['build_dir_path'] = build_dir_path |
| 50 if is_android: | 50 if is_android: |
| 51 paths['shell'] = os.path.join(build_dir_path, 'apks', 'MojoShell.apk') | 51 paths['shell_path'] = os.path.join(build_dir_path, 'apks', 'MojoShell.apk') |
| 52 paths['adb'] = os.path.join(root_path, 'third_party', 'android_tools', | 52 paths['adb_path'] = os.path.join(root_path, 'third_party', 'android_tools', |
| 53 'sdk', 'platform-tools', 'adb') | 53 'sdk', 'platform-tools', 'adb') |
| 54 else: | 54 else: |
| 55 paths['shell'] = os.path.join(build_dir_path, 'mojo_shell') | 55 paths['shell_path'] = os.path.join(build_dir_path, 'mojo_shell') |
| 56 return paths, None | 56 return paths |
| 57 | 57 |
| 58 | 58 |
| 59 # Based on Chromium //tools/find_depot_tools.py. | 59 # Based on Chromium //tools/find_depot_tools.py. |
| 60 def find_depot_tools(): | 60 def find_depot_tools(): |
| 61 """Searches for depot_tools. | 61 """Searches for depot_tools. |
| 62 | 62 |
| 63 Returns: | 63 Returns: |
| 64 Path to the depot_tools checkout present on the machine, None if not found. | 64 Path to the depot_tools checkout present on the machine, None if not found. |
| 65 """ | 65 """ |
| 66 def _is_real_depot_tools(path): | 66 def _is_real_depot_tools(path): |
| (...skipping 10 matching lines...) Expand all Loading... |
| 77 # Rare case, it's not even in PATH, look upward up to root. | 77 # Rare case, it's not even in PATH, look upward up to root. |
| 78 root_dir = os.path.dirname(os.path.abspath(__file__)) | 78 root_dir = os.path.dirname(os.path.abspath(__file__)) |
| 79 previous_dir = os.path.abspath(__file__) | 79 previous_dir = os.path.abspath(__file__) |
| 80 while root_dir and root_dir != previous_dir: | 80 while root_dir and root_dir != previous_dir: |
| 81 i = os.path.join(root_dir, 'depot_tools') | 81 i = os.path.join(root_dir, 'depot_tools') |
| 82 if _is_real_depot_tools(i): | 82 if _is_real_depot_tools(i): |
| 83 return i | 83 return i |
| 84 previous_dir = root_dir | 84 previous_dir = root_dir |
| 85 root_dir = os.path.dirname(root_dir) | 85 root_dir = os.path.dirname(root_dir) |
| 86 return None | 86 return None |
| OLD | NEW |