Bug 1415618: Allow specifying extra paths to search for config files mozharness. r=jlund
☠☠ backed out by b89090531f6a ☠ ☠
authorTom Prince <mozilla@hocat.ca>
Tue, 14 Nov 2017 15:15:56 -0700
changeset 392092 780f67a36d6d91d4ee35070dc7f8d8c598106929
parent 392091 5ecdc55db739801216435854ce412694a8e0dca7
child 392093 71510fd07ef52f8539ed37968e2ec7ea9c1a5fdd
push id32910
push userrgurzau@mozilla.com
push dateThu, 16 Nov 2017 10:02:59 +0000
treeherdermozilla-central@9941e68b5a53 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlund
bugs1415618
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1415618: Allow specifying extra paths to search for config files mozharness. r=jlund MozReview-Commit-ID: 3xkUaDwYB6v
testing/mozharness/mozharness/base/config.py
testing/mozharness/mozharness/mozilla/building/buildbase.py
--- a/testing/mozharness/mozharness/base/config.py
+++ b/testing/mozharness/mozharness/base/config.py
@@ -276,16 +276,20 @@ class BaseConfig(object):
             help="Specify the work_dir (subdir of base_work_dir)"
         )
         self.config_parser.add_option(
             "--base-work-dir", action="store", dest="base_work_dir",
             type="string", default=os.getcwd(),
             help="Specify the absolute path of the parent of the working directory"
         )
         self.config_parser.add_option(
+            "--extra-config-path", action='extend', dest="config_paths",
+            type="string", help="Specify additional paths to search for config files.",
+        )
+        self.config_parser.add_option(
             "-c", "--config-file", "--cfg", action="extend", dest="config_files",
             type="string", help="Specify a config file; can be repeated"
         )
         self.config_parser.add_option(
             "-C", "--opt-config-file", "--opt-cfg", action="extend",
             dest="opt_config_files", type="string", default=[],
             help="Specify an optional config file, like --config-file but with no "
                  "error if the file is missing; can be repeated"
@@ -428,28 +432,31 @@ class BaseConfig(object):
         This function is also responsible for downloading any configuration
         files specified by URL.  It uses ``parse_config_file`` in this module
         to parse individual files.
 
         This method can be overridden in a subclass to add extra logic to the
         way that self.config is made up.  See
         `mozharness.mozilla.building.buildbase.BuildingConfig` for an example.
         """
+        config_paths = options.config_paths or ['.']
         all_cfg_files_and_dicts = []
         for cf in all_config_files:
             try:
                 if '://' in cf:  # config file is an url
                     file_name = os.path.basename(cf)
                     file_path = os.path.join(os.getcwd(), file_name)
                     download_config_file(cf, file_path)
                     all_cfg_files_and_dicts.append(
                         (file_path, parse_config_file(file_path, search_path=["."]))
                     )
                 else:
-                    all_cfg_files_and_dicts.append((cf, parse_config_file(cf)))
+                    all_cfg_files_and_dicts.append(
+                        (cf, parse_config_file(cf, search_path=config_paths + [DEFAULT_CONFIG_PATH]))
+                    )
             except Exception:
                 if cf in options.opt_config_files:
                     print(
                         "WARNING: optional config file not found %s" % cf
                     )
                 else:
                     raise
         return all_cfg_files_and_dicts
--- a/testing/mozharness/mozharness/mozilla/building/buildbase.py
+++ b/testing/mozharness/mozharness/mozilla/building/buildbase.py
@@ -394,19 +394,16 @@ class BuildingConfig(BaseConfig):
         return all_config_dicts
 
 
 # noinspection PyUnusedLocal
 class BuildOptionParser(object):
     # TODO add nosetests for this class
     platform = None
     bits = None
-    config_file_search_path = [
-        DEFAULT_CONFIG_PATH,
-    ]
 
     # add to this list and you can automagically do things like
     # --custom-build-variant-cfg asan
     # and the script will pull up the appropriate path for the config
     # against the current platform and bits.
     # *It will warn and fail if there is not a config for the current
     # platform/bits
     build_variants = {
@@ -516,19 +513,24 @@ class BuildOptionParser(object):
             # this is either an incomplete path or an invalid key in
             # build_variants
             prospective_cfg_path = value
 
         if os.path.exists(prospective_cfg_path):
             # now let's see if we were given a valid pathname
             valid_variant_cfg_path = value
         else:
+            # FIXME: We should actually wait until we have parsed all arguments
+            # before looking at this, otherwise the behavior will depend on the
+            # order of arguments. But that isn't a problem as long as --extra-config-path
+            # is always passed first.
+            config_paths = parser.values.config_paths + [DEFAULT_CONFIG_PATH]
             # let's take our prospective_cfg_path and see if we can
             # determine an existing file
-            for path in cls.config_file_search_path:
+            for path in config_paths:
                 if os.path.exists(os.path.join(path, prospective_cfg_path)):
                     # success! we found a config file
                     valid_variant_cfg_path = os.path.join(path,
                                                           prospective_cfg_path)
                     break
         return valid_variant_cfg_path, prospective_cfg_path
 
     @classmethod