Skip to content

Commit 16d970a

Browse files
authored
Rollup merge of rust-lang#71819 - jyn514:check-for-tools, r=Mark-Simulacrum
x.py: Give a more helpful error message if curl isn't installed 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: ``` Updating only changed submodules Submodules updated in 0.01 seconds spurious failure, trying again spurious failure, trying again spurious failure, trying again spurious failure, trying again failed to run: curl -s -y 30 -Y 10 --connect-timeout 30 --retry 3 -Sf -o /tmp/tmpSWF21P.sha256 https://static.rust-lang.org/dist/2020-04-22/rust-std-beta-x86_64-unknown-linux-gnu.tar.gz.sha256: [Errno 2] No such file or directory Build completed unsuccessfully in 0:00:00 ```
2 parents f4e080f + 9bcf409 commit 16d970a

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/bootstrap/bootstrap.py

+25-23
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def _download(path, url, probably_big, verbose, exception):
7979
option = "-#"
8080
else:
8181
option = "-s"
82+
require(["curl", "--version"])
8283
run(["curl", option,
8384
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
8485
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
@@ -143,6 +144,21 @@ def run(args, verbose=False, exception=False, **kwargs):
143144
sys.exit(err)
144145

145146

147+
def require(cmd, exit=True):
148+
'''Run a command, returning its output.
149+
On error,
150+
If `exit` is `True`, exit the process.
151+
Otherwise, return None.'''
152+
try:
153+
return subprocess.check_output(cmd).strip()
154+
except (subprocess.CalledProcessError, OSError) as exc:
155+
if not exit:
156+
return None
157+
print("error: unable to run `{}`: {}".format(' '.join(cmd), exc))
158+
print("Please make sure it's installed and in the path.")
159+
sys.exit(1)
160+
161+
146162
def stage0_data(rust_root):
147163
"""Build a dictionary from stage0.txt"""
148164
nightlies = os.path.join(rust_root, "src/stage0.txt")
@@ -164,16 +180,12 @@ def format_build_time(duration):
164180
def default_build_triple():
165181
"""Build triple as in LLVM"""
166182
default_encoding = sys.getdefaultencoding()
167-
try:
168-
ostype = subprocess.check_output(
169-
['uname', '-s']).strip().decode(default_encoding)
170-
cputype = subprocess.check_output(
171-
['uname', '-m']).strip().decode(default_encoding)
172-
except (subprocess.CalledProcessError, OSError):
173-
if sys.platform == 'win32':
174-
return 'x86_64-pc-windows-msvc'
175-
err = "uname not found"
176-
sys.exit(err)
183+
required = not sys.platform == 'win32'
184+
ostype = require(["uname", "-s"], exit=required).decode(default_encoding)
185+
cputype = require(['uname', '-m'], exit=required).decode(default_encoding)
186+
187+
if ostype is None or cputype is None:
188+
return 'x86_64-pc-windows-msvc'
177189

178190
# The goal here is to come up with the same triple as LLVM would,
179191
# at least for the subset of platforms we're willing to target.
@@ -203,12 +215,7 @@ def default_build_triple():
203215
# output from that option is too generic for our purposes (it will
204216
# always emit 'i386' on x86/amd64 systems). As such, isainfo -k
205217
# must be used instead.
206-
try:
207-
cputype = subprocess.check_output(
208-
['isainfo', '-k']).strip().decode(default_encoding)
209-
except (subprocess.CalledProcessError, OSError):
210-
err = "isainfo not found"
211-
sys.exit(err)
218+
cputype = require(['isainfo', '-k']).decode(default_encoding)
212219
elif ostype.startswith('MINGW'):
213220
# msys' `uname` does not print gcc configuration, but prints msys
214221
# configuration. so we cannot believe `uname -m`:
@@ -766,13 +773,8 @@ def update_submodules(self):
766773
default_encoding = sys.getdefaultencoding()
767774

768775
# check the existence and version of 'git' command
769-
try:
770-
git_version_output = subprocess.check_output(['git', '--version'])
771-
git_version_str = git_version_output.strip().split()[2].decode(default_encoding)
772-
self.git_version = distutils.version.LooseVersion(git_version_str)
773-
except (subprocess.CalledProcessError, OSError):
774-
print("error: `git` is not found, please make sure it's installed and in the path.")
775-
sys.exit(1)
776+
git_version_str = require(['git', '--version']).split()[2].decode(default_encoding)
777+
self.git_version = distutils.version.LooseVersion(git_version_str)
776778

777779
slow_submodules = self.get_toml('fast-submodules') == "false"
778780
start_time = time()

0 commit comments

Comments
 (0)