Bug 1278890 - Add a method for normalizing test paths to the test package mach environment, r=armenzg
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Wed, 13 Jul 2016 10:49:42 -0400
changeset 330021 45d6a990dd2877b9c8f265f13fc565a96f6667bf
parent 330020 06ca3f2b883b2eaeea2e37841dba283d0acfa0f2
child 330022 3e6f9e3a99a1419bed34c396c0e30eb67f870a1e
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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