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 260292 a0b48af4bb54
parent 260291 49abfe1a8ef8
child 260293 56d740d0769f
push id741
push userryanvm@gmail.com
push date2015-04-27 20:01 +0000
treeherdermozilla-release@d10817faa571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersRyanVM, NPOTB
bugs1128586
milestone38.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
@@ -173,23 +173,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')
             for error in e.errors:
                 print(error.message)