Index: lib/cros_build_lib.py |
diff --git a/lib/cros_build_lib.py b/lib/cros_build_lib.py |
index 71c908648f764575433251a16b45ff181df03f2e..47c8f96ae659b6b31394da97f78107f0e10ffa9d 100644 |
--- a/lib/cros_build_lib.py |
+++ b/lib/cros_build_lib.py |
@@ -136,3 +136,36 @@ def Info(message): |
""" |
print >> sys.stderr, ( |
Color(_STDOUT_IS_TTY).Color(Color.BLUE, '\nINFO: ' + message)) |
+ |
+ |
+def FindRepoDir(): |
+ """Returns the nearest higher-level repo dir from the cwd.""" |
+ cwd = os.getcwd() |
+ while cwd != '/': |
+ repo_dir = os.path.join(cwd, '.repo') |
+ if os.path.isdir(repo_dir): |
+ return repo_dir |
+ cwd = os.path.dirname(cwd) |
+ return None |
+ |
+ |
+def ReinterpretPathForChroot(path): |
+ """Returns reinterpreted path from outside the chroot for use inside. |
+ |
+ Keyword arguments: |
+ path: The path to reinterpret. Must be in src tree. |
+ """ |
+ root_path = os.path.join(FindRepoDir(), '..') |
+ |
+ path_abs_path = os.path.abspath(path) |
+ root_abs_path = os.path.abspath(root_path) |
+ |
+ # Strip the repository root from the path and strip first /. |
+ relative_path = path_abs_path.replace(root_abs_path, '')[1:] |
+ |
+ if relative_path == path_abs_path: |
+ raise Exception('Error: path is outside your src tree, cannot reinterpret.') |
+ |
+ new_path = os.path.join('/home', os.getenv('USER'), 'trunk', relative_path) |
+ return new_path |
+ |