Skip to content

Commit 2224a42

Browse files
committed
Auto merge of #52036 - collin5:b50509-2, r=collin5
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 354a29a + 5ae40be commit 2224a42

File tree

6 files changed

+90
-109
lines changed

6 files changed

+90
-109
lines changed

src/bootstrap/builder.rs

+74
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,80 @@ 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+
// This is for the original compiler, but if we're forced to use stage 1, then
723+
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
724+
// we copy the libs forward.
725+
let cmp = if self.force_use_stage1(compiler, target) {
726+
self.compiler(1, compiler.host)
727+
} else {
728+
compiler
729+
};
730+
731+
let libstd_stamp = match cmd {
732+
"check" => check::libstd_stamp(self, cmp, target),
733+
_ => compile::libstd_stamp(self, cmp, target),
734+
};
735+
736+
let libtest_stamp = match cmd {
737+
"check" => check::libtest_stamp(self, cmp, target),
738+
_ => compile::libstd_stamp(self, cmp, target),
739+
};
740+
741+
let librustc_stamp = match cmd {
742+
"check" => check::librustc_stamp(self, cmp, target),
743+
_ => compile::librustc_stamp(self, cmp, target),
744+
};
745+
746+
if cmd == "doc" {
747+
if mode == Mode::Rustc || mode == Mode::ToolRustc || mode == Mode::Codegen {
748+
// This is the intended out directory for compiler documentation.
749+
my_out = self.compiler_doc_out(target);
750+
}
751+
let rustdoc = self.rustdoc(compiler.host);
752+
self.clear_if_dirty(&my_out, &rustdoc);
753+
} else if cmd != "test" {
754+
match mode {
755+
Mode::Std => {
756+
self.clear_if_dirty(&my_out, &self.rustc(compiler));
757+
},
758+
Mode::Test => {
759+
self.clear_if_dirty(&my_out, &libstd_stamp);
760+
},
761+
Mode::Rustc => {
762+
self.clear_if_dirty(&my_out, &self.rustc(compiler));
763+
self.clear_if_dirty(&my_out, &libstd_stamp);
764+
self.clear_if_dirty(&my_out, &libtest_stamp);
765+
},
766+
Mode::Codegen => {
767+
self.clear_if_dirty(&my_out, &librustc_stamp);
768+
},
769+
Mode::ToolBootstrap => { },
770+
Mode::ToolStd => {
771+
self.clear_if_dirty(&my_out, &libstd_stamp);
772+
},
773+
Mode::ToolTest => {
774+
self.clear_if_dirty(&my_out, &libstd_stamp);
775+
self.clear_if_dirty(&my_out, &libtest_stamp);
776+
},
777+
Mode::ToolRustc => {
778+
self.clear_if_dirty(&my_out, &libstd_stamp);
779+
self.clear_if_dirty(&my_out, &libtest_stamp);
780+
self.clear_if_dirty(&my_out, &librustc_stamp);
781+
},
782+
}
783+
}
784+
711785
cargo
712786
.env("CARGO_TARGET_DIR", out_dir)
713787
.arg(cmd);

src/bootstrap/check.rs

+9-24
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,14 +40,11 @@ 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

4946
let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
50-
println!("Checking std artifacts ({} -> {})", &compiler.host, target);
47+
builder.info(&format!("Checking std artifacts ({} -> {})", &compiler.host, target));
5148
run_cargo(builder,
5249
&mut cargo,
5350
vec![],
@@ -88,15 +85,13 @@ 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));
88+
builder.ensure(Test { target });
9489

9590
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "check");
9691
rustc_cargo(builder, &mut cargo);
9792

9893
let _folder = builder.fold_output(|| format!("stage{}-rustc", compiler.stage));
99-
println!("Checking compiler artifacts ({} -> {})", &compiler.host, target);
94+
builder.info(&format!("Checking compiler artifacts ({} -> {})", &compiler.host, target));
10095
run_cargo(builder,
10196
&mut cargo,
10297
vec![],
@@ -139,8 +134,7 @@ impl Step for CodegenBackend {
139134
let target = self.target;
140135
let backend = self.backend;
141136

142-
let out_dir = builder.cargo_out(compiler, Mode::Codegen, target);
143-
builder.clear_if_dirty(&out_dir, &librustc_stamp(builder, compiler, target));
137+
builder.ensure(Rustc { target });
144138

145139
let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "check");
146140
cargo.arg("--manifest-path").arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
@@ -180,14 +174,13 @@ impl Step for Test {
180174
let compiler = builder.compiler(0, builder.config.build);
181175
let target = self.target;
182176

183-
let out_dir = builder.stage_out(compiler, Mode::Test);
184-
builder.clear_if_dirty(&out_dir, &libstd_stamp(builder, compiler, target));
177+
builder.ensure(Std { target });
185178

186179
let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
187180
test_cargo(builder, &compiler, target, &mut cargo);
188181

189182
let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
190-
println!("Checking test artifacts ({} -> {})", &compiler.host, target);
183+
builder.info(&format!("Checking test artifacts ({} -> {})", &compiler.host, target));
191184
run_cargo(builder,
192185
&mut cargo,
193186
vec![],
@@ -223,10 +216,7 @@ impl Step for Rustdoc {
223216
let compiler = builder.compiler(0, builder.config.build);
224217
let target = self.target;
225218

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));
219+
builder.ensure(Rustc { target });
230220

231221
let mut cargo = prepare_tool_cargo(builder,
232222
compiler,
@@ -246,12 +236,7 @@ impl Step for Rustdoc {
246236

247237
let libdir = builder.sysroot_libdir(compiler, target);
248238
add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
249-
250-
builder.ensure(tool::CleanTools {
251-
compiler,
252-
target,
253-
cause: Mode::Rustc,
254-
});
239+
builder.cargo(compiler, Mode::ToolRustc, target, "clean");
255240
}
256241
}
257242

src/bootstrap/compile.rs

+4-24
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, GitRepo};
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

@@ -246,11 +243,7 @@ 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+
builder.cargo(target_compiler, Mode::ToolStd, target, "clean");
254247
}
255248
}
256249

@@ -387,8 +380,6 @@ impl Step for Test {
387380
return;
388381
}
389382

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

@@ -448,11 +439,8 @@ impl Step for TestLink {
448439
target));
449440
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
450441
&libtest_stamp(builder, compiler, target));
451-
builder.ensure(tool::CleanTools {
452-
compiler: target_compiler,
453-
target,
454-
cause: Mode::Test,
455-
});
442+
443+
builder.cargo(target_compiler, Mode::ToolTest, target, "clean");
456444
}
457445
}
458446

@@ -519,9 +507,6 @@ impl Step for Rustc {
519507
compiler: builder.compiler(self.compiler.stage, builder.config.build),
520508
target: builder.config.build,
521509
});
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));
525510

526511
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "build");
527512
rustc_cargo(builder, &mut cargo);
@@ -613,11 +598,7 @@ impl Step for RustcLink {
613598
target));
614599
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
615600
&librustc_stamp(builder, compiler, target));
616-
builder.ensure(tool::CleanTools {
617-
compiler: target_compiler,
618-
target,
619-
cause: Mode::Rustc,
620-
});
601+
builder.cargo(target_compiler, Mode::ToolRustc, target, "clean");
621602
}
622603
}
623604

@@ -674,7 +655,6 @@ impl Step for CodegenBackend {
674655
}
675656

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

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

src/bootstrap/doc.rs

-10
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

+2
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ pub enum Mode {
352352
/// Compile a tool which uses all libraries we compile (up to rustc).
353353
/// Doesn't use the stage0 compiler libraries like "other", and includes
354354
/// tools like rustdoc, cargo, rls, etc.
355+
ToolTest,
355356
ToolStd,
356357
ToolRustc,
357358
}
@@ -572,6 +573,7 @@ impl Build {
572573
Mode::Codegen => "-codegen",
573574
Mode::ToolBootstrap => "-bootstrap-tools",
574575
Mode::ToolStd => "-tools",
576+
Mode::ToolTest => "-tools",
575577
Mode::ToolRustc => "-tools",
576578
};
577579
self.out.join(&*compiler.host)

0 commit comments

Comments
 (0)