Skip to content

Commit cc6f786

Browse files
committed
apply some nits and add coverage for downgraded_from
Signed-off-by: onur-ozkan <[email protected]>
1 parent b222ef8 commit cc6f786

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

src/bootstrap/src/core/build_steps/clippy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ macro_rules! lint_any {
283283
}
284284

285285
fn run(self, builder: &Builder<'_>) -> Self::Output {
286-
let compiler = builder.compiler(builder.top_stage, builder.config.build, $mode == Mode::ToolRustc);
286+
let compiler = builder.compiler(builder.top_stage, builder.config.build, builder.top_stage > 0 && $mode == Mode::ToolRustc);
287287
let target = self.target;
288288

289289
builder.ensure(check::Rustc::new(target, builder).build_kind(Some(Kind::Check)));

src/bootstrap/src/core/build_steps/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ macro_rules! tool_doc {
953953
// Rustdoc needs the rustc sysroot available to build.
954954
// FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed
955955
// with strange errors, but only on a full bors test ...
956-
let _ = builder.compiler(compiler.stage, target, false);
956+
let _ = builder.compiler(compiler.stage, target, true);
957957
}
958958

959959
// Build cargo command.

src/bootstrap/src/core/build_steps/tool.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub fn prepare_tool_cargo(
175175
extra_features: &[String],
176176
) -> CargoCommand {
177177
// FIXME: remove stage check
178-
if mode == Mode::ToolRustc && !compiler.is_downgraded_already() && compiler.stage != 0 {
178+
if builder.top_stage > 0 && mode == Mode::ToolRustc && !compiler.is_downgraded_already() {
179179
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
180180
// we'd have stageN/bin/rustc and stageN/bin/$tool_name be effectively different stage
181181
// compilers, which isn't what we want.
@@ -617,8 +617,8 @@ impl Step for Rustdoc {
617617
let compiler = self.compiler;
618618
let target = compiler.host;
619619

620-
if compiler.stage == 0 {
621-
if !compiler.is_snapshot(builder) && !compiler.is_downgraded_already() {
620+
if compiler.stage == 0 && !compiler.is_downgraded_already() {
621+
if !compiler.is_snapshot(builder) {
622622
panic!("rustdoc in stage 0 must be snapshot rustdoc");
623623
}
624624
return builder.initial_rustc.with_file_name(exe("rustdoc", compiler.host));

src/bootstrap/src/core/builder/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1220,8 +1220,6 @@ impl<'a> Builder<'a> {
12201220

12211221
// FIXME: remove stage check
12221222
if stage > 0 && downgrade_for_rustc_tool {
1223-
assert!(stage > 0, "can't downgrade stage 0 compiler");
1224-
12251223
self.ensure(compile::Std::new(compiler, host));
12261224
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
12271225
// we'd have stageN/bin/rustc and stageN/bin/$tool_name be effectively different stage
@@ -1371,8 +1369,12 @@ impl<'a> Builder<'a> {
13711369
}
13721370

13731371
pub fn rustdoc(&self, mut compiler: Compiler) -> PathBuf {
1374-
// FIXME: remove stage check
1375-
if compiler.stage > 0 && !compiler.is_downgraded_already() {
1372+
if compiler.is_snapshot(self) && !compiler.is_downgraded_already() {
1373+
return self.initial_rustc.with_file_name(exe("rustdoc", compiler.host));
1374+
}
1375+
1376+
if !compiler.is_downgraded_already() {
1377+
assert!(compiler.stage > 0, "Can't use stage0 compiler for rustdoc");
13761378
compiler.downgrade();
13771379
}
13781380

src/bootstrap/src/core/builder/tests.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,23 @@ mod defaults {
359359
assert_eq!(first(cache.all::<tool::ErrorIndex>()), &[tool::ErrorIndex {
360360
compiler: Compiler::new(0, a)
361361
}]);
362+
assert!(first(cache.all::<tool::Rustdoc>()).is_empty());
363+
}
364+
365+
#[test]
366+
fn doc_stage_1() {
367+
let mut config = configure("doc", &[TEST_TRIPLE_1], &[TEST_TRIPLE_1]);
368+
config.compiler_docs = true;
369+
config.stage = 1;
370+
config.cmd = Subcommand::Doc { open: false, json: false };
371+
let mut cache = run_build(&[], config);
372+
let a = TargetSelection::from_user(TEST_TRIPLE_1);
373+
362374
// docs should be built with the beta compiler, not with the stage0 artifacts.
363375
// recall that rustdoc is off-by-one: `stage` is the compiler rustdoc is _linked_ to,
364376
// not the one it was built by.
365377
assert_eq!(first(cache.all::<tool::Rustdoc>()), &[tool::Rustdoc {
366-
compiler: Compiler::new(0, a)
378+
compiler: Compiler::new(0, a).downgraded_from(1)
367379
},]);
368380
}
369381
}
@@ -396,7 +408,7 @@ mod dist {
396408
assert_eq!(first(cache.all::<dist::Src>()), &[dist::Src]);
397409
// Make sure rustdoc is only built once.
398410
assert_eq!(first(cache.all::<tool::Rustdoc>()), &[tool::Rustdoc {
399-
compiler: Compiler::new(1, a).with_stage(1)
411+
compiler: Compiler::new(1, a).downgraded_from(2)
400412
},]);
401413
}
402414

@@ -764,8 +776,8 @@ mod dist {
764776
// (currently) needed to run "cargo test" on the linkchecker, and
765777
// should be relatively "free".
766778
assert_eq!(first(builder.cache.all::<tool::Rustdoc>()), &[
767-
tool::Rustdoc { compiler: Compiler::new(0, a) },
768-
tool::Rustdoc { compiler: Compiler::new(1, a) },
779+
tool::Rustdoc { compiler: Compiler::new(0, a).downgraded_from(1) },
780+
tool::Rustdoc { compiler: Compiler::new(1, a).downgraded_from(2) },
769781
]);
770782
}
771783
}

src/bootstrap/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ impl std::hash::Hash for Compiler {
106106

107107
impl PartialEq for Compiler {
108108
fn eq(&self, other: &Self) -> bool {
109-
// FIXME: cover `downgraded_from` for test env
110109
self.stage == other.stage && self.host == other.host
110+
// We have coverage for `downgraded_from` in our unit tests
111+
&& (!cfg!(test) || self.downgraded_from == other.downgraded_from)
111112
}
112113
}
113114

0 commit comments

Comments
 (0)