@@ -41,6 +41,10 @@ def get_cpus():
41
41
return 1
42
42
43
43
44
+ def eprint (* args , ** kwargs ):
45
+ kwargs ["file" ] = sys .stderr
46
+ print (* args , ** kwargs )
47
+
44
48
45
49
def get (base , url , path , checksums , verbose = False ):
46
50
with tempfile .NamedTemporaryFile (delete = False ) as temp_file :
@@ -57,23 +61,23 @@ def get(base, url, path, checksums, verbose=False):
57
61
if os .path .exists (path ):
58
62
if verify (path , sha256 , False ):
59
63
if verbose :
60
- print ("using already-download file" , path , file = sys . stderr )
64
+ eprint ("using already-download file" , path )
61
65
return
62
66
else :
63
67
if verbose :
64
- print ("ignoring already-download file" ,
65
- path , "due to failed verification" , file = sys . stderr )
68
+ eprint ("ignoring already-download file" ,
69
+ path , "due to failed verification" )
66
70
os .unlink (path )
67
71
download (temp_path , "{}/{}" .format (base , url ), True , verbose )
68
72
if not verify (temp_path , sha256 , verbose ):
69
73
raise RuntimeError ("failed verification" )
70
74
if verbose :
71
- print ("moving {} to {}" .format (temp_path , path ), file = sys . stderr )
75
+ eprint ("moving {} to {}" .format (temp_path , path ))
72
76
shutil .move (temp_path , path )
73
77
finally :
74
78
if os .path .isfile (temp_path ):
75
79
if verbose :
76
- print ("removing" , temp_path , file = sys . stderr )
80
+ eprint ("removing" , temp_path )
77
81
os .unlink (temp_path )
78
82
79
83
@@ -83,7 +87,7 @@ def download(path, url, probably_big, verbose):
83
87
_download (path , url , probably_big , verbose , True )
84
88
return
85
89
except RuntimeError :
86
- print ("\n spurious failure, trying again" , file = sys . stderr )
90
+ eprint ("\n spurious failure, trying again" )
87
91
_download (path , url , probably_big , verbose , False )
88
92
89
93
@@ -94,7 +98,7 @@ def _download(path, url, probably_big, verbose, exception):
94
98
# - If we are on win32 fallback to powershell
95
99
# - Otherwise raise the error if appropriate
96
100
if probably_big or verbose :
97
- print ("downloading {}" .format (url ), file = sys . stderr )
101
+ eprint ("downloading {}" .format (url ))
98
102
99
103
try :
100
104
if (probably_big or verbose ) and "GITHUB_ACTIONS" not in os .environ :
@@ -129,20 +133,20 @@ def _download(path, url, probably_big, verbose, exception):
129
133
def verify (path , expected , verbose ):
130
134
"""Check if the sha256 sum of the given path is valid"""
131
135
if verbose :
132
- print ("verifying" , path , file = sys . stderr )
136
+ eprint ("verifying" , path )
133
137
with open (path , "rb" ) as source :
134
138
found = hashlib .sha256 (source .read ()).hexdigest ()
135
139
verified = found == expected
136
140
if not verified :
137
- print ("invalid checksum:\n "
141
+ eprint ("invalid checksum:\n "
138
142
" found: {}\n "
139
- " expected: {}" .format (found , expected ), file = sys . stderr )
143
+ " expected: {}" .format (found , expected ))
140
144
return verified
141
145
142
146
143
147
def unpack (tarball , tarball_suffix , dst , verbose = False , match = None ):
144
148
"""Unpack the given tarball file"""
145
- print ("extracting" , tarball , file = sys . stderr )
149
+ eprint ("extracting" , tarball )
146
150
fname = os .path .basename (tarball ).replace (tarball_suffix , "" )
147
151
with contextlib .closing (tarfile .open (tarball )) as tar :
148
152
for member in tar .getnames ():
@@ -155,7 +159,7 @@ def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
155
159
156
160
dst_path = os .path .join (dst , name )
157
161
if verbose :
158
- print (" extracting" , member , file = sys . stderr )
162
+ eprint (" extracting" , member )
159
163
tar .extract (member , dst )
160
164
src_path = os .path .join (dst , member )
161
165
if os .path .isdir (src_path ) and os .path .exists (dst_path ):
@@ -167,7 +171,7 @@ def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
167
171
def run (args , verbose = False , exception = False , is_bootstrap = False , ** kwargs ):
168
172
"""Run a child program in a new process"""
169
173
if verbose :
170
- print ("running: " + ' ' .join (args ), file = sys . stderr )
174
+ eprint ("running: " + ' ' .join (args ))
171
175
sys .stdout .flush ()
172
176
# Ensure that the .exe is used on Windows just in case a Linux ELF has been
173
177
# compiled in the same directory.
@@ -207,8 +211,8 @@ def require(cmd, exit=True, exception=False):
207
211
if exception :
208
212
raise
209
213
elif exit :
210
- print ("error: unable to run `{}`: {}" .format (' ' .join (cmd ), exc ), file = sys . stderr )
211
- print ("Please make sure it's installed and in the path." , file = sys . stderr )
214
+ eprint ("error: unable to run `{}`: {}" .format (' ' .join (cmd ), exc ))
215
+ eprint ("Please make sure it's installed and in the path." )
212
216
sys .exit (1 )
213
217
return None
214
218
@@ -239,14 +243,12 @@ def default_build_triple(verbose):
239
243
host = next (x for x in version .split ('\n ' ) if x .startswith ("host: " ))
240
244
triple = host .split ("host: " )[1 ]
241
245
if verbose :
242
- print ("detected default triple {} from pre-installed rustc" .format (triple ),
243
- file = sys .stderr )
246
+ eprint ("detected default triple {} from pre-installed rustc" .format (triple ))
244
247
return triple
245
248
except Exception as e :
246
249
if verbose :
247
- print ("pre-installed rustc not detected: {}" .format (e ),
248
- file = sys .stderr )
249
- print ("falling back to auto-detect" , file = sys .stderr )
250
+ eprint ("pre-installed rustc not detected: {}" .format (e ))
251
+ eprint ("falling back to auto-detect" )
250
252
251
253
required = not platform_is_win32 ()
252
254
uname = require (["uname" , "-smp" ], exit = required )
@@ -672,15 +674,14 @@ def get_answer():
672
674
if not is_nixos :
673
675
in_nix_shell = os .getenv ('IN_NIX_SHELL' )
674
676
if in_nix_shell :
675
- print ("The IN_NIX_SHELL environment variable is `{}`;" .format (in_nix_shell ),
676
- "you may need to set `patch-binaries-for-nix=true` in config.toml" ,
677
- file = sys .stderr )
677
+ eprint ("The IN_NIX_SHELL environment variable is `{}`;" .format (in_nix_shell ),
678
+ "you may need to set `patch-binaries-for-nix=true` in config.toml" )
678
679
679
680
return is_nixos
680
681
681
682
answer = self ._should_fix_bins_and_dylibs = get_answer ()
682
683
if answer :
683
- print ("info: You seem to be using Nix." , file = sys . stderr )
684
+ eprint ("info: You seem to be using Nix." )
684
685
return answer
685
686
686
687
def fix_bin_or_dylib (self , fname ):
@@ -693,7 +694,7 @@ def fix_bin_or_dylib(self, fname):
693
694
Please see https://nixos.org/patchelf.html for more information
694
695
"""
695
696
assert self ._should_fix_bins_and_dylibs is True
696
- print ("attempting to patch" , fname , file = sys . stderr )
697
+ eprint ("attempting to patch" , fname )
697
698
698
699
# Only build `.nix-deps` once.
699
700
nix_deps_dir = self .nix_deps_dir
@@ -726,7 +727,7 @@ def fix_bin_or_dylib(self, fname):
726
727
"nix-build" , "-E" , nix_expr , "-o" , nix_deps_dir ,
727
728
])
728
729
except subprocess .CalledProcessError as reason :
729
- print ("warning: failed to call nix-build:" , reason , file = sys . stderr )
730
+ eprint ("warning: failed to call nix-build:" , reason )
730
731
return
731
732
self .nix_deps_dir = nix_deps_dir
732
733
@@ -746,7 +747,7 @@ def fix_bin_or_dylib(self, fname):
746
747
try :
747
748
subprocess .check_output ([patchelf ] + patchelf_args + [fname ])
748
749
except subprocess .CalledProcessError as reason :
749
- print ("warning: failed to call patchelf:" , reason , file = sys . stderr )
750
+ eprint ("warning: failed to call patchelf:" , reason )
750
751
return
751
752
752
753
def rustc_stamp (self ):
@@ -888,7 +889,7 @@ def build_bootstrap(self):
888
889
if "GITHUB_ACTIONS" in env :
889
890
print ("::group::Building bootstrap" )
890
891
else :
891
- print ("Building bootstrap" , file = sys . stderr )
892
+ eprint ("Building bootstrap" )
892
893
893
894
args = self .build_bootstrap_cmd (env )
894
895
# Run this from the source directory so cargo finds .cargo/config
@@ -997,12 +998,9 @@ def check_vendored_status(self):
997
998
if 'SUDO_USER' in os .environ and not self .use_vendored_sources :
998
999
if os .getuid () == 0 :
999
1000
self .use_vendored_sources = True
1000
- print ('info: looks like you\' re trying to run this command as root' ,
1001
- file = sys .stderr )
1002
- print (' and so in order to preserve your $HOME this will now' ,
1003
- file = sys .stderr )
1004
- print (' use vendored sources by default.' ,
1005
- file = sys .stderr )
1001
+ eprint ('info: looks like you\' re trying to run this command as root' )
1002
+ eprint (' and so in order to preserve your $HOME this will now' )
1003
+ eprint (' use vendored sources by default.' )
1006
1004
1007
1005
cargo_dir = os .path .join (self .rust_root , '.cargo' )
1008
1006
if self .use_vendored_sources :
@@ -1012,18 +1010,14 @@ def check_vendored_status(self):
1012
1010
"--sync ./src/tools/rust-analyzer/Cargo.toml " \
1013
1011
"--sync ./compiler/rustc_codegen_cranelift/Cargo.toml " \
1014
1012
"--sync ./src/bootstrap/Cargo.toml "
1015
- print ('error: vendoring required, but vendor directory does not exist.' ,
1016
- file = sys .stderr )
1017
- print (' Run `cargo vendor {}` to initialize the '
1018
- 'vendor directory.' .format (sync_dirs ),
1019
- file = sys .stderr )
1020
- print ('Alternatively, use the pre-vendored `rustc-src` dist component.' ,
1021
- file = sys .stderr )
1013
+ eprint ('error: vendoring required, but vendor directory does not exist.' )
1014
+ eprint (' Run `cargo vendor {}` to initialize the '
1015
+ 'vendor directory.' .format (sync_dirs ))
1016
+ eprint ('Alternatively, use the pre-vendored `rustc-src` dist component.' )
1022
1017
raise Exception ("{} not found" .format (vendor_dir ))
1023
1018
1024
1019
if not os .path .exists (cargo_dir ):
1025
- print ('error: vendoring required, but .cargo/config does not exist.' ,
1026
- file = sys .stderr )
1020
+ eprint ('error: vendoring required, but .cargo/config does not exist.' )
1027
1021
raise Exception ("{} not found" .format (cargo_dir ))
1028
1022
else :
1029
1023
if os .path .exists (cargo_dir ):
@@ -1117,10 +1111,9 @@ def main():
1117
1111
# If the user is asking for help, let them know that the whole download-and-build
1118
1112
# process has to happen before anything is printed out.
1119
1113
if help_triggered :
1120
- print (
1114
+ eprint (
1121
1115
"info: Downloading and building bootstrap before processing --help command.\n "
1122
- " See src/bootstrap/README.md for help with common commands."
1123
- , file = sys .stderr )
1116
+ " See src/bootstrap/README.md for help with common commands." )
1124
1117
1125
1118
exit_code = 0
1126
1119
success_word = "successfully"
@@ -1131,12 +1124,11 @@ def main():
1131
1124
exit_code = error .code
1132
1125
else :
1133
1126
exit_code = 1
1134
- print (error , file = sys . stderr )
1127
+ eprint (error )
1135
1128
success_word = "unsuccessfully"
1136
1129
1137
1130
if not help_triggered :
1138
- print ("Build completed" , success_word , "in" , format_build_time (time () - start_time ),
1139
- file = sys .stderr )
1131
+ eprint ("Build completed" , success_word , "in" , format_build_time (time () - start_time ))
1140
1132
sys .exit (exit_code )
1141
1133
1142
1134
0 commit comments