Bug 1128586 - Prefer hg.exe over hg. r=RyanVM, a=NPOTB
This is needed for compatibility with an upcoming release of
MozillaBuild, which distributes Mercurial as a Python package, not as a
standalone Windows program. As a result, it introduces "hg" into $PATH,
which "which" will happily prefer as the "hg" binary. This upsets
subprocess. So, we explicitly prefer "hg.exe" over "hg".
We could accomplish the same thing by calling which.whichall() and
sorting results. But this is more code and IMO not worth the effort to
implement.
--- a/tools/mercurial/hgsetup/wizard.py
+++ b/tools/mercurial/hgsetup/wizard.py
@@ -101,23 +101,31 @@ class MercurialSetupWizard(object):
def run(self, config_paths):
try:
os.makedirs(self.ext_dir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
+ # We use subprocess in places, which expects a Win32 executable or
+ # batch script. On some versions of MozillaBuild, we have "hg.exe",
+ # "hg.bat," and "hg" (a Python script). "which" will happily return the
+ # Python script, which will cause subprocess to choke. Explicitly favor
+ # the Windows version over the plain script.
try:
- hg = which.which('hg')
- except which.WhichError as e:
- print(e)
- print('Try running |mach bootstrap| to ensure your environment is '
- 'up to date.')
- return 1
+ hg = which.which('hg.exe')
+ except which.WhichError:
+ try:
+ hg = which.which('hg')
+ except which.WhichError as e:
+ print(e)
+ print('Try running |mach bootstrap| to ensure your environment is '
+ 'up to date.')
+ return 1
try:
c = MercurialConfig(config_paths)
except ConfigObjError as e:
print('Error importing existing Mercurial config!\n'
'%s\n'
'If using quotes, they must wrap the entire string.' % e)
return 1