Bug 1128586 - Prefer hg.exe over hg. r=RyanVM, a=NPOTB
authorGregory Szorc <gps@mozilla.com>
Mon, 27 Apr 2015 10:43:49 -0700
changeset 201171 8ab58180c92f52a2ded2a09afd594cf65f0b89ea
parent 201170 2f3e78643f5cc49e367917cebd71ea90f7b54378
child 201172 068fedc4a117b332f09827bb0c148006a615467c
push id261
push userryanvm@gmail.com
push dateTue, 28 Apr 2015 01:04:57 +0000
treeherdermozilla-esr31@068fedc4a117 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersRyanVM, NPOTB
bugs1128586
milestone31.6.0
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.
tools/mercurial/hgsetup/wizard.py
--- 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