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,
stderr=subprocess.STDOUT)
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:
print(NO_MERCURIAL)
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.' %
version)