@@ -49,7 +49,7 @@ def eprint(*args, **kwargs):
4949 print (* args , ** kwargs )
5050
5151
52- def get (base , url , path , checksums , verbose = False ):
52+ def get (base , url , path , checksums , verbose = 0 ):
5353 with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
5454 temp_path = temp_file .name
5555
@@ -66,11 +66,11 @@ def get(base, url, path, checksums, verbose=False):
6666 sha256 = checksums [url ]
6767 if os .path .exists (path ):
6868 if verify (path , sha256 , False ):
69- if verbose :
69+ if verbose > 0 :
7070 eprint ("using already-download file" , path )
7171 return
7272 else :
73- if verbose :
73+ if verbose > 0 :
7474 eprint (
7575 "ignoring already-download file" ,
7676 path ,
@@ -80,12 +80,12 @@ def get(base, url, path, checksums, verbose=False):
8080 download (temp_path , "{}/{}" .format (base , url ), True , verbose )
8181 if not verify (temp_path , sha256 , verbose ):
8282 raise RuntimeError ("failed verification" )
83- if verbose :
83+ if verbose > 0 :
8484 eprint ("moving {} to {}" .format (temp_path , path ))
8585 shutil .move (temp_path , path )
8686 finally :
8787 if os .path .isfile (temp_path ):
88- if verbose :
88+ if verbose > 0 :
8989 eprint ("removing" , temp_path )
9090 os .unlink (temp_path )
9191
@@ -113,11 +113,11 @@ def _download(path, url, probably_big, verbose, exception):
113113 # If an error occurs:
114114 # - If we are on win32 fallback to powershell
115115 # - Otherwise raise the error if appropriate
116- if probably_big or verbose :
116+ if probably_big or verbose > 0 :
117117 eprint ("downloading {}" .format (url ))
118118
119119 try :
120- if (probably_big or verbose ) and "GITHUB_ACTIONS" not in os .environ :
120+ if (probably_big or verbose > 0 ) and "GITHUB_ACTIONS" not in os .environ :
121121 option = "--progress-bar"
122122 else :
123123 option = "--silent"
@@ -180,7 +180,7 @@ def _download(path, url, probably_big, verbose, exception):
180180
181181def verify (path , expected , verbose ):
182182 """Check if the sha256 sum of the given path is valid"""
183- if verbose :
183+ if verbose > 0 :
184184 eprint ("verifying" , path )
185185 with open (path , "rb" ) as source :
186186 found = hashlib .sha256 (source .read ()).hexdigest ()
@@ -194,7 +194,7 @@ def verify(path, expected, verbose):
194194 return verified
195195
196196
197- def unpack (tarball , tarball_suffix , dst , verbose = False , match = None ):
197+ def unpack (tarball , tarball_suffix , dst , verbose = 0 , match = None ):
198198 """Unpack the given tarball file"""
199199 eprint ("extracting" , tarball )
200200 fname = os .path .basename (tarball ).replace (tarball_suffix , "" )
@@ -208,7 +208,7 @@ def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
208208 name = name [len (match ) + 1 :]
209209
210210 dst_path = os .path .join (dst , name )
211- if verbose :
211+ if verbose > 0 :
212212 eprint (" extracting" , member )
213213 tar .extract (member , dst )
214214 src_path = os .path .join (dst , member )
@@ -218,9 +218,9 @@ def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
218218 shutil .rmtree (os .path .join (dst , fname ))
219219
220220
221- def run (args , verbose = False , exception = False , is_bootstrap = False , ** kwargs ):
221+ def run (args , verbose = 0 , exception = False , is_bootstrap = False , ** kwargs ):
222222 """Run a child program in a new process"""
223- if verbose :
223+ if verbose > 0 :
224224 eprint ("running: " + " " .join (args ))
225225 sys .stdout .flush ()
226226 # Ensure that the .exe is used on Windows just in case a Linux ELF has been
@@ -233,7 +233,7 @@ def run(args, verbose=False, exception=False, is_bootstrap=False, **kwargs):
233233 code = ret .wait ()
234234 if code != 0 :
235235 err = "failed to run: " + " " .join (args )
236- if verbose or exception :
236+ if verbose > 0 or exception :
237237 raise RuntimeError (err )
238238 # For most failures, we definitely do want to print this error, or the user will have no
239239 # idea what went wrong. But when we've successfully built bootstrap and it failed, it will
@@ -293,13 +293,13 @@ def default_build_triple(verbose):
293293 version = version .decode (default_encoding )
294294 host = next (x for x in version .split ("\n " ) if x .startswith ("host: " ))
295295 triple = host .split ("host: " )[1 ]
296- if verbose :
296+ if verbose > 0 :
297297 eprint (
298298 "detected default triple {} from pre-installed rustc" .format (triple )
299299 )
300300 return triple
301301 except Exception as e :
302- if verbose :
302+ if verbose > 0 :
303303 eprint ("pre-installed rustc not detected: {}" .format (e ))
304304 eprint ("falling back to auto-detect" )
305305
@@ -699,7 +699,7 @@ def download_toolchain(self):
699699 # Unpack the tarballs in parallel.
700700 # In Python 2.7, Pool cannot be used as a context manager.
701701 pool_size = min (len (tarballs_download_info ), get_cpus ())
702- if self .verbose :
702+ if self .verbose > 0 :
703703 print (
704704 "Choosing a pool size of" ,
705705 pool_size ,
@@ -1126,6 +1126,8 @@ def build_bootstrap_cmd(self, env):
11261126 ]
11271127 # verbose cargo output is very noisy, so only enable it with -vv
11281128 args .extend ("--verbose" for _ in range (self .verbose - 1 ))
1129+ if self .verbose < 0 :
1130+ args .append ("--quiet" )
11291131
11301132 target_features = []
11311133 if self .get_toml ("crt-static" , build_section ) == "true" :
@@ -1275,7 +1277,12 @@ def parse_args(args):
12751277 parser .add_argument (
12761278 "--warnings" , choices = ["deny" , "warn" , "default" ], default = "default"
12771279 )
1278- parser .add_argument ("-v" , "--verbose" , action = "count" , default = 0 )
1280+ group = parser .add_mutually_exclusive_group ()
1281+ group .add_argument ("-v" , "--verbose" , action = "count" , default = 0 )
1282+ # Note that we're storing the `--quiet` value in `verbose`. That way we don't need to thread
1283+ # `self.quiet` throughout the code. That could be error prone, which could let some output
1284+ # through that should have been suppressed.
1285+ group .add_argument ("-q" , "--quiet" , action = "store_const" , const = - 1 , dest = "verbose" )
12791286
12801287 return parser .parse_known_args (args )[0 ]
12811288
0 commit comments