Bug 1278890 - Add a method for normalizing test paths to the test package mach environment, r?armenzg draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 13 Jul 2016 10:49:42 -0400
changeset 387191 a85edf771af15a4429e4faf36be36ca6bd03d9f6
parent 387190 e5c7ced3edb959cae4a3413ace1ed2ab8eda9578
child 387192 70ce608bf14d7d8e829f1aa6c7f10b4d36fe55fc
push id22912
push userahalberstadt@mozilla.com
push dateWed, 13 Jul 2016 15:23:47 +0000
reviewersarmenzg
bugs1278890
milestone50.0a1
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
testing/tools/mach_test_package_bootstrap.py
--- 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