Skip to content

Commit 25be3eb

Browse files
committed
Extract {Crate,}Bootstrap bootstrap self-test steps into bootstrap_self_tests module
1 parent 5fd30f8 commit 25be3eb

File tree

2 files changed

+139
-121
lines changed

2 files changed

+139
-121
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//! Self-tests for bootstrap itself and tools used by bootstrap.
2+
3+
use std::path::PathBuf;
4+
5+
use super::test_helpers::run_cargo_test;
6+
use crate::Mode;
7+
use crate::core::build_steps::tool::{self, SourceType};
8+
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
9+
use crate::core::config::TargetSelection;
10+
use crate::utils::exec::command;
11+
12+
// FIXME(#137178): `CrateBootstrap` is not a great name, on cursory glance it sounds like it would
13+
// be testing bootstrap-the-crate itself, but actually tests "some tools used by bootstrap". Its
14+
// `should_run` condition is also not at all clear...
15+
16+
/// Runs `cargo test` on various internal tools used by bootstrap.
17+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
18+
pub struct CrateBootstrap {
19+
path: PathBuf,
20+
host: TargetSelection,
21+
}
22+
23+
impl Step for CrateBootstrap {
24+
type Output = ();
25+
const ONLY_HOSTS: bool = true;
26+
const DEFAULT: bool = true;
27+
28+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
29+
// This step is responsible for several different tool paths. By default it will test all of
30+
// them, but requesting specific tools on the command-line (e.g. `./x test suggest-tests`)
31+
// will test only the specified tools.
32+
run.path("src/tools/jsondoclint")
33+
.path("src/tools/suggest-tests")
34+
.path("src/tools/replace-version-placeholder")
35+
// We want `./x test tidy` to _run_ the tidy tool, not its tests. So we need a separate
36+
// alias to test the tidy tool itself.
37+
.alias("tidyselftest")
38+
}
39+
40+
fn make_run(run: RunConfig<'_>) {
41+
// Create and ensure a separate instance of this step for each path that was selected on the
42+
// command-line (or selected by default).
43+
for path in run.paths {
44+
let path = path.assert_single_path().path.clone();
45+
run.builder.ensure(CrateBootstrap { host: run.target, path });
46+
}
47+
}
48+
49+
fn run(self, builder: &Builder<'_>) {
50+
let bootstrap_host = builder.config.build;
51+
let compiler = builder.compiler(0, bootstrap_host);
52+
let mut path = self.path.to_str().unwrap();
53+
54+
// Map alias `tidyselftest` back to the actual crate path of tidy.
55+
if path == "tidyselftest" {
56+
path = "src/tools/tidy";
57+
}
58+
59+
let cargo = tool::prepare_tool_cargo(
60+
builder,
61+
compiler,
62+
Mode::ToolBootstrap,
63+
bootstrap_host,
64+
Kind::Test,
65+
path,
66+
SourceType::InTree,
67+
&[],
68+
);
69+
70+
let crate_name = path.rsplit_once('/').unwrap().1;
71+
run_cargo_test(cargo, &[], &[], crate_name, crate_name, bootstrap_host, builder);
72+
}
73+
}
74+
75+
// FIXME(#137178): `Bootstrap` is not a great name either, because it's easily confused with
76+
// `CrateBootstrap`.
77+
78+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
79+
pub struct Bootstrap;
80+
81+
impl Step for Bootstrap {
82+
type Output = ();
83+
const DEFAULT: bool = true;
84+
const ONLY_HOSTS: bool = true;
85+
86+
/// Tests the build system itself.
87+
fn run(self, builder: &Builder<'_>) {
88+
let host = builder.config.build;
89+
let compiler = builder.compiler(0, host);
90+
let _guard = builder.msg(Kind::Test, 0, "bootstrap", host, host);
91+
92+
// Some tests require cargo submodule to be present.
93+
builder.build.require_submodule("src/tools/cargo", None);
94+
95+
let mut check_bootstrap = command(builder.python());
96+
check_bootstrap
97+
.args(["-m", "unittest", "bootstrap_test.py"])
98+
.env("BUILD_DIR", &builder.out)
99+
.env("BUILD_PLATFORM", builder.build.build.triple)
100+
.env("BOOTSTRAP_TEST_RUSTC_BIN", &builder.initial_rustc)
101+
.env("BOOTSTRAP_TEST_CARGO_BIN", &builder.initial_cargo)
102+
.current_dir(builder.src.join("src/bootstrap/"));
103+
// NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible.
104+
// Use `python -m unittest` manually if you want to pass arguments.
105+
check_bootstrap.delay_failure().run(builder);
106+
107+
let mut cargo = tool::prepare_tool_cargo(
108+
builder,
109+
compiler,
110+
Mode::ToolBootstrap,
111+
host,
112+
Kind::Test,
113+
"src/bootstrap",
114+
SourceType::InTree,
115+
&[],
116+
);
117+
118+
cargo.release_build(false);
119+
120+
cargo
121+
.rustflag("-Cdebuginfo=2")
122+
.env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
123+
.env("RUSTC_BOOTSTRAP", "1");
124+
125+
// bootstrap tests are racy on directory creation so just run them one at a time. Since
126+
// there's not many this shouldn't be a problem.
127+
run_cargo_test(cargo, &["--test-threads=1"], &[], "bootstrap", None, host, builder);
128+
}
129+
130+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
131+
run.path("src/bootstrap")
132+
}
133+
134+
fn make_run(run: RunConfig<'_>) {
135+
run.builder.ensure(Bootstrap);
136+
}
137+
}

src/bootstrap/src/core/build_steps/test/mod.rs

Lines changed: 2 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -36,77 +36,19 @@ use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
3636
use crate::{CLang, DocTests, GitRepo, Mode, PathSet, envify};
3737

3838
mod book_tests;
39+
mod bootstrap_self_tests;
3940
mod test_helpers;
4041
mod tidy;
4142

4243
pub(crate) use book_tests::{
4344
EditionGuide, EmbeddedBook, ErrorIndex, Nomicon, Reference, RustByExample, RustcBook,
4445
RustdocBook, TheBook, UnstableBook,
4546
};
47+
pub(crate) use bootstrap_self_tests::{Bootstrap, CrateBootstrap};
4648
pub(crate) use tidy::Tidy;
4749

4850
const ADB_TEST_DIR: &str = "/data/local/tmp/work";
4951

50-
/// Runs `cargo test` on various internal tools used by bootstrap.
51-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
52-
pub struct CrateBootstrap {
53-
path: PathBuf,
54-
host: TargetSelection,
55-
}
56-
57-
impl Step for CrateBootstrap {
58-
type Output = ();
59-
const ONLY_HOSTS: bool = true;
60-
const DEFAULT: bool = true;
61-
62-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
63-
// This step is responsible for several different tool paths. By default
64-
// it will test all of them, but requesting specific tools on the
65-
// command-line (e.g. `./x test suggest-tests`) will test only the
66-
// specified tools.
67-
run.path("src/tools/jsondoclint")
68-
.path("src/tools/suggest-tests")
69-
.path("src/tools/replace-version-placeholder")
70-
// We want `./x test tidy` to _run_ the tidy tool, not its tests.
71-
// So we need a separate alias to test the tidy tool itself.
72-
.alias("tidyselftest")
73-
}
74-
75-
fn make_run(run: RunConfig<'_>) {
76-
// Create and ensure a separate instance of this step for each path
77-
// that was selected on the command-line (or selected by default).
78-
for path in run.paths {
79-
let path = path.assert_single_path().path.clone();
80-
run.builder.ensure(CrateBootstrap { host: run.target, path });
81-
}
82-
}
83-
84-
fn run(self, builder: &Builder<'_>) {
85-
let bootstrap_host = builder.config.build;
86-
let compiler = builder.compiler(0, bootstrap_host);
87-
let mut path = self.path.to_str().unwrap();
88-
89-
// Map alias `tidyselftest` back to the actual crate path of tidy.
90-
if path == "tidyselftest" {
91-
path = "src/tools/tidy";
92-
}
93-
94-
let cargo = tool::prepare_tool_cargo(
95-
builder,
96-
compiler,
97-
Mode::ToolBootstrap,
98-
bootstrap_host,
99-
Kind::Test,
100-
path,
101-
SourceType::InTree,
102-
&[],
103-
);
104-
105-
let crate_name = path.rsplit_once('/').unwrap().1;
106-
run_cargo_test(cargo, &[], &[], crate_name, crate_name, bootstrap_host, builder);
107-
}
108-
}
109-
11052
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11153
pub struct Linkcheck {
11254
host: TargetSelection,
@@ -2558,67 +2500,6 @@ impl Step for Distcheck {
25582500
}
25592501
}
25602502

2561-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2562-
pub struct Bootstrap;
2563-
2564-
impl Step for Bootstrap {
2565-
type Output = ();
2566-
const DEFAULT: bool = true;
2567-
const ONLY_HOSTS: bool = true;
2568-
2569-
/// Tests the build system itself.
2570-
fn run(self, builder: &Builder<'_>) {
2571-
let host = builder.config.build;
2572-
let compiler = builder.compiler(0, host);
2573-
let _guard = builder.msg(Kind::Test, 0, "bootstrap", host, host);
2574-
2575-
// Some tests require cargo submodule to be present.
2576-
builder.build.require_submodule("src/tools/cargo", None);
2577-
2578-
let mut check_bootstrap = command(builder.python());
2579-
check_bootstrap
2580-
.args(["-m", "unittest", "bootstrap_test.py"])
2581-
.env("BUILD_DIR", &builder.out)
2582-
.env("BUILD_PLATFORM", builder.build.build.triple)
2583-
.env("BOOTSTRAP_TEST_RUSTC_BIN", &builder.initial_rustc)
2584-
.env("BOOTSTRAP_TEST_CARGO_BIN", &builder.initial_cargo)
2585-
.current_dir(builder.src.join("src/bootstrap/"));
2586-
// NOTE: we intentionally don't pass test_args here because the args for unittest and cargo test are mutually incompatible.
2587-
// Use `python -m unittest` manually if you want to pass arguments.
2588-
check_bootstrap.delay_failure().run(builder);
2589-
2590-
let mut cargo = tool::prepare_tool_cargo(
2591-
builder,
2592-
compiler,
2593-
Mode::ToolBootstrap,
2594-
host,
2595-
Kind::Test,
2596-
"src/bootstrap",
2597-
SourceType::InTree,
2598-
&[],
2599-
);
2600-
2601-
cargo.release_build(false);
2602-
2603-
cargo
2604-
.rustflag("-Cdebuginfo=2")
2605-
.env("CARGO_TARGET_DIR", builder.out.join("bootstrap"))
2606-
.env("RUSTC_BOOTSTRAP", "1");
2607-
2608-
// bootstrap tests are racy on directory creation so just run them one at a time.
2609-
// Since there's not many this shouldn't be a problem.
2610-
run_cargo_test(cargo, &["--test-threads=1"], &[], "bootstrap", None, host, builder);
2611-
}
2612-
2613-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2614-
run.path("src/bootstrap")
2615-
}
2616-
2617-
fn make_run(run: RunConfig<'_>) {
2618-
run.builder.ensure(Bootstrap);
2619-
}
2620-
}
2621-
26222503
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
26232504
pub struct TierCheck {
26242505
pub compiler: Compiler,

0 commit comments

Comments
 (0)