Skip to content

Commit 8fdfab2

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 8dbbd81 + d02eb95 commit 8fdfab2

File tree

6 files changed

+85
-101
lines changed

6 files changed

+85
-101
lines changed

src/bootstrap/builder.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,82 @@ impl<'a> Builder<'a> {
707707
) -> Command {
708708
let mut cargo = Command::new(&self.initial_cargo);
709709
let out_dir = self.stage_out(compiler, mode);
710+
711+
// command specific path, we call clear_if_dirty with this
712+
let mut my_out = match cmd {
713+
"build" => self.cargo_out(compiler, mode, target),
714+
715+
// This is the intended out directory for crate documentation.
716+
"doc" => self.crate_doc_out(target),
717+
718+
_ => self.stage_out(compiler, mode),
719+
};
720+
721+
// This is for the original compiler, but if we're forced to use stage 1, then
722+
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
723+
// we copy the libs forward.
724+
let cmp = if self.force_use_stage1(compiler, target) {
725+
self.compiler(1, compiler.host)
726+
} else {
727+
compiler
728+
};
729+
730+
let libstd_stamp = match cmd {
731+
"check" => check::libstd_stamp(self, cmp, target),
732+
_ => compile::libstd_stamp(self, cmp, target),
733+
};
734+
735+
let libtest_stamp = match cmd {
736+
"check" => check::libtest_stamp(self, cmp, target),
737+
_ => compile::libstd_stamp(self, cmp, target),
738+
};
739+
740+
let librustc_stamp = match cmd {
741+
"check" => check::librustc_stamp(self, cmp, target),
742+
_ => compile::librustc_stamp(self, cmp, target),
743+
};
744+
745+
if cmd == "doc" {
746+
if mode == Mode::Rustc || mode == Mode::ToolRustc || mode == Mode::Codegen {
747+
// This is the intended out directory for compiler documentation.
748+
my_out = self.compiler_doc_out(target);
749+
}
750+
let rustdoc = self.rustdoc(compiler.host);
751+
self.clear_if_dirty(&my_out, &rustdoc);
752+
} else {
753+
match mode {
754+
Mode::Std => {
755+
self.clear_if_dirty(&my_out, &self.rustc(compiler));
756+
},
757+
Mode::Test => {
758+
self.clear_if_dirty(&my_out, &libstd_stamp);
759+
},
760+
Mode::Rustc => {
761+
self.clear_if_dirty(&my_out, &self.rustc(compiler));
762+
self.clear_if_dirty(&my_out, &libstd_stamp);
763+
self.clear_if_dirty(&my_out, &libtest_stamp);
764+
},
765+
Mode::Codegen => {
766+
self.clear_if_dirty(&my_out, &self.rustc(compiler));
767+
self.clear_if_dirty(&my_out, &libstd_stamp);
768+
self.clear_if_dirty(&my_out, &libtest_stamp);
769+
},
770+
Mode::ToolBootstrap => { },
771+
Mode::ToolStd => {
772+
self.clear_if_dirty(&my_out, &libstd_stamp);
773+
},
774+
Mode::ToolTest => {
775+
self.clear_if_dirty(&my_out, &libstd_stamp);
776+
self.clear_if_dirty(&my_out, &libtest_stamp);
777+
},
778+
Mode::ToolRustc => {
779+
self.clear_if_dirty(&my_out, &libstd_stamp);
780+
self.clear_if_dirty(&my_out, &libtest_stamp);
781+
self.clear_if_dirty(&my_out, &librustc_stamp);
782+
},
783+
}
784+
}
785+
710786
cargo
711787
.env("CARGO_TARGET_DIR", out_dir)
712788
.arg(cmd);

src/bootstrap/check.rs

Lines changed: 2 additions & 17 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};
15+
use tool::prepare_tool_cargo;
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

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

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

@@ -175,9 +168,6 @@ impl Step for Test {
175168
let compiler = builder.compiler(0, builder.config.build);
176169
let target = self.target;
177170

178-
let out_dir = builder.stage_out(compiler, Mode::Test);
179-
builder.clear_if_dirty(&out_dir, &libstd_stamp(builder, compiler, target));
180-
181171
let mut cargo = builder.cargo(compiler, Mode::Test, target, "check");
182172
test_cargo(builder, &compiler, target, &mut cargo);
183173

@@ -233,12 +223,7 @@ impl Step for Rustdoc {
233223

234224
let libdir = builder.sysroot_libdir(compiler, target);
235225
add_to_sysroot(&builder, &libdir, &rustdoc_stamp(builder, compiler, target));
236-
237-
builder.ensure(tool::CleanTools {
238-
compiler,
239-
target,
240-
cause: Mode::Rustc,
241-
});
226+
builder.cargo(compiler, Mode::ToolRustc, target, "clean");
242227
}
243228
}
244229

src/bootstrap/compile.rs

Lines changed: 4 additions & 23 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

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

@@ -447,11 +438,8 @@ impl Step for TestLink {
447438
target));
448439
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
449440
&libtest_stamp(builder, compiler, target));
450-
builder.ensure(tool::CleanTools {
451-
compiler: target_compiler,
452-
target,
453-
cause: Mode::Test,
454-
});
441+
442+
builder.cargo(target_compiler, Mode::ToolTest, target, "clean");
455443
}
456444
}
457445

@@ -518,9 +506,6 @@ impl Step for Rustc {
518506
compiler: builder.compiler(self.compiler.stage, builder.config.build),
519507
target: builder.config.build,
520508
});
521-
let cargo_out = builder.cargo_out(compiler, Mode::Rustc, target);
522-
builder.clear_if_dirty(&cargo_out, &libstd_stamp(builder, compiler, target));
523-
builder.clear_if_dirty(&cargo_out, &libtest_stamp(builder, compiler, target));
524509

525510
let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "build");
526511
rustc_cargo(builder, &mut cargo);
@@ -611,11 +596,7 @@ impl Step for RustcLink {
611596
target));
612597
add_to_sysroot(builder, &builder.sysroot_libdir(target_compiler, target),
613598
&librustc_stamp(builder, compiler, target));
614-
builder.ensure(tool::CleanTools {
615-
compiler: target_compiler,
616-
target,
617-
cause: Mode::Rustc,
618-
});
599+
builder.cargo(target_compiler, Mode::ToolRustc, target, "clean");
619600
}
620601
}
621602

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
@@ -340,6 +340,7 @@ pub enum Mode {
340340
/// Compile a tool which uses all libraries we compile (up to rustc).
341341
/// Doesn't use the stage0 compiler libraries like "other", and includes
342342
/// tools like rustdoc, cargo, rls, etc.
343+
ToolTest,
343344
ToolStd,
344345
ToolRustc,
345346
}
@@ -559,6 +560,7 @@ impl Build {
559560
Mode::Rustc => "-rustc",
560561
Mode::ToolBootstrap => "-bootstrap-tools",
561562
Mode::ToolStd => "-tools",
563+
Mode::ToolTest => "-tools",
562564
Mode::ToolRustc => "-tools",
563565
};
564566
self.out.join(&*compiler.host)

src/bootstrap/tool.rs

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,12 @@ use Mode;
1919
use Compiler;
2020
use builder::{Step, RunConfig, ShouldRun, Builder};
2121
use util::{exe, add_lib_path};
22-
use compile::{self, libtest_stamp, libstd_stamp, librustc_stamp};
22+
use compile;
2323
use native;
2424
use channel::GitInfo;
2525
use cache::Interned;
2626
use toolstate::ToolState;
2727

28-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
29-
pub struct CleanTools {
30-
pub compiler: Compiler,
31-
pub target: Interned<String>,
32-
pub cause: Mode,
33-
}
34-
35-
impl Step for CleanTools {
36-
type Output = ();
37-
38-
fn should_run(run: ShouldRun) -> ShouldRun {
39-
run.never()
40-
}
41-
42-
fn run(self, builder: &Builder) {
43-
let compiler = self.compiler;
44-
let target = self.target;
45-
let cause = self.cause;
46-
47-
// This is for the original compiler, but if we're forced to use stage 1, then
48-
// std/test/rustc stamps won't exist in stage 2, so we need to get those from stage 1, since
49-
// we copy the libs forward.
50-
let tools_dir = builder.stage_out(compiler, Mode::ToolRustc);
51-
let compiler = if builder.force_use_stage1(compiler, target) {
52-
builder.compiler(1, compiler.host)
53-
} else {
54-
compiler
55-
};
56-
57-
for &cur_mode in &[Mode::Std, Mode::Test, Mode::Rustc] {
58-
let stamp = match cur_mode {
59-
Mode::Std => libstd_stamp(builder, compiler, target),
60-
Mode::Test => libtest_stamp(builder, compiler, target),
61-
Mode::Rustc => librustc_stamp(builder, compiler, target),
62-
_ => panic!(),
63-
};
64-
65-
if builder.clear_if_dirty(&tools_dir, &stamp) {
66-
break;
67-
}
68-
69-
// If we are a rustc tool, and std changed, we also need to clear ourselves out -- our
70-
// dependencies depend on std. Therefore, we iterate up until our own mode.
71-
if cause == cur_mode {
72-
break;
73-
}
74-
}
75-
}
76-
}
77-
7828
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
7929
struct ToolBuild {
8030
compiler: Compiler,

0 commit comments

Comments
 (0)