| 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 collections |
| 12 import os.path | 12 import os.path |
| 13 import sys | 13 import sys |
| 14 | 14 |
| 15 | 15 |
| 16 def find_ancestor_with(relpath): | 16 def find_ancestor_with(relpath, start_path=None): |
| 17 """Returns the lowest ancestor of this file that contains |relpath|.""" | 17 """Returns the lowest ancestor of this file that contains |relpath|.""" |
| 18 cur_dir_path = os.path.abspath(os.path.dirname(__file__)) | 18 cur_dir_path = start_path or os.path.abspath(os.path.dirname(__file__)) |
| 19 while True: | 19 while True: |
| 20 if os.path.exists(os.path.join(cur_dir_path, relpath)): | 20 if os.path.exists(os.path.join(cur_dir_path, relpath)): |
| 21 return cur_dir_path | 21 return cur_dir_path |
| 22 | 22 |
| 23 next_dir_path = os.path.dirname(cur_dir_path) | 23 next_dir_path = os.path.dirname(cur_dir_path) |
| 24 if next_dir_path != cur_dir_path: | 24 if next_dir_path != cur_dir_path: |
| 25 cur_dir_path = next_dir_path | 25 cur_dir_path = next_dir_path |
| 26 else: | 26 else: |
| 27 return None | 27 return None |
| 28 | 28 |
| 29 | 29 |
| 30 def find_within_ancestors(target_relpath, start_path=None): |
| 31 """Returns the absolute path to |target_relpath| in the lowest ancestor of |
| 32 |start_path| that contains it. |
| 33 """ |
| 34 ancestor = find_ancestor_with(target_relpath, start_path) |
| 35 if not ancestor: |
| 36 return None |
| 37 return os.path.join(ancestor, target_relpath) |
| 38 |
| 39 |
| 30 def infer_paths(is_android, is_debug, target_cpu): | 40 def infer_paths(is_android, is_debug, target_cpu): |
| 31 """Infers the locations of select build output artifacts in a regular | 41 """Infers the locations of select build output artifacts in a regular |
| 32 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 |
| 33 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. |
| 34 | 44 |
| 35 Returns: | 45 Returns: |
| 36 Defaultdict with the inferred paths. | 46 Defaultdict with the inferred paths. |
| 37 """ | 47 """ |
| 38 build_dir = (('android_' if is_android else '') + | 48 build_dir = (('android_' if is_android else '') + |
| 39 (target_cpu + '_' if target_cpu else '') + | 49 (target_cpu + '_' if target_cpu else '') + |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 # Rare case, it's not even in PATH, look upward up to root. | 87 # Rare case, it's not even in PATH, look upward up to root. |
| 78 root_dir = os.path.dirname(os.path.abspath(__file__)) | 88 root_dir = os.path.dirname(os.path.abspath(__file__)) |
| 79 previous_dir = os.path.abspath(__file__) | 89 previous_dir = os.path.abspath(__file__) |
| 80 while root_dir and root_dir != previous_dir: | 90 while root_dir and root_dir != previous_dir: |
| 81 i = os.path.join(root_dir, 'depot_tools') | 91 i = os.path.join(root_dir, 'depot_tools') |
| 82 if _is_real_depot_tools(i): | 92 if _is_real_depot_tools(i): |
| 83 return i | 93 return i |
| 84 previous_dir = root_dir | 94 previous_dir = root_dir |
| 85 root_dir = os.path.dirname(root_dir) | 95 root_dir = os.path.dirname(root_dir) |
| 86 return None | 96 return None |
| OLD | NEW |