x.py: Give a more helpful error message if curl isn't installed
This also abstracts checking for a command into `require`. Before: ``` Updating only changed submodules Submodules updated in 0.01 seconds Traceback (most recent call last): File "./x.py", line 11, in <module> bootstrap.main() ... File "/home/joshua/src/rust/src/bootstrap/bootstrap.py", line 137, in run ret = subprocess.Popen(args, **kwargs) File "/usr/lib/python2.7/subprocess.py", line 394, in __init__ errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory ``` After: ``` error: unable to run `curl --version`: [Errno 2] No such file or directory Please make sure it's installed and in the path. ```
This commit is contained in:
parent
f05a524044
commit
9bcf4097e3
1 changed files with 25 additions and 23 deletions
|
@ -79,6 +79,7 @@ def _download(path, url, probably_big, verbose, exception):
|
||||||
option = "-#"
|
option = "-#"
|
||||||
else:
|
else:
|
||||||
option = "-s"
|
option = "-s"
|
||||||
|
require(["curl", "--version"])
|
||||||
run(["curl", option,
|
run(["curl", option,
|
||||||
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
|
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
|
||||||
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
|
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
|
||||||
|
@ -143,6 +144,21 @@ def run(args, verbose=False, exception=False, **kwargs):
|
||||||
sys.exit(err)
|
sys.exit(err)
|
||||||
|
|
||||||
|
|
||||||
|
def require(cmd, exit=True):
|
||||||
|
'''Run a command, returning its output.
|
||||||
|
On error,
|
||||||
|
If `exit` is `True`, exit the process.
|
||||||
|
Otherwise, return None.'''
|
||||||
|
try:
|
||||||
|
return subprocess.check_output(cmd).strip()
|
||||||
|
except (subprocess.CalledProcessError, OSError) as exc:
|
||||||
|
if not exit:
|
||||||
|
return None
|
||||||
|
print("error: unable to run `{}`: {}".format(' '.join(cmd), exc))
|
||||||
|
print("Please make sure it's installed and in the path.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def stage0_data(rust_root):
|
def stage0_data(rust_root):
|
||||||
"""Build a dictionary from stage0.txt"""
|
"""Build a dictionary from stage0.txt"""
|
||||||
nightlies = os.path.join(rust_root, "src/stage0.txt")
|
nightlies = os.path.join(rust_root, "src/stage0.txt")
|
||||||
|
@ -164,16 +180,12 @@ def format_build_time(duration):
|
||||||
def default_build_triple():
|
def default_build_triple():
|
||||||
"""Build triple as in LLVM"""
|
"""Build triple as in LLVM"""
|
||||||
default_encoding = sys.getdefaultencoding()
|
default_encoding = sys.getdefaultencoding()
|
||||||
try:
|
required = not sys.platform == 'win32'
|
||||||
ostype = subprocess.check_output(
|
ostype = require(["uname", "-s"], exit=required).decode(default_encoding)
|
||||||
['uname', '-s']).strip().decode(default_encoding)
|
cputype = require(['uname', '-m'], exit=required).decode(default_encoding)
|
||||||
cputype = subprocess.check_output(
|
|
||||||
['uname', '-m']).strip().decode(default_encoding)
|
if ostype is None or cputype is None:
|
||||||
except (subprocess.CalledProcessError, OSError):
|
return 'x86_64-pc-windows-msvc'
|
||||||
if sys.platform == 'win32':
|
|
||||||
return 'x86_64-pc-windows-msvc'
|
|
||||||
err = "uname not found"
|
|
||||||
sys.exit(err)
|
|
||||||
|
|
||||||
# The goal here is to come up with the same triple as LLVM would,
|
# The goal here is to come up with the same triple as LLVM would,
|
||||||
# at least for the subset of platforms we're willing to target.
|
# at least for the subset of platforms we're willing to target.
|
||||||
|
@ -203,12 +215,7 @@ def default_build_triple():
|
||||||
# output from that option is too generic for our purposes (it will
|
# output from that option is too generic for our purposes (it will
|
||||||
# always emit 'i386' on x86/amd64 systems). As such, isainfo -k
|
# always emit 'i386' on x86/amd64 systems). As such, isainfo -k
|
||||||
# must be used instead.
|
# must be used instead.
|
||||||
try:
|
cputype = require(['isainfo', '-k']).decode(default_encoding)
|
||||||
cputype = subprocess.check_output(
|
|
||||||
['isainfo', '-k']).strip().decode(default_encoding)
|
|
||||||
except (subprocess.CalledProcessError, OSError):
|
|
||||||
err = "isainfo not found"
|
|
||||||
sys.exit(err)
|
|
||||||
elif ostype.startswith('MINGW'):
|
elif ostype.startswith('MINGW'):
|
||||||
# msys' `uname` does not print gcc configuration, but prints msys
|
# msys' `uname` does not print gcc configuration, but prints msys
|
||||||
# configuration. so we cannot believe `uname -m`:
|
# configuration. so we cannot believe `uname -m`:
|
||||||
|
@ -766,13 +773,8 @@ class RustBuild(object):
|
||||||
default_encoding = sys.getdefaultencoding()
|
default_encoding = sys.getdefaultencoding()
|
||||||
|
|
||||||
# check the existence and version of 'git' command
|
# check the existence and version of 'git' command
|
||||||
try:
|
git_version_str = require(['git', '--version']).split()[2].decode(default_encoding)
|
||||||
git_version_output = subprocess.check_output(['git', '--version'])
|
self.git_version = distutils.version.LooseVersion(git_version_str)
|
||||||
git_version_str = git_version_output.strip().split()[2].decode(default_encoding)
|
|
||||||
self.git_version = distutils.version.LooseVersion(git_version_str)
|
|
||||||
except (subprocess.CalledProcessError, OSError):
|
|
||||||
print("error: `git` is not found, please make sure it's installed and in the path.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
slow_submodules = self.get_toml('fast-submodules') == "false"
|
slow_submodules = self.get_toml('fast-submodules') == "false"
|
||||||
start_time = time()
|
start_time = time()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue