@@ -79,6 +79,7 @@ def _download(path, url, probably_big, verbose, exception):
79
79
option = "-#"
80
80
else :
81
81
option = "-s"
82
+ require (["curl" , "--version" ])
82
83
run (["curl" , option ,
83
84
"-y" , "30" , "-Y" , "10" , # timeout if speed is < 10 bytes/sec for > 30 seconds
84
85
"--connect-timeout" , "30" , # timeout if cannot connect within 30 seconds
@@ -143,6 +144,21 @@ def run(args, verbose=False, exception=False, **kwargs):
143
144
sys .exit (err )
144
145
145
146
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
+
146
162
def stage0_data (rust_root ):
147
163
"""Build a dictionary from stage0.txt"""
148
164
nightlies = os .path .join (rust_root , "src/stage0.txt" )
@@ -164,16 +180,12 @@ def format_build_time(duration):
164
180
def default_build_triple ():
165
181
"""Build triple as in LLVM"""
166
182
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'
177
189
178
190
# The goal here is to come up with the same triple as LLVM would,
179
191
# at least for the subset of platforms we're willing to target.
@@ -203,12 +215,7 @@ def default_build_triple():
203
215
# output from that option is too generic for our purposes (it will
204
216
# always emit 'i386' on x86/amd64 systems). As such, isainfo -k
205
217
# 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 )
212
219
elif ostype .startswith ('MINGW' ):
213
220
# msys' `uname` does not print gcc configuration, but prints msys
214
221
# configuration. so we cannot believe `uname -m`:
@@ -766,13 +773,8 @@ def update_submodules(self):
766
773
default_encoding = sys .getdefaultencoding ()
767
774
768
775
# 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 )
776
778
777
779
slow_submodules = self .get_toml ('fast-submodules' ) == "false"
778
780
start_time = time ()
0 commit comments