Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #111017

Merged
merged 12 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ impl<T> Option<T> {
{
match self {
Some(x) => x,
None => Default::default(),
None => T::default(),
}
}

Expand Down Expand Up @@ -1615,11 +1615,7 @@ impl<T> Option<T> {
where
T: Default,
{
fn default<T: Default>() -> T {
T::default()
}

self.get_or_insert_with(default)
self.get_or_insert_with(T::default)
}

/// Inserts a value computed from `f` into the option if it is [`None`],
Expand Down
76 changes: 43 additions & 33 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,23 @@ def get(base, url, path, checksums, verbose=False):
if os.path.exists(path):
if verify(path, sha256, False):
if verbose:
print("using already-download file", path)
print("using already-download file", path, file=sys.stderr)
return
else:
if verbose:
print("ignoring already-download file",
path, "due to failed verification")
path, "due to failed verification", file=sys.stderr)
os.unlink(path)
download(temp_path, "{}/{}".format(base, url), True, verbose)
if not verify(temp_path, sha256, verbose):
raise RuntimeError("failed verification")
if verbose:
print("moving {} to {}".format(temp_path, path))
print("moving {} to {}".format(temp_path, path), file=sys.stderr)
shutil.move(temp_path, path)
finally:
if os.path.isfile(temp_path):
if verbose:
print("removing", temp_path)
print("removing", temp_path, file=sys.stderr)
os.unlink(temp_path)


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


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

try:
if probably_big or verbose:
Expand Down Expand Up @@ -115,20 +115,20 @@ def _download(path, url, probably_big, verbose, exception):
def verify(path, expected, verbose):
"""Check if the sha256 sum of the given path is valid"""
if verbose:
print("verifying", path)
print("verifying", path, file=sys.stderr)
with open(path, "rb") as source:
found = hashlib.sha256(source.read()).hexdigest()
verified = found == expected
if not verified:
print("invalid checksum:\n"
" found: {}\n"
" expected: {}".format(found, expected))
" expected: {}".format(found, expected), file=sys.stderr)
return verified


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

dst_path = os.path.join(dst, name)
if verbose:
print(" extracting", member)
print(" extracting", member, file=sys.stderr)
tar.extract(member, dst)
src_path = os.path.join(dst, member)
if os.path.isdir(src_path) and os.path.exists(dst_path):
Expand All @@ -153,7 +153,7 @@ def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
def run(args, verbose=False, exception=False, is_bootstrap=False, **kwargs):
"""Run a child program in a new process"""
if verbose:
print("running: " + ' '.join(args))
print("running: " + ' '.join(args), file=sys.stderr)
sys.stdout.flush()
# Ensure that the .exe is used on Windows just in case a Linux ELF has been
# compiled in the same directory.
Expand Down Expand Up @@ -193,8 +193,8 @@ def require(cmd, exit=True, exception=False):
if exception:
raise
elif exit:
print("error: unable to run `{}`: {}".format(' '.join(cmd), exc))
print("Please make sure it's installed and in the path.")
print("error: unable to run `{}`: {}".format(' '.join(cmd), exc), file=sys.stderr)
print("Please make sure it's installed and in the path.", file=sys.stderr)
sys.exit(1)
return None

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

if sys.platform == 'darwin':
if verbose:
print("not using rustc detection as it is unreliable on macOS")
print("falling back to auto-detect")
print("not using rustc detection as it is unreliable on macOS", file=sys.stderr)
print("falling back to auto-detect", file=sys.stderr)
else:
try:
version = subprocess.check_output(["rustc", "--version", "--verbose"],
Expand All @@ -228,12 +228,14 @@ def default_build_triple(verbose):
host = next(x for x in version.split('\n') if x.startswith("host: "))
triple = host.split("host: ")[1]
if verbose:
print("detected default triple {} from pre-installed rustc".format(triple))
print("detected default triple {} from pre-installed rustc".format(triple),
file=sys.stderr)
return triple
except Exception as e:
if verbose:
print("pre-installed rustc not detected: {}".format(e))
print("falling back to auto-detect")
print("pre-installed rustc not detected: {}".format(e),
file=sys.stderr)
print("falling back to auto-detect", file=sys.stderr)

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

answer = self._should_fix_bins_and_dylibs = get_answer()
if answer:
print("info: You seem to be using Nix.")
print("info: You seem to be using Nix.", file=sys.stderr)
return answer

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

# Only build `.nix-deps` once.
nix_deps_dir = self.nix_deps_dir
Expand Down Expand Up @@ -591,7 +593,7 @@ def fix_bin_or_dylib(self, fname):
"nix-build", "-E", nix_expr, "-o", nix_deps_dir,
])
except subprocess.CalledProcessError as reason:
print("warning: failed to call nix-build:", reason)
print("warning: failed to call nix-build:", reason, file=sys.stderr)
return
self.nix_deps_dir = nix_deps_dir

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

def rustc_stamp(self):
Expand Down Expand Up @@ -755,7 +757,7 @@ def build_bootstrap(self, color, verbose_count):
if "GITHUB_ACTIONS" in env:
print("::group::Building bootstrap")
else:
print("Building bootstrap")
print("Building bootstrap", file=sys.stderr)
build_dir = os.path.join(self.build_dir, "bootstrap")
if self.clean and os.path.exists(build_dir):
shutil.rmtree(build_dir)
Expand Down Expand Up @@ -849,9 +851,12 @@ def check_vendored_status(self):
if 'SUDO_USER' in os.environ and not self.use_vendored_sources:
if os.getuid() == 0:
self.use_vendored_sources = True
print('info: looks like you\'re trying to run this command as root')
print(' and so in order to preserve your $HOME this will now')
print(' use vendored sources by default.')
print('info: looks like you\'re trying to run this command as root',
file=sys.stderr)
print(' and so in order to preserve your $HOME this will now',
file=sys.stderr)
print(' use vendored sources by default.',
file=sys.stderr)

cargo_dir = os.path.join(self.rust_root, '.cargo')
if self.use_vendored_sources:
Expand All @@ -861,14 +866,18 @@ def check_vendored_status(self):
"--sync ./src/tools/rust-analyzer/Cargo.toml " \
"--sync ./compiler/rustc_codegen_cranelift/Cargo.toml " \
"--sync ./src/bootstrap/Cargo.toml "
print('error: vendoring required, but vendor directory does not exist.')
print('error: vendoring required, but vendor directory does not exist.',
file=sys.stderr)
print(' Run `cargo vendor {}` to initialize the '
'vendor directory.'.format(sync_dirs))
print('Alternatively, use the pre-vendored `rustc-src` dist component.')
'vendor directory.'.format(sync_dirs),
file=sys.stderr)
print('Alternatively, use the pre-vendored `rustc-src` dist component.',
file=sys.stderr)
raise Exception("{} not found".format(vendor_dir))

if not os.path.exists(cargo_dir):
print('error: vendoring required, but .cargo/config does not exist.')
print('error: vendoring required, but .cargo/config does not exist.',
file=sys.stderr)
raise Exception("{} not found".format(cargo_dir))
else:
if os.path.exists(cargo_dir):
Expand Down Expand Up @@ -978,7 +987,7 @@ def main():
print(
"info: Downloading and building bootstrap before processing --help command.\n"
" See src/bootstrap/README.md for help with common commands."
)
, file=sys.stderr)

exit_code = 0
success_word = "successfully"
Expand All @@ -989,11 +998,12 @@ def main():
exit_code = error.code
else:
exit_code = 1
print(error)
print(error, file=sys.stderr)
success_word = "unsuccessfully"

if not help_triggered:
print("Build completed", success_word, "in", format_build_time(time() - start_time))
print("Build completed", success_word, "in", format_build_time(time() - start_time),
file=sys.stderr)
sys.exit(exit_code)


Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ impl Config {
if config.llvm_from_ci {
let triple = &config.build.triple;
let ci_llvm_bin = config.ci_llvm_root().join("bin");
let mut build_target = config
let build_target = config
.target_config
.entry(config.build)
.or_insert_with(|| Target::from_triple(&triple));
Expand Down
21 changes: 16 additions & 5 deletions src/bootstrap/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Config {
is_nixos && !Path::new("/lib").exists()
});
if val {
println!("info: You seem to be using Nix.");
eprintln!("info: You seem to be using Nix.");
}
val
}
Expand Down Expand Up @@ -226,7 +226,7 @@ impl Config {
curl.stdout(Stdio::from(f));
if !self.check_run(&mut curl) {
if self.build.contains("windows-msvc") {
println!("Fallback to PowerShell");
eprintln!("Fallback to PowerShell");
for _ in 0..3 {
if self.try_run(Command::new("PowerShell.exe").args(&[
"/nologo",
Expand All @@ -239,7 +239,7 @@ impl Config {
])) {
return;
}
println!("\nspurious failure, trying again");
eprintln!("\nspurious failure, trying again");
}
}
if !help_on_error.is_empty() {
Expand All @@ -250,7 +250,7 @@ impl Config {
}

fn unpack(&self, tarball: &Path, dst: &Path, pattern: &str) {
println!("extracting {} to {}", tarball.display(), dst.display());
eprintln!("extracting {} to {}", tarball.display(), dst.display());
if !dst.exists() {
t!(fs::create_dir_all(dst));
}
Expand Down Expand Up @@ -541,7 +541,18 @@ impl Config {
None
};

self.download_file(&format!("{base_url}/{url}"), &tarball, "");
let mut help_on_error = "";
if destination == "ci-rustc" {
help_on_error = "error: failed to download pre-built rustc from CI

note: old builds get deleted after a certain time
help: if trying to compile an old commit of rustc, disable `download-rustc` in config.toml:

[rust]
download-rustc = false
";
}
self.download_file(&format!("{base_url}/{url}"), &tarball, help_on_error);
if let Some(sha256) = checksum {
if !self.verify(&tarball, sha256) {
panic!("failed to verify {}", tarball.display());
Expand Down
Loading