Patchwork D5435: rust: better treatment of cargo/rustc errors

login
register
mail settings
Submitter phabricator
Date Dec. 16, 2018, 3:30 a.m.
Message ID <faa87fb32e1f9e684f23e3f26e1cfc42@localhost.localdomain>
Download mbox | patch
Permalink /patch/37194/
State Not Applicable
Headers show

Comments

phabricator - Dec. 16, 2018, 3:30 a.m.
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




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

Patch

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'],