D5435: rust: better treatment of cargo/rustc errors

gracinet (Georges Racinet) phabricator at mercurial-scm.org
Sat Dec 15 11:41:56 UTC 2018


gracinet created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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
@@ -898,6 +898,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 +945,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 == os.errno.ENOENT:
+                raise RustCompilationError("Cargo not found")
+            elif exc.errno == os.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: mercurial-devel


More information about the Mercurial-devel mailing list