@@ -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+
146162def 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):
164180def 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