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
--- 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