Skip to content

Commit a422610

Browse files
authored
Rollup merge of #110999 - clubby789:bootstrap-stderr, r=Mark-Simulacrum
Output some bootstrap messages on stderr Fixes #110995
2 parents 9b10f98 + 8c8d198 commit a422610

File tree

2 files changed

+47
-37
lines changed

2 files changed

+47
-37
lines changed

src/bootstrap/bootstrap.py

+43-33
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ def get(base, url, path, checksums, verbose=False):
4242
if os.path.exists(path):
4343
if verify(path, sha256, False):
4444
if verbose:
45-
print("using already-download file", path)
45+
print("using already-download file", path, file=sys.stderr)
4646
return
4747
else:
4848
if verbose:
4949
print("ignoring already-download file",
50-
path, "due to failed verification")
50+
path, "due to failed verification", file=sys.stderr)
5151
os.unlink(path)
5252
download(temp_path, "{}/{}".format(base, url), True, verbose)
5353
if not verify(temp_path, sha256, verbose):
5454
raise RuntimeError("failed verification")
5555
if verbose:
56-
print("moving {} to {}".format(temp_path, path))
56+
print("moving {} to {}".format(temp_path, path), file=sys.stderr)
5757
shutil.move(temp_path, path)
5858
finally:
5959
if os.path.isfile(temp_path):
6060
if verbose:
61-
print("removing", temp_path)
61+
print("removing", temp_path, file=sys.stderr)
6262
os.unlink(temp_path)
6363

6464

@@ -68,7 +68,7 @@ def download(path, url, probably_big, verbose):
6868
_download(path, url, probably_big, verbose, True)
6969
return
7070
except RuntimeError:
71-
print("\nspurious failure, trying again")
71+
print("\nspurious failure, trying again", file=sys.stderr)
7272
_download(path, url, probably_big, verbose, False)
7373

7474

@@ -79,7 +79,7 @@ def _download(path, url, probably_big, verbose, exception):
7979
# - If we are on win32 fallback to powershell
8080
# - Otherwise raise the error if appropriate
8181
if probably_big or verbose:
82-
print("downloading {}".format(url))
82+
print("downloading {}".format(url), file=sys.stderr)
8383

8484
try:
8585
if probably_big or verbose:
@@ -115,20 +115,20 @@ def _download(path, url, probably_big, verbose, exception):
115115
def verify(path, expected, verbose):
116116
"""Check if the sha256 sum of the given path is valid"""
117117
if verbose:
118-
print("verifying", path)
118+
print("verifying", path, file=sys.stderr)
119119
with open(path, "rb") as source:
120120
found = hashlib.sha256(source.read()).hexdigest()
121121
verified = found == expected
122122
if not verified:
123123
print("invalid checksum:\n"
124124
" found: {}\n"
125-
" expected: {}".format(found, expected))
125+
" expected: {}".format(found, expected), file=sys.stderr)
126126
return verified
127127

128128

129129
def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
130130
"""Unpack the given tarball file"""
131-
print("extracting", tarball)
131+
print("extracting", tarball, file=sys.stderr)
132132
fname = os.path.basename(tarball).replace(tarball_suffix, "")
133133
with contextlib.closing(tarfile.open(tarball)) as tar:
134134
for member in tar.getnames():
@@ -141,7 +141,7 @@ def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
141141

142142
dst_path = os.path.join(dst, name)
143143
if verbose:
144-
print(" extracting", member)
144+
print(" extracting", member, file=sys.stderr)
145145
tar.extract(member, dst)
146146
src_path = os.path.join(dst, member)
147147
if os.path.isdir(src_path) and os.path.exists(dst_path):
@@ -153,7 +153,7 @@ def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
153153
def run(args, verbose=False, exception=False, is_bootstrap=False, **kwargs):
154154
"""Run a child program in a new process"""
155155
if verbose:
156-
print("running: " + ' '.join(args))
156+
print("running: " + ' '.join(args), file=sys.stderr)
157157
sys.stdout.flush()
158158
# Ensure that the .exe is used on Windows just in case a Linux ELF has been
159159
# compiled in the same directory.
@@ -193,8 +193,8 @@ def require(cmd, exit=True, exception=False):
193193
if exception:
194194
raise
195195
elif exit:
196-
print("error: unable to run `{}`: {}".format(' '.join(cmd), exc))
197-
print("Please make sure it's installed and in the path.")
196+
print("error: unable to run `{}`: {}".format(' '.join(cmd), exc), file=sys.stderr)
197+
print("Please make sure it's installed and in the path.", file=sys.stderr)
198198
sys.exit(1)
199199
return None
200200

@@ -218,8 +218,8 @@ def default_build_triple(verbose):
218218

219219
if sys.platform == 'darwin':
220220
if verbose:
221-
print("not using rustc detection as it is unreliable on macOS")
222-
print("falling back to auto-detect")
221+
print("not using rustc detection as it is unreliable on macOS", file=sys.stderr)
222+
print("falling back to auto-detect", file=sys.stderr)
223223
else:
224224
try:
225225
version = subprocess.check_output(["rustc", "--version", "--verbose"],
@@ -228,12 +228,14 @@ def default_build_triple(verbose):
228228
host = next(x for x in version.split('\n') if x.startswith("host: "))
229229
triple = host.split("host: ")[1]
230230
if verbose:
231-
print("detected default triple {} from pre-installed rustc".format(triple))
231+
print("detected default triple {} from pre-installed rustc".format(triple),
232+
file=sys.stderr)
232233
return triple
233234
except Exception as e:
234235
if verbose:
235-
print("pre-installed rustc not detected: {}".format(e))
236-
print("falling back to auto-detect")
236+
print("pre-installed rustc not detected: {}".format(e),
237+
file=sys.stderr)
238+
print("falling back to auto-detect", file=sys.stderr)
237239

238240
required = not platform_is_win32()
239241
ostype = require(["uname", "-s"], exit=required)
@@ -545,7 +547,7 @@ def get_answer():
545547

546548
answer = self._should_fix_bins_and_dylibs = get_answer()
547549
if answer:
548-
print("info: You seem to be using Nix.")
550+
print("info: You seem to be using Nix.", file=sys.stderr)
549551
return answer
550552

551553
def fix_bin_or_dylib(self, fname):
@@ -558,7 +560,7 @@ def fix_bin_or_dylib(self, fname):
558560
Please see https://nixos.org/patchelf.html for more information
559561
"""
560562
assert self._should_fix_bins_and_dylibs is True
561-
print("attempting to patch", fname)
563+
print("attempting to patch", fname, file=sys.stderr)
562564

563565
# Only build `.nix-deps` once.
564566
nix_deps_dir = self.nix_deps_dir
@@ -591,7 +593,7 @@ def fix_bin_or_dylib(self, fname):
591593
"nix-build", "-E", nix_expr, "-o", nix_deps_dir,
592594
])
593595
except subprocess.CalledProcessError as reason:
594-
print("warning: failed to call nix-build:", reason)
596+
print("warning: failed to call nix-build:", reason, file=sys.stderr)
595597
return
596598
self.nix_deps_dir = nix_deps_dir
597599

@@ -611,7 +613,7 @@ def fix_bin_or_dylib(self, fname):
611613
try:
612614
subprocess.check_output([patchelf] + patchelf_args + [fname])
613615
except subprocess.CalledProcessError as reason:
614-
print("warning: failed to call patchelf:", reason)
616+
print("warning: failed to call patchelf:", reason, file=sys.stderr)
615617
return
616618

617619
def rustc_stamp(self):
@@ -755,7 +757,7 @@ def build_bootstrap(self, color, verbose_count):
755757
if "GITHUB_ACTIONS" in env:
756758
print("::group::Building bootstrap")
757759
else:
758-
print("Building bootstrap")
760+
print("Building bootstrap", file=sys.stderr)
759761
build_dir = os.path.join(self.build_dir, "bootstrap")
760762
if self.clean and os.path.exists(build_dir):
761763
shutil.rmtree(build_dir)
@@ -849,9 +851,12 @@ def check_vendored_status(self):
849851
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
850852
if os.getuid() == 0:
851853
self.use_vendored_sources = True
852-
print('info: looks like you\'re trying to run this command as root')
853-
print(' and so in order to preserve your $HOME this will now')
854-
print(' use vendored sources by default.')
854+
print('info: looks like you\'re trying to run this command as root',
855+
file=sys.stderr)
856+
print(' and so in order to preserve your $HOME this will now',
857+
file=sys.stderr)
858+
print(' use vendored sources by default.',
859+
file=sys.stderr)
855860

856861
cargo_dir = os.path.join(self.rust_root, '.cargo')
857862
if self.use_vendored_sources:
@@ -861,14 +866,18 @@ def check_vendored_status(self):
861866
"--sync ./src/tools/rust-analyzer/Cargo.toml " \
862867
"--sync ./compiler/rustc_codegen_cranelift/Cargo.toml " \
863868
"--sync ./src/bootstrap/Cargo.toml "
864-
print('error: vendoring required, but vendor directory does not exist.')
869+
print('error: vendoring required, but vendor directory does not exist.',
870+
file=sys.stderr)
865871
print(' Run `cargo vendor {}` to initialize the '
866-
'vendor directory.'.format(sync_dirs))
867-
print('Alternatively, use the pre-vendored `rustc-src` dist component.')
872+
'vendor directory.'.format(sync_dirs),
873+
file=sys.stderr)
874+
print('Alternatively, use the pre-vendored `rustc-src` dist component.',
875+
file=sys.stderr)
868876
raise Exception("{} not found".format(vendor_dir))
869877

870878
if not os.path.exists(cargo_dir):
871-
print('error: vendoring required, but .cargo/config does not exist.')
879+
print('error: vendoring required, but .cargo/config does not exist.',
880+
file=sys.stderr)
872881
raise Exception("{} not found".format(cargo_dir))
873882
else:
874883
if os.path.exists(cargo_dir):
@@ -978,7 +987,7 @@ def main():
978987
print(
979988
"info: Downloading and building bootstrap before processing --help command.\n"
980989
" See src/bootstrap/README.md for help with common commands."
981-
)
990+
, file=sys.stderr)
982991

983992
exit_code = 0
984993
success_word = "successfully"
@@ -989,11 +998,12 @@ def main():
989998
exit_code = error.code
990999
else:
9911000
exit_code = 1
992-
print(error)
1001+
print(error, file=sys.stderr)
9931002
success_word = "unsuccessfully"
9941003

9951004
if not help_triggered:
996-
print("Build completed", success_word, "in", format_build_time(time() - start_time))
1005+
print("Build completed", success_word, "in", format_build_time(time() - start_time),
1006+
file=sys.stderr)
9971007
sys.exit(exit_code)
9981008

9991009

src/bootstrap/download.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl Config {
112112
is_nixos && !Path::new("/lib").exists()
113113
});
114114
if val {
115-
println!("info: You seem to be using Nix.");
115+
eprintln!("info: You seem to be using Nix.");
116116
}
117117
val
118118
}
@@ -226,7 +226,7 @@ impl Config {
226226
curl.stdout(Stdio::from(f));
227227
if !self.check_run(&mut curl) {
228228
if self.build.contains("windows-msvc") {
229-
println!("Fallback to PowerShell");
229+
eprintln!("Fallback to PowerShell");
230230
for _ in 0..3 {
231231
if self.try_run(Command::new("PowerShell.exe").args(&[
232232
"/nologo",
@@ -239,7 +239,7 @@ impl Config {
239239
])) {
240240
return;
241241
}
242-
println!("\nspurious failure, trying again");
242+
eprintln!("\nspurious failure, trying again");
243243
}
244244
}
245245
if !help_on_error.is_empty() {
@@ -250,7 +250,7 @@ impl Config {
250250
}
251251

252252
fn unpack(&self, tarball: &Path, dst: &Path, pattern: &str) {
253-
println!("extracting {} to {}", tarball.display(), dst.display());
253+
eprintln!("extracting {} to {}", tarball.display(), dst.display());
254254
if !dst.exists() {
255255
t!(fs::create_dir_all(dst));
256256
}

0 commit comments

Comments
 (0)