Bug 1415618: Allow specifying extra paths to search for config files mozharness. r=jlund draft
authorTom Prince <mozilla@hocat.ca>
Tue, 14 Nov 2017 15:15:56 -0700
changeset 698843 e80f0f20213e76ee68e62757eab8c788b7d398c6
parent 698842 77fb6c02d5e3f4e7011f0bef5ee22708145d3702
child 698844 2a184e66c3413e9e206b999b1340a6ecb52bd234
push id89369
push userbmo:mozilla@hocat.ca
push dateThu, 16 Nov 2017 04:26:10 +0000
Bug 1415618: Allow specifying extra paths to search for config files mozharness. r=jlund MozReview-Commit-ID: 3xkUaDwYB6v
--- 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)"
             "--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"
+            "--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"
             "-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:
                 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)
                         (file_path, parse_config_file(file_path, search_path=["."]))
-                    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:
                         "WARNING: optional config file not found %s" % cf
         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 = [
-    ]
     # 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,25 @@ 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
+            # 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.
+            extra_config_paths = parser.values.config_paths or []
+            config_paths = extra_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,
         return valid_variant_cfg_path, prospective_cfg_path