Skip to content

Commit d4f534f

Browse files
committed
Extract {HtmlCheck,Linkcheck} into their own doc_tool_tests module
1 parent c10e7dd commit d4f534f

File tree

2 files changed

+142
-131
lines changed

2 files changed

+142
-131
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
//! Auxiliary tools for checking various documentation.
2+
3+
use super::test_helpers::run_cargo_test;
4+
use crate::core::build_steps::tool::{self, SourceType, Tool};
5+
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
6+
use crate::core::config::TargetSelection;
7+
use crate::utils::exec::command;
8+
use crate::utils::helpers::{self};
9+
use crate::{DocTests, Mode};
10+
11+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
12+
pub struct Linkcheck {
13+
host: TargetSelection,
14+
}
15+
16+
impl Step for Linkcheck {
17+
type Output = ();
18+
const ONLY_HOSTS: bool = true;
19+
const DEFAULT: bool = true;
20+
21+
/// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
22+
///
23+
/// This tool in `src/tools` will verify the validity of all our links in the
24+
/// documentation to ensure we don't have a bunch of dead ones.
25+
fn run(self, builder: &Builder<'_>) {
26+
let host = self.host;
27+
let hosts = &builder.hosts;
28+
let targets = &builder.targets;
29+
30+
// if we have different hosts and targets, some things may be built for
31+
// the host (e.g. rustc) and others for the target (e.g. std). The
32+
// documentation built for each will contain broken links to
33+
// docs built for the other platform (e.g. rustc linking to cargo)
34+
if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
35+
panic!(
36+
"Linkcheck currently does not support builds with different hosts and targets.
37+
You can skip linkcheck with --skip src/tools/linkchecker"
38+
);
39+
}
40+
41+
builder.info(&format!("Linkcheck ({host})"));
42+
43+
// Test the linkchecker itself.
44+
let bootstrap_host = builder.config.build;
45+
let compiler = builder.compiler(0, bootstrap_host);
46+
47+
let cargo = tool::prepare_tool_cargo(
48+
builder,
49+
compiler,
50+
Mode::ToolBootstrap,
51+
bootstrap_host,
52+
Kind::Test,
53+
"src/tools/linkchecker",
54+
SourceType::InTree,
55+
&[],
56+
);
57+
run_cargo_test(
58+
cargo,
59+
&[],
60+
&[],
61+
"linkchecker",
62+
"linkchecker self tests",
63+
bootstrap_host,
64+
builder,
65+
);
66+
67+
if builder.doc_tests == DocTests::No {
68+
return;
69+
}
70+
71+
// Build all the default documentation.
72+
builder.default_doc(&[]);
73+
74+
// Build the linkchecker before calling `msg`, since GHA doesn't support nested groups.
75+
let linkchecker = builder.tool_cmd(Tool::Linkchecker);
76+
77+
// Run the linkchecker.
78+
let _guard =
79+
builder.msg(Kind::Test, compiler.stage, "Linkcheck", bootstrap_host, bootstrap_host);
80+
let _time = helpers::timeit(builder);
81+
linkchecker.delay_failure().arg(builder.out.join(host).join("doc")).run(builder);
82+
}
83+
84+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
85+
let builder = run.builder;
86+
let run = run.path("src/tools/linkchecker");
87+
run.default_condition(builder.config.docs)
88+
}
89+
90+
fn make_run(run: RunConfig<'_>) {
91+
run.builder.ensure(Linkcheck { host: run.target });
92+
}
93+
}
94+
95+
fn check_if_tidy_is_installed(builder: &Builder<'_>) -> bool {
96+
command("tidy").allow_failure().arg("--version").run_capture_stdout(builder).is_success()
97+
}
98+
99+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
100+
pub struct HtmlCheck {
101+
target: TargetSelection,
102+
}
103+
104+
impl Step for HtmlCheck {
105+
type Output = ();
106+
const DEFAULT: bool = true;
107+
const ONLY_HOSTS: bool = true;
108+
109+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
110+
let builder = run.builder;
111+
let run = run.path("src/tools/html-checker");
112+
run.lazy_default_condition(Box::new(|| check_if_tidy_is_installed(builder)))
113+
}
114+
115+
fn make_run(run: RunConfig<'_>) {
116+
run.builder.ensure(HtmlCheck { target: run.target });
117+
}
118+
119+
fn run(self, builder: &Builder<'_>) {
120+
if !check_if_tidy_is_installed(builder) {
121+
eprintln!("not running HTML-check tool because `tidy` is missing");
122+
eprintln!(
123+
"You need the HTML tidy tool https://www.html-tidy.org/, this tool is *not* part of the rust project and needs to be installed separately, for example via your package manager."
124+
);
125+
panic!("Cannot run html-check tests");
126+
}
127+
// Ensure that a few different kinds of documentation are available.
128+
builder.default_doc(&[]);
129+
builder.ensure(crate::core::build_steps::doc::Rustc::new(
130+
builder.top_stage,
131+
self.target,
132+
builder,
133+
));
134+
135+
builder
136+
.tool_cmd(Tool::HtmlChecker)
137+
.delay_failure()
138+
.arg(builder.doc_out(self.target))
139+
.run(builder);
140+
}
141+
}

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

Lines changed: 1 addition & 131 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 doc_tool_tests;
4546
mod miri_tests;
4647
mod rustdoc_tests;
4748
mod std_tests;
@@ -69,137 +70,6 @@ pub(crate) use std_tests::TestFloatParse;
6970
pub(crate) use test_helpers::Crate;
7071
pub(crate) use tidy::Tidy;
7172

72-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
73-
pub struct Linkcheck {
74-
host: TargetSelection,
75-
}
76-
77-
impl Step for Linkcheck {
78-
type Output = ();
79-
const ONLY_HOSTS: bool = true;
80-
const DEFAULT: bool = true;
81-
82-
/// Runs the `linkchecker` tool as compiled in `stage` by the `host` compiler.
83-
///
84-
/// This tool in `src/tools` will verify the validity of all our links in the
85-
/// documentation to ensure we don't have a bunch of dead ones.
86-
fn run(self, builder: &Builder<'_>) {
87-
let host = self.host;
88-
let hosts = &builder.hosts;
89-
let targets = &builder.targets;
90-
91-
// if we have different hosts and targets, some things may be built for
92-
// the host (e.g. rustc) and others for the target (e.g. std). The
93-
// documentation built for each will contain broken links to
94-
// docs built for the other platform (e.g. rustc linking to cargo)
95-
if (hosts != targets) && !hosts.is_empty() && !targets.is_empty() {
96-
panic!(
97-
"Linkcheck currently does not support builds with different hosts and targets.
98-
You can skip linkcheck with --skip src/tools/linkchecker"
99-
);
100-
}
101-
102-
builder.info(&format!("Linkcheck ({host})"));
103-
104-
// Test the linkchecker itself.
105-
let bootstrap_host = builder.config.build;
106-
let compiler = builder.compiler(0, bootstrap_host);
107-
108-
let cargo = tool::prepare_tool_cargo(
109-
builder,
110-
compiler,
111-
Mode::ToolBootstrap,
112-
bootstrap_host,
113-
Kind::Test,
114-
"src/tools/linkchecker",
115-
SourceType::InTree,
116-
&[],
117-
);
118-
run_cargo_test(
119-
cargo,
120-
&[],
121-
&[],
122-
"linkchecker",
123-
"linkchecker self tests",
124-
bootstrap_host,
125-
builder,
126-
);
127-
128-
if builder.doc_tests == DocTests::No {
129-
return;
130-
}
131-
132-
// Build all the default documentation.
133-
builder.default_doc(&[]);
134-
135-
// Build the linkchecker before calling `msg`, since GHA doesn't support nested groups.
136-
let linkchecker = builder.tool_cmd(Tool::Linkchecker);
137-
138-
// Run the linkchecker.
139-
let _guard =
140-
builder.msg(Kind::Test, compiler.stage, "Linkcheck", bootstrap_host, bootstrap_host);
141-
let _time = helpers::timeit(builder);
142-
linkchecker.delay_failure().arg(builder.out.join(host).join("doc")).run(builder);
143-
}
144-
145-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
146-
let builder = run.builder;
147-
let run = run.path("src/tools/linkchecker");
148-
run.default_condition(builder.config.docs)
149-
}
150-
151-
fn make_run(run: RunConfig<'_>) {
152-
run.builder.ensure(Linkcheck { host: run.target });
153-
}
154-
}
155-
156-
fn check_if_tidy_is_installed(builder: &Builder<'_>) -> bool {
157-
command("tidy").allow_failure().arg("--version").run_capture_stdout(builder).is_success()
158-
}
159-
160-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
161-
pub struct HtmlCheck {
162-
target: TargetSelection,
163-
}
164-
165-
impl Step for HtmlCheck {
166-
type Output = ();
167-
const DEFAULT: bool = true;
168-
const ONLY_HOSTS: bool = true;
169-
170-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
171-
let builder = run.builder;
172-
let run = run.path("src/tools/html-checker");
173-
run.lazy_default_condition(Box::new(|| check_if_tidy_is_installed(builder)))
174-
}
175-
176-
fn make_run(run: RunConfig<'_>) {
177-
run.builder.ensure(HtmlCheck { target: run.target });
178-
}
179-
180-
fn run(self, builder: &Builder<'_>) {
181-
if !check_if_tidy_is_installed(builder) {
182-
eprintln!("not running HTML-check tool because `tidy` is missing");
183-
eprintln!(
184-
"You need the HTML tidy tool https://www.html-tidy.org/, this tool is *not* part of the rust project and needs to be installed separately, for example via your package manager."
185-
);
186-
panic!("Cannot run html-check tests");
187-
}
188-
// Ensure that a few different kinds of documentation are available.
189-
builder.default_doc(&[]);
190-
builder.ensure(crate::core::build_steps::doc::Rustc::new(
191-
builder.top_stage,
192-
self.target,
193-
builder,
194-
));
195-
196-
builder
197-
.tool_cmd(Tool::HtmlChecker)
198-
.delay_failure()
199-
.arg(builder.doc_out(self.target))
200-
.run(builder);
201-
}
202-
}
20373
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
20474
pub struct CrateBuildHelper {
20575
host: TargetSelection,

0 commit comments

Comments
 (0)