| 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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 def find_within_ancestors(target_relpath, start_path=None): | 30 def find_within_ancestors(target_relpath, start_path=None): |
| 31 """Returns the absolute path to |target_relpath| in the lowest ancestor of | 31 """Returns the absolute path to |target_relpath| in the lowest ancestor of |
| 32 |start_path| that contains it. | 32 |start_path| that contains it. |
| 33 """ | 33 """ |
| 34 ancestor = find_ancestor_with(target_relpath, start_path) | 34 ancestor = find_ancestor_with(target_relpath, start_path) |
| 35 if not ancestor: | 35 if not ancestor: |
| 36 return None | 36 return None |
| 37 return os.path.join(ancestor, target_relpath) | 37 return os.path.join(ancestor, target_relpath) |
| 38 | 38 |
| 39 | 39 |
| 40 def infer_paths(is_android, is_debug, target_cpu): | 40 def infer_params(is_android, is_debug, target_cpu): |
| 41 """Infers the locations of select build output artifacts in a regular | 41 """Infers the locations of select build output artifacts in a regular |
| 42 Chromium-like checkout. This should grow thinner or disappear as we introduce | 42 Chromium-like checkout. This should grow thinner or disappear as we introduce |
| 43 per-repo config files, see https://github.com/domokit/devtools/issues/28. | 43 per-repo config files, see https://github.com/domokit/devtools/issues/28. |
| 44 | 44 |
| 45 Returns: | 45 Returns: |
| 46 Defaultdict with the inferred paths. | 46 Defaultdict with the inferred paths. |
| 47 """ | 47 """ |
| 48 build_dir = (('android_' if is_android else '') + | 48 build_dir = (('android_' if is_android else '') + |
| 49 (target_cpu + '_' if target_cpu else '') + | 49 (target_cpu + '_' if target_cpu else '') + |
| 50 ('Debug' if is_debug else 'Release')) | 50 ('Debug' if is_debug else 'Release')) |
| 51 out_build_dir = os.path.join('out', build_dir) | 51 out_build_dir = os.path.join('out', build_dir) |
| 52 | 52 |
| 53 root_path = find_ancestor_with(out_build_dir) | 53 root_path = find_ancestor_with(out_build_dir) |
| 54 paths = collections.defaultdict(lambda: None) | 54 params = collections.defaultdict(lambda: None) |
| 55 if not root_path: | 55 if not root_path: |
| 56 return paths | 56 return params |
| 57 | 57 |
| 58 build_dir_path = os.path.join(root_path, out_build_dir) | 58 build_dir_path = os.path.join(root_path, out_build_dir) |
| 59 paths['build_dir_path'] = build_dir_path | 59 params['build_dir_path'] = build_dir_path |
| 60 if is_android: | 60 if is_android: |
| 61 paths['shell_path'] = os.path.join(build_dir_path, 'apks', 'MojoShell.apk') | 61 params['shell_path'] = os.path.join(build_dir_path, 'apks', 'MojoShell.apk') |
| 62 paths['adb_path'] = os.path.join(root_path, 'third_party', 'android_tools', | 62 params['adb_path'] = os.path.join(root_path, 'third_party', 'android_tools', |
| 63 'sdk', 'platform-tools', 'adb') | 63 'sdk', 'platform-tools', 'adb') |
| 64 else: | 64 else: |
| 65 paths['shell_path'] = os.path.join(build_dir_path, 'mojo_shell') | 65 params['shell_path'] = os.path.join(build_dir_path, 'mojo_shell') |
| 66 return paths | 66 |
| 67 mojo_version_file = find_within_ancestors('MOJO_VERSION') |
| 68 if mojo_version_file: |
| 69 with open(mojo_version_file) as f: |
| 70 params['mojo_version'] = f.read().strip() |
| 71 return params |
| 67 | 72 |
| 68 | 73 |
| 69 # Based on Chromium //tools/find_depot_tools.py. | 74 # Based on Chromium //tools/find_depot_tools.py. |
| 70 def find_depot_tools(): | 75 def find_depot_tools(): |
| 71 """Searches for depot_tools. | 76 """Searches for depot_tools. |
| 72 | 77 |
| 73 Returns: | 78 Returns: |
| 74 Path to the depot_tools checkout present on the machine, None if not found. | 79 Path to the depot_tools checkout present on the machine, None if not found. |
| 75 """ | 80 """ |
| 76 def _is_real_depot_tools(path): | 81 def _is_real_depot_tools(path): |
| (...skipping 10 matching lines...) Expand all Loading... |
| 87 # Rare case, it's not even in PATH, look upward up to root. | 92 # Rare case, it's not even in PATH, look upward up to root. |
| 88 root_dir = os.path.dirname(os.path.abspath(__file__)) | 93 root_dir = os.path.dirname(os.path.abspath(__file__)) |
| 89 previous_dir = os.path.abspath(__file__) | 94 previous_dir = os.path.abspath(__file__) |
| 90 while root_dir and root_dir != previous_dir: | 95 while root_dir and root_dir != previous_dir: |
| 91 i = os.path.join(root_dir, 'depot_tools') | 96 i = os.path.join(root_dir, 'depot_tools') |
| 92 if _is_real_depot_tools(i): | 97 if _is_real_depot_tools(i): |
| 93 return i | 98 return i |
| 94 previous_dir = root_dir | 99 previous_dir = root_dir |
| 95 root_dir = os.path.dirname(root_dir) | 100 root_dir = os.path.dirname(root_dir) |
| 96 return None | 101 return None |
| OLD | NEW |