Skip to content

Commit 5d276af

Browse files
committed
Always download stage1 when download_stage1 is set
Before, bootstrap would try to second-guess the user when compiler/ was modified or had untracked files. Now it only warns when compiler/ is modified, which means bootstrap.py doesn't have to pass stage through to rustbuild.
1 parent 43d94ec commit 5d276af

File tree

5 files changed

+16
-31
lines changed

5 files changed

+16
-31
lines changed

src/bootstrap/bootstrap.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -631,29 +631,14 @@ def maybe_download_stage1(self):
631631
merge_base = ["git", "merge-base", "HEAD", "{}/master".format(rust_lang_remote)]
632632
commit = subprocess.check_output(merge_base, universal_newlines=True).strip()
633633

634-
# Next, check if there were changes to the compiler since the ancestor commit.
635-
# If so, rebuild instead of using an outdated version of the code.
634+
# Warn if there were changes to the compiler since the ancestor commit.
636635
rev_parse = ["git", "rev-parse", "--show-toplevel"]
637636
top_level = subprocess.check_output(rev_parse, universal_newlines=True).strip()
638637
compiler = "{}/compiler/".format(top_level)
639-
# This is slightly more coarse than it needs to be; it rebuild on *any* changes, not just
640-
# changes to code.
641638
status = subprocess.call(["git", "diff-index", "--quiet", commit, "--", compiler])
642639
if status != 0:
643-
if self.verbose:
644-
print("changes to compiler/ detected, not downloading stage1")
645-
return None
646-
# Check for untracked files. Adding `build.rs` can change the build
647-
# inputs even if no modified files were changed.
648-
# Annoyingly, I can't find a way to check for untracked and modified files at the same
649-
# time. Even more annoyingly, there doesn't seem to be a way to show *whether* there are
650-
# untracked files without listing them.
651-
ls_files = ["git", "ls-files", "-o", "--exclude-standard", "compiler/"]
652-
untracked_files = subprocess.check_output(ls_files, universal_newlines=True)
653-
if untracked_files != '':
654-
if self.verbose:
655-
print("untracked files in compiler/ detected, not downloading stage1")
656-
return None
640+
print("warning: `download_stage1` is enabled, but there are changes to compiler/")
641+
657642
return commit
658643

659644
def rustc_stamp(self):
@@ -1154,8 +1139,6 @@ def bootstrap(help_triggered):
11541139
env["RUSTC_BOOTSTRAP"] = '1'
11551140
if toml_path:
11561141
env["BOOTSTRAP_CONFIG"] = toml_path
1157-
if build.stage1_commit is not None:
1158-
env["BOOTSTRAP_CACHE_STAGE1"] = "1"
11591142
run(args, env=env, verbose=build.verbose)
11601143

11611144

src/bootstrap/builder.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ impl<'a> Builder<'a> {
629629
.join("rustlib")
630630
.join(self.target.triple)
631631
.join("lib");
632-
if !crate::use_cached_rustc(&self.compiler) {
632+
if !builder.use_cached_rustc(&self.compiler) {
633633
let _ = fs::remove_dir_all(&sysroot);
634634
t!(fs::create_dir_all(&sysroot));
635635
}
@@ -702,6 +702,10 @@ impl<'a> Builder<'a> {
702702
add_dylib_path(vec![self.rustc_libdir(compiler)], cmd);
703703
}
704704

705+
pub fn use_cached_rustc(&self, compiler: &Compiler) -> bool {
706+
self.config.download_stage1 && compiler.stage == 0
707+
}
708+
705709
/// Gets a path to the compiler specified.
706710
pub fn rustc(&self, compiler: Compiler) -> PathBuf {
707711
if compiler.is_snapshot(self) {

src/bootstrap/compile.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use crate::config::TargetSelection;
2727
use crate::dist;
2828
use crate::native;
2929
use crate::tool::SourceType;
30-
use crate::use_cached_rustc;
3130
use crate::util::{exe, is_dylib, symlink_dir};
3231
use crate::{Compiler, DependencyType, GitRepo, Mode};
3332

@@ -70,7 +69,7 @@ impl Step for Std {
7069
}
7170

7271
// If this is stage 0 or 1 and we're using a cached rustc, copy the stage 0 standard library instead of rebuilding.
73-
if std::env::var("BOOTSTRAP_CACHE_STAGE1").is_ok() && compiler.stage < 2 {
72+
if builder.config.download_stage1 && compiler.stage < 2 {
7473
return;
7574
}
7675

@@ -507,7 +506,7 @@ impl Step for Rustc {
507506
// No need to build from source if we've already downloaded rustc for this platform.
508507
// This just copies the files from stage0 to stage1.
509508
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
510-
if use_cached_rustc(&compiler) {
509+
if builder.use_cached_rustc(&compiler) {
511510
return;
512511
} else if compiler_to_use != compiler {
513512
builder.ensure(Rustc { compiler: compiler_to_use, target });
@@ -907,14 +906,14 @@ impl Step for Sysroot {
907906

908907
// stage0-sysroot stores master libstd for the beta compiler.
909908
// When not using the beta compiler, there's no need to override the sysroot.
910-
let sysroot = if compiler.stage == 0 && !use_cached_rustc(&compiler) {
909+
let sysroot = if compiler.stage == 0 && !builder.use_cached_rustc(&compiler) {
911910
builder.out.join(&compiler.host.triple).join("stage0-sysroot")
912911
} else {
913912
builder.out.join(&compiler.host.triple).join(format!("stage{}", compiler.stage))
914913
};
915914

916915
// The sysroot is copied to stage1/ in Assemble, not here.
917-
if use_cached_rustc(&compiler) {
916+
if builder.use_cached_rustc(&compiler) {
918917
return INTERNER.intern_path(sysroot);
919918
}
920919

@@ -1086,7 +1085,7 @@ impl Step for Assemble {
10861085
t!(fs::create_dir_all(&bindir));
10871086
let compiler = builder.rustc(target_compiler);
10881087

1089-
if use_cached_rustc(&build_compiler) {
1088+
if builder.use_cached_rustc(&build_compiler) {
10901089
let stage0 = builder.out.join(&*build_compiler.host.triple).join("stage0");
10911090
builder.cp_r(&stage0, &builder.sysroot(target_compiler));
10921091
} else {

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub struct Config {
8080
pub cmd: Subcommand,
8181
pub incremental: bool,
8282
pub dry_run: bool,
83+
pub download_stage1: bool,
8384

8485
pub deny_warnings: bool,
8586
pub backtrace_on_ice: bool,
@@ -883,6 +884,8 @@ impl Config {
883884
config.rust_codegen_units_std = rust.codegen_units_std.map(threads_from_config);
884885
config.rust_profile_use = flags.rust_profile_use.or(rust.profile_use);
885886
config.rust_profile_generate = flags.rust_profile_generate.or(rust.profile_generate);
887+
888+
config.download_stage1 = rust.download_stage1.unwrap_or(false);
886889
} else {
887890
config.rust_profile_use = flags.rust_profile_use;
888891
config.rust_profile_generate = flags.rust_profile_generate;

src/bootstrap/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ use crate::cache::{Interned, INTERNER};
169169
pub use crate::config::Config;
170170
pub use crate::flags::Subcommand;
171171

172-
fn use_cached_rustc(compiler: &Compiler) -> bool {
173-
std::env::var("BOOTSTRAP_CACHE_STAGE1").is_ok() && compiler.stage == 0
174-
}
175-
176172
const LLVM_TOOLS: &[&str] = &[
177173
"llvm-cov", // used to generate coverage report
178174
"llvm-nm", // used to inspect binaries; it shows symbol names, their sizes and visibility

0 commit comments

Comments
 (0)