comparison setup.py @ 40966:1eaf62a67c1a

rust: better treatment of cargo/rustc errors Differential Revision: https://phab.mercurial-scm.org/D5435
author Georges Racinet <gracinet@anybox.fr>
date Thu, 06 Dec 2018 16:23:20 +0100
parents aa76be85029b
children 462a26756f70
comparison
equal deleted inserted replaced
40965:5532823e8c18 40966:1eaf62a67c1a
133 ispypy = "PyPy" in sys.version 133 ispypy = "PyPy" in sys.version
134 134
135 iswithrustextensions = 'HGWITHRUSTEXT' in os.environ 135 iswithrustextensions = 'HGWITHRUSTEXT' in os.environ
136 136
137 import ctypes 137 import ctypes
138 import errno
138 import stat, subprocess, time 139 import stat, subprocess, time
139 import re 140 import re
140 import shutil 141 import shutil
141 import tempfile 142 import tempfile
142 from distutils import log 143 from distutils import log
896 'mercurial/thirdparty/xdiff/xprepare.h', 897 'mercurial/thirdparty/xdiff/xprepare.h',
897 'mercurial/thirdparty/xdiff/xtypes.h', 898 'mercurial/thirdparty/xdiff/xtypes.h',
898 'mercurial/thirdparty/xdiff/xutils.h', 899 'mercurial/thirdparty/xdiff/xutils.h',
899 ] 900 ]
900 901
902 class RustCompilationError(CCompilerError):
903 """Exception class for Rust compilation errors."""
904
901 class RustExtension(Extension): 905 class RustExtension(Extension):
902 """A C Extension, conditionnally enhanced with Rust code. 906 """A C Extension, conditionnally enhanced with Rust code.
903 907
904 if iswithrustextensions is False, does nothing else than plain Extension 908 if iswithrustextensions is False, does nothing else than plain Extension
905 """ 909 """
940 # Unix only fix (os.path.expanduser not really reliable if 944 # Unix only fix (os.path.expanduser not really reliable if
941 # HOME is shadowed like this) 945 # HOME is shadowed like this)
942 import pwd 946 import pwd
943 env['HOME'] = pwd.getpwuid(os.getuid()).pw_dir 947 env['HOME'] = pwd.getpwuid(os.getuid()).pw_dir
944 948
945 subprocess.check_call(['cargo', 'build', '-vv', '--release'], 949 cargocmd = ['cargo', 'build', '-vv', '--release']
946 env=env, cwd=self.rustsrcdir) 950 try:
947 self.library_dirs.append(self.rusttargetdir) 951 subprocess.check_call(cargocmd, env=env, cwd=self.rustsrcdir)
952 except OSError as exc:
953 if exc.errno == errno.ENOENT:
954 raise RustCompilationError("Cargo not found")
955 elif exc.errno == errno.EACCES:
956 raise RustCompilationError(
957 "Cargo found, but permisssion to execute it is denied")
958 else:
959 raise
960 except subprocess.CalledProcessError:
961 raise RustCompilationError(
962 "Cargo failed. Working directory: %r, "
963 "command: %r, environment: %r" % (self.rustsrcdir, cmd, env))
948 964
949 extmodules = [ 965 extmodules = [
950 Extension('mercurial.cext.base85', ['mercurial/cext/base85.c'], 966 Extension('mercurial.cext.base85', ['mercurial/cext/base85.c'],
951 include_dirs=common_include_dirs, 967 include_dirs=common_include_dirs,
952 depends=common_depends), 968 depends=common_depends),