Bug 1304176 - Set BaseScript.topsrcdir if we have a source checkout; r?ted draft
authorGregory Szorc <gps@mozilla.com>
Tue, 20 Sep 2016 11:28:52 -0700
changeset 417179 2cfc03bab8a6d0952e34da5dc605c8dd4d5e1b18
parent 416981 60cc643978c7020926fe4145761e26945fcd5c37
child 417180 721b4037a2bd1f1ed10fcc7954ed9e0ba13e7693
push id30356
push userbmo:gps@mozilla.com
push dateFri, 23 Sep 2016 19:11:51 +0000
reviewersted
bugs1304176
milestone52.0a1
Bug 1304176 - Set BaseScript.topsrcdir if we have a source checkout; r?ted We're going to start executing more mozharness scripts from a source checkout. Rather than add config options to specify the location of a source checkout - something that must be added to every mozharness invocation - we teach BaseScript.__init__ to recognize when we're running from a source checkout and set self.topsrcdir accordingly. This will allow any script or class to check for self.topsrcdir and change behavior accordingly. MozReview-Commit-ID: 3uxOjol7ntR
testing/mozharness/mozharness/base/script.py
--- a/testing/mozharness/mozharness/base/script.py
+++ b/testing/mozharness/mozharness/base/script.py
@@ -1780,16 +1780,31 @@ class BaseScript(ScriptMixin, LogMixin, 
         rw_config = ConfigClass(config_options=config_options, **kwargs)
         self.config = rw_config.get_read_only_config()
         self.actions = tuple(rw_config.actions)
         self.all_actions = tuple(rw_config.all_actions)
         self.env = None
         self.new_log_obj(default_log_level=default_log_level)
         self.script_obj = self
 
+        # Indicate we're a source checkout if VCS directory is present at the
+        # appropriate place. This code will break if this file is ever moved
+        # to another directory.
+        self.topsrcdir = None
+
+        srcreldir = 'testing/mozharness/mozharness/base'
+        here = os.path.normpath(os.path.dirname(__file__))
+        if here.replace('\\', '/').endswith(srcreldir):
+            topsrcdir = os.path.normpath(os.path.join(here, '..', '..',
+                                                      '..', '..'))
+            hg_dir = os.path.join(topsrcdir, '.hg')
+            git_dir = os.path.join(topsrcdir, '.git')
+            if os.path.isdir(hg_dir) or os.path.isdir(git_dir):
+                self.topsrcdir = topsrcdir
+
         # Set self.config to read-only.
         #
         # We can create intermediate config info programmatically from
         # this in a repeatable way, with logs; this is how we straddle the
         # ideal-but-not-user-friendly static config and the
         # easy-to-write-hard-to-debug writable config.
         #
         # To allow for other, script-specific configurations