D5435: rust: better treatment of cargo/rustc errors

gracinet (Georges Racinet) phabricator at mercurial-scm.org
Sat Dec 15 22:30:41 EST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5955cf85ed74: rust: better treatment of cargo/rustc errors (authored by gracinet, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D5435?vs=12872&id=12884#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5435?vs=12872&id=12884

REVISION DETAIL
  https://phab.mercurial-scm.org/D5435

AFFECTED FILES
  setup.py

CHANGE DETAILS

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -135,6 +135,7 @@
 iswithrustextensions = 'HGWITHRUSTEXT' in os.environ
 
 import ctypes
+import errno
 import stat, subprocess, time
 import re
 import shutil
@@ -898,6 +899,9 @@
     'mercurial/thirdparty/xdiff/xutils.h',
 ]
 
+class RustCompilationError(CCompilerError):
+    """Exception class for Rust compilation errors."""
+
 class RustExtension(Extension):
     """A C Extension, conditionnally enhanced with Rust code.
 
@@ -942,9 +946,21 @@
             import pwd
             env['HOME'] = pwd.getpwuid(os.getuid()).pw_dir
 
-        subprocess.check_call(['cargo', 'build', '-vv', '--release'],
-                              env=env, cwd=self.rustsrcdir)
-        self.library_dirs.append(self.rusttargetdir)
+        cargocmd = ['cargo', 'build', '-vv', '--release']
+        try:
+            subprocess.check_call(cargocmd, env=env, cwd=self.rustsrcdir)
+        except OSError as exc:
+            if exc.errno == errno.ENOENT:
+                raise RustCompilationError("Cargo not found")
+            elif exc.errno == errno.EACCES:
+                raise RustCompilationError(
+                    "Cargo found, but permisssion to execute it is denied")
+            else:
+                raise
+        except subprocess.CalledProcessError:
+            raise RustCompilationError(
+                "Cargo failed. Working directory: %r, "
+                "command: %r, environment: %r" % (self.rustsrcdir, cmd, env))
 
 extmodules = [
     Extension('mercurial.cext.base85', ['mercurial/cext/base85.c'],



To: gracinet, #hg-reviewers
Cc: yuja, mercurial-devel


More information about the Mercurial-devel mailing list