Bug 1278890 - Add a method for normalizing test paths to the test package mach environment, r?armenzg
The test path structure is slightly different in the test package compared to a srcdir. So we may need
to normalize the specified paths such that they are relative to a srcdir. Because every test harness
needs to do this, this method is being added to the bootstrap for re-use.
MozReview-Commit-ID: fBAbfuG5XQ
--- a/testing/tools/mach_test_package_bootstrap.py
+++ b/testing/tools/mach_test_package_bootstrap.py
@@ -102,16 +102,26 @@ def find_firefox(context):
for path in search_paths:
try:
return mozinstall.get_binary(path, 'firefox')
except mozinstall.InvalidBinary:
continue
+def normalize_test_path(test_root, path):
+ if os.path.isabs(path) or os.path.exists(path):
+ return os.path.normpath(os.path.abspath(path))
+
+ for parent in ancestors(test_root):
+ test_path = os.path.join(parent, path)
+ if os.path.exists(test_path):
+ return os.path.normpath(os.path.abspath(test_path))
+
+
def bootstrap(test_package_root):
test_package_root = os.path.abspath(test_package_root)
# Ensure we are running Python 2.7+. We put this check here so we generate a
# user-friendly error message rather than a cryptic stack trace on module
# import.
if sys.version_info[0] != 2 or sys.version_info[1] < 7:
print('Python 2.7 or above (but not Python 3) is required to run mach.')
@@ -127,16 +137,17 @@ def bootstrap(test_package_root):
context.package_root = test_package_root
context.bin_dir = os.path.join(test_package_root, 'bin')
context.certs_dir = os.path.join(test_package_root, 'certs')
context.modules_dir = os.path.join(test_package_root, 'modules')
context.ancestors = ancestors
context.find_firefox = types.MethodType(find_firefox, context)
+ context.normalize_test_path = normalize_test_path
# Search for a mozharness localconfig.json
context.mozharness_config = None
for dir_path in ancestors(test_package_root):
mozharness_config = os.path.join(dir_path, 'logs', 'localconfig.json')
if os.path.isfile(mozharness_config):
context.mozharness_config = mozharness_config
break