@@ -402,9 +402,10 @@ def __init__(self):
402
402
self .rust_root = ''
403
403
self .use_locked_deps = False
404
404
self .use_vendored_sources = False
405
- self .verbose = 0
405
+ self .verbose = False
406
406
self .git_version = None
407
407
self .nix_deps_dir = None
408
+ self ._should_fix_bins_and_dylibs = None
408
409
409
410
def download_toolchain (self ):
410
411
"""Fetch the build system for Rust, written in Rust
@@ -466,46 +467,54 @@ def _download_component_helper(
466
467
"dist/{}/{}" .format (key , filename ),
467
468
tarball ,
468
469
self .checksums_sha256 ,
469
- verbose = self .verbose != 0 ,
470
+ verbose = self .verbose ,
470
471
)
471
- unpack (tarball , tarball_suffix , self .bin_root (), match = pattern , verbose = self .verbose != 0 )
472
+ unpack (tarball , tarball_suffix , self .bin_root (), match = pattern , verbose = self .verbose )
472
473
473
474
def should_fix_bins_and_dylibs (self ):
474
475
"""Whether or not `fix_bin_or_dylib` needs to be run; can only be True
475
476
on NixOS.
476
477
"""
477
- default_encoding = sys .getdefaultencoding ()
478
- try :
479
- ostype = subprocess .check_output (
480
- ['uname' , '-s' ]).strip ().decode (default_encoding )
481
- except subprocess .CalledProcessError :
482
- return False
483
- except OSError as reason :
484
- if getattr (reason , 'winerror' , None ) is not None :
478
+ if self ._should_fix_bins_and_dylibs is not None :
479
+ return self ._should_fix_bins_and_dylibs
480
+
481
+ def get_answer ():
482
+ default_encoding = sys .getdefaultencoding ()
483
+ try :
484
+ ostype = subprocess .check_output (
485
+ ['uname' , '-s' ]).strip ().decode (default_encoding )
486
+ except subprocess .CalledProcessError :
485
487
return False
486
- raise reason
488
+ except OSError as reason :
489
+ if getattr (reason , 'winerror' , None ) is not None :
490
+ return False
491
+ raise reason
487
492
488
- if ostype != "Linux" :
489
- return False
493
+ if ostype != "Linux" :
494
+ return False
490
495
491
- # If the user has asked binaries to be patched for Nix, then
492
- # don't check for NixOS or `/lib`.
493
- if self .get_toml ("patch-binaries-for-nix" , "build" ) == "true" :
494
- return True
496
+ # If the user has asked binaries to be patched for Nix, then
497
+ # don't check for NixOS or `/lib`.
498
+ if self .get_toml ("patch-binaries-for-nix" , "build" ) == "true" :
499
+ return True
495
500
496
- # Use `/etc/os-release` instead of `/etc/NIXOS`.
497
- # The latter one does not exist on NixOS when using tmpfs as root.
498
- try :
499
- with open ("/etc/os-release" , "r" ) as f :
500
- if not any (l .strip () in ("ID=nixos" , "ID='nixos'" , 'ID="nixos"' ) for l in f ):
501
- return False
502
- except FileNotFoundError :
503
- return False
504
- if os .path .exists ("/lib" ):
505
- return False
501
+ # Use `/etc/os-release` instead of `/etc/NIXOS`.
502
+ # The latter one does not exist on NixOS when using tmpfs as root.
503
+ try :
504
+ with open ("/etc/os-release" , "r" ) as f :
505
+ if not any (l .strip () in ("ID=nixos" , "ID='nixos'" , 'ID="nixos"' ) for l in f ):
506
+ return False
507
+ except FileNotFoundError :
508
+ return False
509
+ if os .path .exists ("/lib" ):
510
+ return False
511
+
512
+ return True
506
513
507
- print ("info: You seem to be using Nix." )
508
- return True
514
+ answer = self ._should_fix_bins_and_dylibs = get_answer ()
515
+ if answer :
516
+ print ("info: You seem to be using Nix." )
517
+ return answer
509
518
510
519
def fix_bin_or_dylib (self , fname ):
511
520
"""Modifies the interpreter section of 'fname' to fix the dynamic linker,
@@ -516,6 +525,7 @@ def fix_bin_or_dylib(self, fname):
516
525
517
526
Please see https://nixos.org/patchelf.html for more information
518
527
"""
528
+ assert self ._should_fix_bins_and_dylibs is True
519
529
print ("attempting to patch" , fname )
520
530
521
531
# Only build `.nix-deps` once.
@@ -707,7 +717,7 @@ def bootstrap_binary(self):
707
717
"""
708
718
return os .path .join (self .build_dir , "bootstrap" , "debug" , "bootstrap" )
709
719
710
- def build_bootstrap (self , color ):
720
+ def build_bootstrap (self , color , verbose_count ):
711
721
"""Build bootstrap"""
712
722
print ("Building bootstrap" )
713
723
build_dir = os .path .join (self .build_dir , "bootstrap" )
@@ -764,7 +774,7 @@ def build_bootstrap(self, color):
764
774
self .cargo ()))
765
775
args = [self .cargo (), "build" , "--manifest-path" ,
766
776
os .path .join (self .rust_root , "src/bootstrap/Cargo.toml" )]
767
- args .extend ("--verbose" for _ in range (self . verbose ))
777
+ args .extend ("--verbose" for _ in range (verbose_count ))
768
778
if self .use_locked_deps :
769
779
args .append ("--locked" )
770
780
if self .use_vendored_sources :
@@ -778,7 +788,7 @@ def build_bootstrap(self, color):
778
788
args .append ("--color=never" )
779
789
780
790
# Run this from the source directory so cargo finds .cargo/config
781
- run (args , env = env , verbose = self .verbose != 0 , cwd = self .rust_root )
791
+ run (args , env = env , verbose = self .verbose , cwd = self .rust_root )
782
792
783
793
def build_triple (self ):
784
794
"""Build triple as in LLVM
@@ -787,7 +797,7 @@ def build_triple(self):
787
797
so use `self.build` where possible.
788
798
"""
789
799
config = self .get_toml ('build' )
790
- return config or default_build_triple (self .verbose != 0 )
800
+ return config or default_build_triple (self .verbose )
791
801
792
802
def check_vendored_status (self ):
793
803
"""Check that vendoring is configured properly"""
@@ -838,7 +848,7 @@ def bootstrap(args):
838
848
# Configure initial bootstrap
839
849
build = RustBuild ()
840
850
build .rust_root = os .path .abspath (os .path .join (__file__ , '../../..' ))
841
- build .verbose = args .verbose
851
+ build .verbose = args .verbose != 0
842
852
build .clean = args .clean
843
853
844
854
# Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`,
@@ -866,9 +876,10 @@ def bootstrap(args):
866
876
with open (include_path ) as included_toml :
867
877
build .config_toml += os .linesep + included_toml .read ()
868
878
869
- config_verbose = build .get_toml ('verbose' , 'build' )
870
- if config_verbose is not None :
871
- build .verbose = max (build .verbose , int (config_verbose ))
879
+ verbose_count = args .verbose
880
+ config_verbose_count = build .get_toml ('verbose' , 'build' )
881
+ if config_verbose_count is not None :
882
+ verbose_count = max (args .verbose , int (config_verbose_count ))
872
883
873
884
build .use_vendored_sources = build .get_toml ('vendor' , 'build' ) == 'true'
874
885
build .use_locked_deps = build .get_toml ('locked-deps' , 'build' ) == 'true'
@@ -892,7 +903,7 @@ def bootstrap(args):
892
903
# Fetch/build the bootstrap
893
904
build .download_toolchain ()
894
905
sys .stdout .flush ()
895
- build .build_bootstrap (args .color )
906
+ build .build_bootstrap (args .color , verbose_count )
896
907
sys .stdout .flush ()
897
908
898
909
# Run the bootstrap
0 commit comments