Skip to content

Commit d6a9f7d

Browse files
committed
Extract {RustInstaller,Distcheck,CollectLicenseMetadata} into their own dist_tool_tests module
1 parent 4a44164 commit d6a9f7d

File tree

2 files changed

+179
-164
lines changed

2 files changed

+179
-164
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
//! Tool-based tests for dist workflows.
2+
3+
#![warn(unused_imports)]
4+
use std::fs;
5+
use std::path::PathBuf;
6+
7+
use super::test_helpers::run_cargo_test;
8+
use crate::Mode;
9+
use crate::core::build_steps::dist;
10+
use crate::core::build_steps::tool::{self, SourceType, Tool};
11+
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
12+
use crate::utils::exec::command;
13+
use crate::utils::helpers::{self, t};
14+
15+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
16+
pub struct Distcheck;
17+
18+
impl Step for Distcheck {
19+
type Output = ();
20+
21+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
22+
run.alias("distcheck")
23+
}
24+
25+
fn make_run(run: RunConfig<'_>) {
26+
run.builder.ensure(Distcheck);
27+
}
28+
29+
/// Runs "distcheck", a 'make check' from a tarball
30+
fn run(self, builder: &Builder<'_>) {
31+
builder.info("Distcheck");
32+
let dir = builder.tempdir().join("distcheck");
33+
let _ = fs::remove_dir_all(&dir);
34+
t!(fs::create_dir_all(&dir));
35+
36+
// Guarantee that these are built before we begin running.
37+
builder.ensure(dist::PlainSourceTarball);
38+
builder.ensure(dist::Src);
39+
40+
command("tar")
41+
.arg("-xf")
42+
.arg(builder.ensure(dist::PlainSourceTarball).tarball())
43+
.arg("--strip-components=1")
44+
.current_dir(&dir)
45+
.run(builder);
46+
command("./configure")
47+
.args(&builder.config.configure_args)
48+
.arg("--enable-vendor")
49+
.current_dir(&dir)
50+
.run(builder);
51+
command(helpers::make(&builder.config.build.triple))
52+
.arg("check")
53+
.current_dir(&dir)
54+
.run(builder);
55+
56+
// Now make sure that rust-src has all of libstd's dependencies
57+
builder.info("Distcheck rust-src");
58+
let dir = builder.tempdir().join("distcheck-src");
59+
let _ = fs::remove_dir_all(&dir);
60+
t!(fs::create_dir_all(&dir));
61+
62+
command("tar")
63+
.arg("-xf")
64+
.arg(builder.ensure(dist::Src).tarball())
65+
.arg("--strip-components=1")
66+
.current_dir(&dir)
67+
.run(builder);
68+
69+
let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
70+
command(&builder.initial_cargo)
71+
// Will read the libstd Cargo.toml
72+
// which uses the unstable `public-dependency` feature.
73+
.env("RUSTC_BOOTSTRAP", "1")
74+
.arg("generate-lockfile")
75+
.arg("--manifest-path")
76+
.arg(&toml)
77+
.current_dir(&dir)
78+
.run(builder);
79+
}
80+
}
81+
82+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
83+
pub struct RustInstaller;
84+
85+
impl Step for RustInstaller {
86+
type Output = ();
87+
const ONLY_HOSTS: bool = true;
88+
const DEFAULT: bool = true;
89+
90+
/// Ensure the version placeholder replacement tool builds
91+
fn run(self, builder: &Builder<'_>) {
92+
let bootstrap_host = builder.config.build;
93+
let compiler = builder.compiler(0, bootstrap_host);
94+
let cargo = tool::prepare_tool_cargo(
95+
builder,
96+
compiler,
97+
Mode::ToolBootstrap,
98+
bootstrap_host,
99+
Kind::Test,
100+
"src/tools/rust-installer",
101+
SourceType::InTree,
102+
&[],
103+
);
104+
105+
let _guard = builder.msg(
106+
Kind::Test,
107+
compiler.stage,
108+
"rust-installer",
109+
bootstrap_host,
110+
bootstrap_host,
111+
);
112+
run_cargo_test(cargo, &[], &[], "installer", None, bootstrap_host, builder);
113+
114+
// We currently don't support running the test.sh script outside linux(?) environments.
115+
// Eventually this should likely migrate to #[test]s in rust-installer proper rather than a
116+
// set of scripts, which will likely allow dropping this if.
117+
if bootstrap_host != "x86_64-unknown-linux-gnu" {
118+
return;
119+
}
120+
121+
let mut cmd = command(builder.src.join("src/tools/rust-installer/test.sh"));
122+
let tmpdir = builder.test_out(compiler.host).join("rust-installer");
123+
let _ = std::fs::remove_dir_all(&tmpdir);
124+
let _ = std::fs::create_dir_all(&tmpdir);
125+
cmd.current_dir(&tmpdir);
126+
cmd.env("CARGO_TARGET_DIR", tmpdir.join("cargo-target"));
127+
cmd.env("CARGO", &builder.initial_cargo);
128+
cmd.env("RUSTC", &builder.initial_rustc);
129+
cmd.env("TMP_DIR", &tmpdir);
130+
cmd.delay_failure().run(builder);
131+
}
132+
133+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
134+
run.path("src/tools/rust-installer")
135+
}
136+
137+
fn make_run(run: RunConfig<'_>) {
138+
run.builder.ensure(Self);
139+
}
140+
}
141+
142+
/// Runs the tool `src/tools/collect-license-metadata` in `ONLY_CHECK=1` mode, which verifies that
143+
/// `license-metadata.json` is up-to-date and therefore running the tool normally would not update
144+
/// anything.
145+
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
146+
pub struct CollectLicenseMetadata;
147+
148+
impl Step for CollectLicenseMetadata {
149+
type Output = PathBuf;
150+
const ONLY_HOSTS: bool = true;
151+
152+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
153+
run.path("src/tools/collect-license-metadata")
154+
}
155+
156+
fn make_run(run: RunConfig<'_>) {
157+
run.builder.ensure(CollectLicenseMetadata);
158+
}
159+
160+
fn run(self, builder: &Builder<'_>) -> Self::Output {
161+
let Some(reuse) = &builder.config.reuse else {
162+
panic!("REUSE is required to collect the license metadata");
163+
};
164+
165+
let dest = builder.src.join("license-metadata.json");
166+
167+
let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
168+
cmd.env("REUSE_EXE", reuse);
169+
cmd.env("DEST", &dest);
170+
cmd.env("ONLY_CHECK", "1");
171+
cmd.run(builder);
172+
173+
dest
174+
}
175+
}

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

Lines changed: 4 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ mod compiler_crate_tests;
4242
mod compiletest_self_tests;
4343
mod compiletest_suites;
4444
mod devtool_tests;
45+
mod dist_tool_tests;
4546
mod doc_tool_tests;
4647
mod miri_tests;
4748
mod rustdoc_tests;
@@ -63,80 +64,14 @@ pub(crate) use compiletest_suites::{
6364
RustdocJSStd, RustdocJson, RustdocUi, Ui, UiFullDeps,
6465
};
6566
pub(crate) use devtool_tests::{Cargo, Clippy, RustAnalyzer, Rustfmt};
67+
pub(crate) use dist_tool_tests::{CollectLicenseMetadata, Distcheck, RustInstaller};
6668
pub(crate) use doc_tool_tests::{HtmlCheck, Linkcheck};
6769
pub(crate) use miri_tests::{CargoMiri, Miri};
6870
pub(crate) use rustdoc_tests::{CrateRustdoc, CrateRustdocJsonTypes, RustdocTheme};
6971
pub(crate) use std_tests::TestFloatParse;
7072
pub(crate) use test_helpers::Crate;
7173
pub(crate) use tidy::Tidy;
7274

73-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
74-
pub struct Distcheck;
75-
76-
impl Step for Distcheck {
77-
type Output = ();
78-
79-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
80-
run.alias("distcheck")
81-
}
82-
83-
fn make_run(run: RunConfig<'_>) {
84-
run.builder.ensure(Distcheck);
85-
}
86-
87-
/// Runs "distcheck", a 'make check' from a tarball
88-
fn run(self, builder: &Builder<'_>) {
89-
builder.info("Distcheck");
90-
let dir = builder.tempdir().join("distcheck");
91-
let _ = fs::remove_dir_all(&dir);
92-
t!(fs::create_dir_all(&dir));
93-
94-
// Guarantee that these are built before we begin running.
95-
builder.ensure(dist::PlainSourceTarball);
96-
builder.ensure(dist::Src);
97-
98-
command("tar")
99-
.arg("-xf")
100-
.arg(builder.ensure(dist::PlainSourceTarball).tarball())
101-
.arg("--strip-components=1")
102-
.current_dir(&dir)
103-
.run(builder);
104-
command("./configure")
105-
.args(&builder.config.configure_args)
106-
.arg("--enable-vendor")
107-
.current_dir(&dir)
108-
.run(builder);
109-
command(helpers::make(&builder.config.build.triple))
110-
.arg("check")
111-
.current_dir(&dir)
112-
.run(builder);
113-
114-
// Now make sure that rust-src has all of libstd's dependencies
115-
builder.info("Distcheck rust-src");
116-
let dir = builder.tempdir().join("distcheck-src");
117-
let _ = fs::remove_dir_all(&dir);
118-
t!(fs::create_dir_all(&dir));
119-
120-
command("tar")
121-
.arg("-xf")
122-
.arg(builder.ensure(dist::Src).tarball())
123-
.arg("--strip-components=1")
124-
.current_dir(&dir)
125-
.run(builder);
126-
127-
let toml = dir.join("rust-src/lib/rustlib/src/rust/library/std/Cargo.toml");
128-
command(&builder.initial_cargo)
129-
// Will read the libstd Cargo.toml
130-
// which uses the unstable `public-dependency` feature.
131-
.env("RUSTC_BOOTSTRAP", "1")
132-
.arg("generate-lockfile")
133-
.arg("--manifest-path")
134-
.arg(&toml)
135-
.current_dir(&dir)
136-
.run(builder);
137-
}
138-
}
139-
14075
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
14176
pub struct TierCheck {
14277
pub compiler: Compiler,
@@ -209,8 +144,8 @@ impl Step for LintDocs {
209144
});
210145
}
211146

212-
/// Tests that the lint examples in the rustc book generate the correct
213-
/// lints and have the expected format.
147+
/// Tests that the lint examples in the rustc book generate the correct lints and have the
148+
/// expected format.
214149
fn run(self, builder: &Builder<'_>) {
215150
builder.ensure(crate::core::build_steps::doc::RustcBook {
216151
compiler: self.compiler,
@@ -219,98 +154,3 @@ impl Step for LintDocs {
219154
});
220155
}
221156
}
222-
223-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
224-
pub struct RustInstaller;
225-
226-
impl Step for RustInstaller {
227-
type Output = ();
228-
const ONLY_HOSTS: bool = true;
229-
const DEFAULT: bool = true;
230-
231-
/// Ensure the version placeholder replacement tool builds
232-
fn run(self, builder: &Builder<'_>) {
233-
let bootstrap_host = builder.config.build;
234-
let compiler = builder.compiler(0, bootstrap_host);
235-
let cargo = tool::prepare_tool_cargo(
236-
builder,
237-
compiler,
238-
Mode::ToolBootstrap,
239-
bootstrap_host,
240-
Kind::Test,
241-
"src/tools/rust-installer",
242-
SourceType::InTree,
243-
&[],
244-
);
245-
246-
let _guard = builder.msg(
247-
Kind::Test,
248-
compiler.stage,
249-
"rust-installer",
250-
bootstrap_host,
251-
bootstrap_host,
252-
);
253-
run_cargo_test(cargo, &[], &[], "installer", None, bootstrap_host, builder);
254-
255-
// We currently don't support running the test.sh script outside linux(?) environments.
256-
// Eventually this should likely migrate to #[test]s in rust-installer proper rather than a
257-
// set of scripts, which will likely allow dropping this if.
258-
if bootstrap_host != "x86_64-unknown-linux-gnu" {
259-
return;
260-
}
261-
262-
let mut cmd = command(builder.src.join("src/tools/rust-installer/test.sh"));
263-
let tmpdir = builder.test_out(compiler.host).join("rust-installer");
264-
let _ = std::fs::remove_dir_all(&tmpdir);
265-
let _ = std::fs::create_dir_all(&tmpdir);
266-
cmd.current_dir(&tmpdir);
267-
cmd.env("CARGO_TARGET_DIR", tmpdir.join("cargo-target"));
268-
cmd.env("CARGO", &builder.initial_cargo);
269-
cmd.env("RUSTC", &builder.initial_rustc);
270-
cmd.env("TMP_DIR", &tmpdir);
271-
cmd.delay_failure().run(builder);
272-
}
273-
274-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
275-
run.path("src/tools/rust-installer")
276-
}
277-
278-
fn make_run(run: RunConfig<'_>) {
279-
run.builder.ensure(Self);
280-
}
281-
}
282-
283-
/// Runs the tool `src/tools/collect-license-metadata` in `ONLY_CHECK=1` mode,
284-
/// which verifies that `license-metadata.json` is up-to-date and therefore
285-
/// running the tool normally would not update anything.
286-
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
287-
pub struct CollectLicenseMetadata;
288-
289-
impl Step for CollectLicenseMetadata {
290-
type Output = PathBuf;
291-
const ONLY_HOSTS: bool = true;
292-
293-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
294-
run.path("src/tools/collect-license-metadata")
295-
}
296-
297-
fn make_run(run: RunConfig<'_>) {
298-
run.builder.ensure(CollectLicenseMetadata);
299-
}
300-
301-
fn run(self, builder: &Builder<'_>) -> Self::Output {
302-
let Some(reuse) = &builder.config.reuse else {
303-
panic!("REUSE is required to collect the license metadata");
304-
};
305-
306-
let dest = builder.src.join("license-metadata.json");
307-
308-
let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
309-
cmd.env("REUSE_EXE", reuse);
310-
cmd.env("DEST", &dest);
311-
cmd.env("ONLY_CHECK", "1");
312-
cmd.run(builder);
313-
314-
dest
315-
}
316-
}

0 commit comments

Comments
 (0)