Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(808)

Unified Diff: mojo/devtools/common/devtoolslib/default_paths.py

Issue 1242453003: Extract the shell runner into devtools. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/devtools/common/devtoolslib/default_paths.py
diff --git a/mojo/devtools/common/devtoolslib/default_paths.py b/mojo/devtools/common/devtoolslib/default_paths.py
new file mode 100644
index 0000000000000000000000000000000000000000..f25b08e9ac8ecf4ca97f80005385e2cb58dd1b52
--- /dev/null
+++ b/mojo/devtools/common/devtoolslib/default_paths.py
@@ -0,0 +1,58 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Supports inferring locations of files in default checkout layouts.
+
+These functions allow devtools scripts to work out-of-the-box with regular Mojo
+checkouts.
+"""
+
+import os.path
+
+
+def _lowest_ancestor_containing_relpath(relpath):
+ """Returns the lowest ancestor of this file that contains |relpath|."""
+ cur_dir_path = os.path.abspath(os.path.dirname(__file__))
+ while True:
+ if os.path.exists(os.path.join(cur_dir_path, relpath)):
+ return cur_dir_path
+
+ next_dir_path = os.path.dirname(cur_dir_path)
+ if next_dir_path != cur_dir_path:
+ cur_dir_path = next_dir_path
+ else:
+ return None
+
+
+def infer_default_paths(is_android, is_debug, target_cpu):
+ """Infers the locations of select build output artifacts in a regular Mojo
+ checkout.
+
+ Returns:
+ Tuple of path dictionary, error message. Only one of the two will be
+ not-None.
+ """
+ build_dir = (('android_' if is_android else '') +
+ (target_cpu + '_' if target_cpu else '') +
+ ('Debug' if is_debug else 'Release'))
+ out_build_dir = os.path.join('out', build_dir)
+
+ root_path = _lowest_ancestor_containing_relpath(out_build_dir)
+ if not root_path:
+ return None, ('Failed to find build directory: ' + out_build_dir)
+
+ paths = {}
+ paths['root'] = root_path
+ build_dir_path = os.path.join(root_path, out_build_dir)
+ paths['build'] = build_dir_path
+ if is_android:
+ paths['shell'] = os.path.join(build_dir_path, 'apks', 'MojoShell.apk')
+ paths['adb'] = os.path.join(root_path, 'third_party', 'android_tools',
+ 'sdk', 'platform-tools', 'adb')
+ else:
+ paths['shell'] = os.path.join(build_dir_path, 'mojo_shell')
+
+ paths['sky_packages'] = os.path.join(build_dir_path, 'gen', 'dart-pkg',
+ 'packages')
+ return paths, ''
qsr 2015/07/16 14:19:20 According to your doc, this should be paths, None
ppi 2015/07/16 14:23:45 Done.
« no previous file with comments | « README.md ('k') | mojo/devtools/common/mojo_shell » ('j') | mojo/tools/mojo_shell.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698