Bug 1286799 - mozboot: Use a helper for mercurial version detection. r=gps draft
authorRalph Giles <giles@mozilla.com>
Tue, 15 Nov 2016 17:18:21 -0800
changeset 442121 006d347050789dd4fdd370a1267d17067365cd66
parent 442120 5172cf24453d0e43824d38c55f083eab49384679
child 442122 7e3b93919bbd859d6c6ca63aaf659c8f1f4844ba
push id36589
push userbmo:giles@thaumas.net
push dateMon, 21 Nov 2016 19:39:40 +0000
Bug 1286799 - mozboot: Use a helper for mercurial version detection. r=gps Also use the abstracted helper method for reading the current mercurial version too. This changes the regex from what was in use before, but should work for normal version numbers. MozReview-Commit-ID: IZfC65Jg6T8
--- a/python/mozboot/mozboot/base.py
+++ b/python/mozboot/mozboot/base.py
@@ -316,31 +316,36 @@ class BaseBootstrapper(object):
         self.package_manager_updated = True
     def _update_package_manager(self):
         """Updates the package manager's manifests/package list.
         This should be defined in child classes.
-    def _parse_version(self, path, name=None):
+    def _parse_version(self, path, name=None, env=None):
         '''Execute the given path, returning the version.
         Invokes the path argument with the --version switch
         and returns a LooseVersion representing the output
         if successful. If not, returns None.
         An optional name argument gives the expected program
         name returned as part of the version string, if it's
         different from the basename of the executable.
+        An optional env argument allows modifying environment
+        variable during the invocation to set options, PATH,
+        etc.
         if not name:
             name = os.path.basename(path)
         info = self.check_output([path, '--version'],
+                                 env=env,
         match = re.search(name + ' ([a-z0-9\.]+)', info)
         if not match:
             print('ERROR! Unable to identify %s version.' % name)
             return None
         return LooseVersion(match.group(1))
@@ -357,25 +362,20 @@ class BaseBootstrapper(object):
         return env
     def is_mercurial_modern(self):
         hg = self.which('hg')
         if not hg:
             return False, False, None
-        info = self.check_output([hg, '--version'], env=self._hgplain_env()).splitlines()[0]
-        match = re.search('version ([^\+\)]+)', info)
-        if not match:
-            print('ERROR: Unable to identify Mercurial version.')
+        our = self._parse_version(hg, 'version', self._hgplain_env())
+        if not our:
             return True, False, None
-        our = LooseVersion(match.group(1))
         return True, our >= MODERN_MERCURIAL_VERSION, our
     def ensure_mercurial_modern(self):
         installed, modern, version = self.is_mercurial_modern()
         if modern:
             print('Your version of Mercurial (%s) is sufficiently modern.' %