changeset 50771:5dc7e1907e48 stable

setup: make the error "Unable to find a working hg binary" more informative The error message now shows the attempted hg commands and their stderr, to make it easier to investigate why things are not working. Here's an example output /!\ /!\ Unable to find a working hg binary /!\ Version cannot be extracted from the repository /!\ Re-run the setup once a first version is built /!\ Attempts: /!\ attempt #0: /!\ cmd: ['hg-missing', 'log', '-r.', '-Ttest'] /!\ exception: [Errno 2] No such file or directory: 'hg-missing': 'hg-missing' /!\ attempt #1: /!\ cmd: ['/usr/bin/python3', 'hg', 'log', '-r.', '-Ttest'] /!\ return code: 255 /!\ std output: /!\ std error: *** failed to import extension "topic": No module named 'topic' *** failed to import extension "evolve": No module named 'evolve' abort: accessing `dirstate-v2` repository without associated fast implementation. (check `hg help config.format.use-dirstate-v2` for details) /!\ /!\ Could not determine the Mercurial version /!\ You need to build a local version first /!\ Run `make local` and try again /!\
author Arseniy Alekseyev <aalekseyev@janestreet.com>
date Mon, 04 Sep 2023 13:33:32 +0100
parents 0a4efb650b3e
children a4ec7a92d2c5
files setup.py
diffstat 1 files changed, 26 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Mon Aug 21 10:21:58 2023 -0400
+++ b/setup.py	Mon Sep 04 13:33:32 2023 +0100
@@ -278,28 +278,44 @@
     # gives precedence to hg.exe in the current directory, so fall back to the
     # python invocation of local hg, where pythonXY.dll can always be found.
     check_cmd = ['log', '-r.', '-Ttest']
-    if os.name != 'nt' or not os.path.exists("hg.exe"):
+    attempts = []
+
+    def attempt(cmd, env):
         try:
             retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
-        except EnvironmentError:
-            retcode = -1
-        if retcode == 0 and not filterhgerr(err):
+            res = (True, retcode, out, err)
+            if retcode == 0 and not filterhgerr(err):
+                return True
+        except EnvironmentError as e:
+            res = (False, e)
+        attempts.append((cmd, res))
+        return False
+
+    if os.name != 'nt' or not os.path.exists("hg.exe"):
+        if attempt(hgcmd + check_cmd, hgenv):
             return hgcommand(hgcmd, hgenv)
 
     # Fall back to trying the local hg installation.
     hgenv = localhgenv()
     hgcmd = [sys.executable, 'hg']
-    try:
-        retcode, out, err = runcmd(hgcmd + check_cmd, hgenv)
-    except EnvironmentError:
-        retcode = -1
-    if retcode == 0 and not filterhgerr(err):
+    if attempt(hgcmd + check_cmd, hgenv):
         return hgcommand(hgcmd, hgenv)
 
     eprint("/!\\")
     eprint(r"/!\ Unable to find a working hg binary")
-    eprint(r"/!\ Version cannot be extract from the repository")
+    eprint(r"/!\ Version cannot be extracted from the repository")
     eprint(r"/!\ Re-run the setup once a first version is built")
+    eprint(r"/!\ Attempts:")
+    for i, e in enumerate(attempts):
+        eprint(r"/!\   attempt #%d:" % (i))
+        eprint(r"/!\     cmd:        ", e[0])
+        res = e[1]
+        if res[0]:
+            eprint(r"/!\     return code:", res[1])
+            eprint("/!\\     std output:\n%s" % (res[2].decode()), end="")
+            eprint("/!\\     std error:\n%s" % (res[3].decode()), end="")
+        else:
+            eprint(r"/!\     exception:  ", res[1])
     return None