Skip to content

Commit fa70942

Browse files
committed
Auto merge of #52036 - collin5:b50509-2, r=<try>
Clean up dependency tracking in Rustbuild [2/2] Make `clear_if_dirty` calls in `Builder::cargo` with stamp dependencies for the given Mode. Continuation of #50904 Ref issue #50509 r? @Mark-Simulacrum
2 parents 3c3e372 + 5653421 commit fa70942

File tree

6 files changed

+107
-113
lines changed

6 files changed

+107
-113
lines changed

src/bootstrap/builder.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,71 @@ impl<'a> Builder<'a> {
708708
) -> Command {
709709
let mut cargo = Command::new(&self.initial_cargo);
710710
let out_dir = self.stage_out(compiler, mode);
711+
712+
// command specific path, we call clear_if_dirty with this
713+
let mut my_out = match cmd {
714+
"build" => self.cargo_out(compiler, mode, target),
715+
716+
// This is the intended out directory for crate documentation.
717+
"doc" => self.crate_doc_out(target),
718+
719+
_ => self.stage_out(compiler, mode),
720+
};
721+
722+
let libstd_stamp = match cmd {
723+
"check" => check::libstd_stamp(self, compiler, target),
724+
_ => compile::libstd_stamp(self, compiler, target),
725+
};
726+
727+
let libtest_stamp = match cmd {
728+
"check" => check::libtest_stamp(self, compiler, target),
729+
_ => compile::libstd_stamp(self, compiler, target),
730+
};
731+
732+
let librustc_stamp = match cmd {
733+
"check" => check::librustc_stamp(self, compiler, target),
734+
_ => compile::librustc_stamp(self, compiler, target),
735+
};
736+
737+
if cmd == "doc" {
738+
if mode == Mode::Rustc || mode == Mode::ToolRustc || mode == Mode::Codegen {
739+
// This is the intended out directory for compiler documentation.
740+
my_out = self.compiler_doc_out(target);
741+
}
742+
let rustdoc = self.rustdoc(compiler.host);
743+
self.clear_if_dirty(&my_out, &rustdoc);
744+
} else {
745+
match mode {
746+
Mode::Std => {
747+
self.clear_if_dirty(&my_out, &self.rustc(compiler));
748+
},
749+
Mode::Test => {
750+
self.clear_if_dirty(&my_out, &libstd_stamp);
751+
},
752+
Mode::Rustc => {
753+
self.clear_if_dirty(&my_out, &self.rustc(compiler));
754+
self.clear_if_dirty(&my_out, &libstd_stamp);
755+
self.clear_if_dirty(&my_out, &libtest_stamp);
756+
},
757+
Mode::Codegen => {
758+
self.clear_if_dirty(&my_out, &librustc_stamp);
759+
},
760+
Mode::ToolBootstrap => { },
761+
Mode::ToolStd => {
762+
self.clear_if_dirty(&my_out, &libstd_stamp);
763+
},
764+
Mode::ToolTest => {
765+
self.clear_if_dirty(&my_out, &libstd_stamp);
766+
self.clear_if_dirty(&my_out, &libtest_stamp);
767+
},
768+
Mode::ToolRustc => {
769+
self.clear_if_dirty(&my_out, &libstd_stamp);
770+
self.clear_if_dirty(&my_out, &libtest_stamp);
771+
self.clear_if_dirty(&my_out, &librustc_stamp);
772+
},
773+
}
774+
}
775+
711776
cargo
712777
.env("CARGO_TARGET_DIR", out_dir)
713778
.arg(cmd);

src/bootstrap/check.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use compile::{run_cargo, std_cargo, test_cargo, rustc_cargo, rustc_cargo_env, add_to_sysroot};
1414
use builder::{RunConfig, Builder, ShouldRun, Step};
15-
use tool::{self, prepare_tool_cargo, SourceType};
15+
use tool::{prepare_tool_cargo, SourceType};
1616
use {Compiler, Mode};
1717
use cache::{INTERNER, Interned};
1818
use std::path::PathBuf;
@@ -40,9 +40,6 @@ impl Step for Std {
4040
let target = self.target;
4141
let compiler = builder.compiler(0, builder.config.build);
4242

43-
let out_dir = builder.stage_out(compiler, Mode::Std);
44-
builder.clear_if_dirty(&out_dir, &builder.rustc(compiler));
45-
4643
let mut cargo = builder.cargo(compiler, Mode::Std, target, "check");
4744
std_cargo(builder, &compiler, target, &mut cargo);
4845

@@ -88,10 +85,6 @@ impl Step for Rustc {
8885
let compiler = builder.compiler(0, builder.config.build);
8986
let target = self.target;
9087

91-
let stage_out = builder.stage_out(compiler, Mode::Rustc);
92-
builder.clear_if_dirty(&stage_out, &libstd_stamp(builder, compiler, target));
93-
builder.clear_if_dirty(&stage_out, &libtest_stamp(builder, compiler, target));
94-
9588
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "check");
9689
rustc_cargo(builder, &mut cargo);
9790

@@ -139,9 +132,6 @@ impl Step for CodegenBackend {
139132
let target = self.target;
140133
let backend = self.backend;
141134

142-
let out_dir = builder.cargo_out(compiler, Mode::Codegen, target);
143-
builder.clear_if_dirty(&out_dir, &librustc_stamp(builder, compiler, target));
144-
145135
let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "check");
146136
cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
147137
rustc_cargo_env(builder, &mut cargo);
@@ -180,9 +170,6 @@ impl Step for Test {
180170
let compiler = builder.compiler(0, builder.config.build);
181171
let target = self.target;
182172

183-
let out_dir = builder.stage_out(compiler, Mode::Test);
184-
builder.clear_if_dirty(&out_dir, &libstd_stamp(builder, compiler, target));
185-
186173
let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
187174
test_cargo(builder, &compiler, target, &mut cargo);
188175

@@ -220,14 +207,9 @@ impl Step for Rustdoc {
220207
}
221208

222209
fn run(self, builder: &Builder) {
223-
let compiler = builder.compiler(0, builder.config.build);
210+
let mut compiler = builder.compiler(0, builder.config.build);
224211
let target = self.target;
225212

226-
let stage_out = builder.stage_out(compiler, Mode::ToolRustc);
227-
builder.clear_if_dirty(&stage_out, &libstd_stamp(builder, compiler, target));
228-
builder.clear_if_dirty(&stage_out, &libtest_stamp(builder, compiler, target));
229-
builder.clear_if_dirty(&stage_out, &librustc_stamp(builder, compiler, target));
230-
231213
let mut cargo = prepare_tool_cargo(builder,
232214
compiler,
233215
Mode::ToolRustc,
@@ -247,11 +229,14 @@ impl Step for Rustdoc {
247229
let libdir = builder.sysroot_libdir(compiler, target);
248230
add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
249231

250-
builder.ensure(tool::CleanTools {
251-
compiler,
252-
target,
253-
cause: Mode::Rustc,
254-
});
232+
// This is for the original compiler, but if we're forced to use stage 1, then
233+
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
234+
// we copy the libs forward.
235+
if builder.force_use_stage1(compiler, target) {
236+
compiler = builder.compiler(1, compiler.host)
237+
};
238+
239+
builder.cargo(compiler, Mode::ToolRustc, target, "clean");
255240
}
256241
}
257242

src/bootstrap/compile.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use serde_json;
3232
use util::{exe, libdir, is_dylib, CiEnv};
3333
use {Compiler, Mode};
3434
use native;
35-
use tool;
3635

3736
use cache::{INTERNER, Interned};
3837
use builder::{Step, RunConfig, ShouldRun, Builder};
@@ -107,8 +106,6 @@ impl Step for Std {
107106
copy_musl_third_party_objects(builder, target, &libdir);
108107
}
109108

110-
let out_dir = builder.cargo_out(compiler, Mode::Std, target);
111-
builder.clear_if_dirty(&out_dir, &builder.rustc(compiler));
112109
let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
113110
std_cargo(builder, &compiler, target, &mut cargo);
114111

@@ -228,7 +225,7 @@ impl Step for StdLink {
228225
/// output directory.
229226
fn run(self, builder: &Builder) {
230227
let compiler = self.compiler;
231-
let target_compiler = self.target_compiler;
228+
let mut target_compiler = self.target_compiler;
232229
let target = self.target;
233230
builder.info(&format!("Copying stage{} std from stage{} ({} -> {} / {})",
234231
target_compiler.stage,
@@ -246,11 +243,14 @@ impl Step for StdLink {
246243
copy_apple_sanitizer_dylibs(builder, &builder.native_dir(target), "osx", &libdir);
247244
}
248245

249-
builder.ensure(tool::CleanTools {
250-
compiler: target_compiler,
251-
target,
252-
cause: Mode::Std,
253-
});
246+
// This is for the original compiler, but if we're forced to use stage 1, then
247+
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
248+
// we copy the libs forward.
249+
if builder.force_use_stage1(target_compiler, target) {
250+
target_compiler = builder.compiler(1, target_compiler.host)
251+
};
252+
253+
builder.cargo(target_compiler, Mode::ToolStd, target, "clean");
254254
}
255255
}
256256

@@ -387,8 +387,6 @@ impl Step for Test {
387387
return;
388388
}
389389

390-
let out_dir = builder.cargo_out(compiler, Mode::Test, target);
391-
builder.clear_if_dirty(&out_dir, &libstd_stamp(builder, compiler, target));
392390
let mut cargo = builder.cargo(compiler, Mode::Test, target, "build");
393391
test_cargo(builder, &compiler, target, &mut cargo);
394392

@@ -438,7 +436,7 @@ impl Step for TestLink {
438436
/// Same as `std_link`, only for libtest
439437
fn run(self, builder: &Builder) {
440438
let compiler = self.compiler;
441-
let target_compiler = self.target_compiler;
439+
let mut target_compiler = self.target_compiler;
442440
let target = self.target;
443441
builder.info(&format!("Copying stage{} test from stage{} ({} -> {} / {})",
444442
target_compiler.stage,
@@ -448,11 +446,15 @@ impl Step for TestLink {
448446
target));
449447
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
450448
&libtest_stamp(builder, compiler, target));
451-
builder.ensure(tool::CleanTools {
452-
compiler: target_compiler,
453-
target,
454-
cause: Mode::Test,
455-
});
449+
450+
// This is for the original compiler, but if we're forced to use stage 1, then
451+
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
452+
// we copy the libs forward.
453+
if builder.force_use_stage1(target_compiler, target) {
454+
target_compiler = builder.compiler(1, target_compiler.host)
455+
};
456+
457+
builder.cargo(target_compiler, Mode::ToolTest, target, "clean");
456458
}
457459
}
458460

@@ -519,9 +521,6 @@ impl Step for Rustc {
519521
compiler: builder.compiler(self.compiler.stage, builder.config.build),
520522
target: builder.config.build,
521523
});
522-
let cargo_out = builder.cargo_out(compiler, Mode::Rustc, target);
523-
builder.clear_if_dirty(&cargo_out, &libstd_stamp(builder, compiler, target));
524-
builder.clear_if_dirty(&cargo_out, &libtest_stamp(builder, compiler, target));
525524

526525
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "build");
527526
rustc_cargo(builder, &mut cargo);
@@ -603,7 +602,7 @@ impl Step for RustcLink {
603602
/// Same as `std_link`, only for librustc
604603
fn run(self, builder: &Builder) {
605604
let compiler = self.compiler;
606-
let target_compiler = self.target_compiler;
605+
let mut target_compiler = self.target_compiler;
607606
let target = self.target;
608607
builder.info(&format!("Copying stage{} rustc from stage{} ({} -> {} / {})",
609608
target_compiler.stage,
@@ -613,11 +612,15 @@ impl Step for RustcLink {
613612
target));
614613
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
615614
&librustc_stamp(builder, compiler, target));
616-
builder.ensure(tool::CleanTools {
617-
compiler: target_compiler,
618-
target,
619-
cause: Mode::Rustc,
620-
});
615+
616+
// This is for the original compiler, but if we're forced to use stage 1, then
617+
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
618+
// we copy the libs forward.
619+
if builder.force_use_stage1(target_compiler, target) {
620+
target_compiler = builder.compiler(1, target_compiler.host)
621+
};
622+
623+
builder.cargo(target_compiler, Mode::ToolRustc, target, "clean");
621624
}
622625
}
623626

@@ -674,7 +677,6 @@ impl Step for CodegenBackend {
674677
}
675678

676679
let out_dir = builder.cargo_out(compiler, Mode::Codegen, target);
677-
builder.clear_if_dirty(&out_dir, &librustc_stamp(builder, compiler, target));
678680

679681
let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "rustc");
680682
cargo.arg("--manifest-path")

src/bootstrap/doc.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ impl Step for Std {
455455
let out = builder.doc_out(target);
456456
t!(fs::create_dir_all(&out));
457457
let compiler = builder.compiler(stage, builder.config.build);
458-
let rustdoc = builder.rustdoc(compiler.host);
459458
let compiler = if builder.force_use_stage1(compiler, target) {
460459
builder.compiler(1, compiler.host)
461460
} else {
@@ -480,7 +479,6 @@ impl Step for Std {
480479
// This way rustdoc generates output directly into the output, and rustdoc
481480
// will also directly handle merging.
482481
let my_out = builder.crate_doc_out(target);
483-
builder.clear_if_dirty(&my_out, &rustdoc);
484482
t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
485483

486484
let mut cargo = builder.cargo(compiler, Mode::Std, target, "doc");
@@ -535,7 +533,6 @@ impl Step for Test {
535533
let out = builder.doc_out(target);
536534
t!(fs::create_dir_all(&out));
537535
let compiler = builder.compiler(stage, builder.config.build);
538-
let rustdoc = builder.rustdoc(compiler.host);
539536
let compiler = if builder.force_use_stage1(compiler, target) {
540537
builder.compiler(1, compiler.host)
541538
} else {
@@ -551,7 +548,6 @@ impl Step for Test {
551548

552549
// See docs in std above for why we symlink
553550
let my_out = builder.crate_doc_out(target);
554-
builder.clear_if_dirty(&my_out, &rustdoc);
555551
t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
556552

557553
let mut cargo = builder.cargo(compiler, Mode::Test, target, "doc");
@@ -603,7 +599,6 @@ impl Step for WhitelistedRustc {
603599
let out = builder.doc_out(target);
604600
t!(fs::create_dir_all(&out));
605601
let compiler = builder.compiler(stage, builder.config.build);
606-
let rustdoc = builder.rustdoc(compiler.host);
607602
let compiler = if builder.force_use_stage1(compiler, target) {
608603
builder.compiler(1, compiler.host)
609604
} else {
@@ -619,7 +614,6 @@ impl Step for WhitelistedRustc {
619614

620615
// See docs in std above for why we symlink
621616
let my_out = builder.crate_doc_out(target);
622-
builder.clear_if_dirty(&my_out, &rustdoc);
623617
t!(symlink_dir_force(&builder.config, &my_out, &out_dir));
624618

625619
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "doc");
@@ -678,7 +672,6 @@ impl Step for Rustc {
678672

679673
// Get the correct compiler for this stage.
680674
let compiler = builder.compiler(stage, builder.config.build);
681-
let rustdoc = builder.rustdoc(compiler.host);
682675
let compiler = if builder.force_use_stage1(compiler, target) {
683676
builder.compiler(1, compiler.host)
684677
} else {
@@ -699,7 +692,6 @@ impl Step for Rustc {
699692
// We do not symlink to the same shared folder that already contains std library
700693
// documentation from previous steps as we do not want to include that.
701694
let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc");
702-
builder.clear_if_dirty(&out, &rustdoc);
703695
t!(symlink_dir_force(&builder.config, &out, &out_dir));
704696

705697
// Build cargo command.
@@ -780,7 +772,6 @@ impl Step for Rustdoc {
780772

781773
// Get the correct compiler for this stage.
782774
let compiler = builder.compiler(stage, builder.config.build);
783-
let rustdoc = builder.rustdoc(compiler.host);
784775
let compiler = if builder.force_use_stage1(compiler, target) {
785776
builder.compiler(1, compiler.host)
786777
} else {
@@ -803,7 +794,6 @@ impl Step for Rustdoc {
803794
.join(target)
804795
.join("doc");
805796
t!(fs::create_dir_all(&out_dir));
806-
builder.clear_if_dirty(&out, &rustdoc);
807797
t!(symlink_dir_force(&builder.config, &out, &out_dir));
808798

809799
// Build cargo command.

src/bootstrap/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ pub enum Mode {
347347
/// Compile a tool which uses all libraries we compile (up to rustc).
348348
/// Doesn't use the stage0 compiler libraries like "other", and includes
349349
/// tools like rustdoc, cargo, rls, etc.
350+
ToolTest,
350351
ToolStd,
351352
ToolRustc,
352353
}
@@ -567,6 +568,7 @@ impl Build {
567568
Mode::Codegen => "-codegen",
568569
Mode::ToolBootstrap => "-bootstrap-tools",
569570
Mode::ToolStd => "-tools",
571+
Mode::ToolTest => "-tools",
570572
Mode::ToolRustc => "-tools",
571573
};
572574
self.out.join(&*compiler.host)

0 commit comments

Comments
 (0)