Skip to content

Commit fbf743c

Browse files
committed
Break out CrateRustdoc{,JsonTypes}/RustdocTheme into their own rustdoc_tests module
1 parent 3bd2561 commit fbf743c

File tree

2 files changed

+174
-161
lines changed

2 files changed

+174
-161
lines changed

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

Lines changed: 4 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ mod book_tests;
3939
mod bootstrap_self_tests;
4040
mod devtool_tests;
4141
mod miri_tests;
42+
mod rustdoc_tests;
4243
mod test_helpers;
4344
mod tidy;
4445

@@ -58,6 +59,9 @@ pub(crate) use compiletest_suites::{
5859
pub(crate) use devtool_tests::{Cargo, Clippy, RustAnalyzer, Rustfmt};
5960
pub(crate) use doc_tool_tests::{HtmlCheck, Linkcheck};
6061
pub(crate) use miri_tests::{CargoMiri, Miri};
62+
pub(crate) use rustdoc_tests::{CrateRustdoc, CrateRustdocJsonTypes, RustdocTheme};
63+
pub(crate) use std_tests::TestFloatParse;
64+
pub(crate) use test_helpers::Crate;
6165
pub(crate) use tidy::Tidy;
6266

6367
const ADB_TEST_DIR: &str = "/data/local/tmp/work";
@@ -1759,167 +1763,6 @@ impl Step for Crate {
17591763
}
17601764
}
17611765

1762-
/// Rustdoc is special in various ways, which is why this step is different from `Crate`.
1763-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1764-
pub struct CrateRustdoc {
1765-
host: TargetSelection,
1766-
}
1767-
1768-
impl Step for CrateRustdoc {
1769-
type Output = ();
1770-
const DEFAULT: bool = true;
1771-
const ONLY_HOSTS: bool = true;
1772-
1773-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1774-
run.paths(&["src/librustdoc", "src/tools/rustdoc"])
1775-
}
1776-
1777-
fn make_run(run: RunConfig<'_>) {
1778-
let builder = run.builder;
1779-
1780-
builder.ensure(CrateRustdoc { host: run.target });
1781-
}
1782-
1783-
fn run(self, builder: &Builder<'_>) {
1784-
let target = self.host;
1785-
1786-
let compiler = if builder.download_rustc() {
1787-
builder.compiler(builder.top_stage, target)
1788-
} else {
1789-
// Use the previous stage compiler to reuse the artifacts that are
1790-
// created when running compiletest for tests/rustdoc. If this used
1791-
// `compiler`, then it would cause rustdoc to be built *again*, which
1792-
// isn't really necessary.
1793-
builder.compiler_for(builder.top_stage, target, target)
1794-
};
1795-
// NOTE: normally `ensure(Rustc)` automatically runs `ensure(Std)` for us. However, when
1796-
// using `download-rustc`, the rustc_private artifacts may be in a *different sysroot* from
1797-
// the target rustdoc (`ci-rustc-sysroot` vs `stage2`). In that case, we need to ensure this
1798-
// explicitly to make sure it ends up in the stage2 sysroot.
1799-
builder.ensure(compile::Std::new(compiler, target));
1800-
builder.ensure(compile::Rustc::new(compiler, target));
1801-
1802-
let mut cargo = tool::prepare_tool_cargo(
1803-
builder,
1804-
compiler,
1805-
Mode::ToolRustc,
1806-
target,
1807-
builder.kind,
1808-
"src/tools/rustdoc",
1809-
SourceType::InTree,
1810-
&[],
1811-
);
1812-
if self.host.contains("musl") {
1813-
cargo.arg("'-Ctarget-feature=-crt-static'");
1814-
}
1815-
1816-
// This is needed for running doctests on librustdoc. This is a bit of
1817-
// an unfortunate interaction with how bootstrap works and how cargo
1818-
// sets up the dylib path, and the fact that the doctest (in
1819-
// html/markdown.rs) links to rustc-private libs. For stage1, the
1820-
// compiler host dylibs (in stage1/lib) are not the same as the target
1821-
// dylibs (in stage1/lib/rustlib/...). This is different from a normal
1822-
// rust distribution where they are the same.
1823-
//
1824-
// On the cargo side, normal tests use `target_process` which handles
1825-
// setting up the dylib for a *target* (stage1/lib/rustlib/... in this
1826-
// case). However, for doctests it uses `rustdoc_process` which only
1827-
// sets up the dylib path for the *host* (stage1/lib), which is the
1828-
// wrong directory.
1829-
//
1830-
// Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
1831-
//
1832-
// It should be considered to just stop running doctests on
1833-
// librustdoc. There is only one test, and it doesn't look too
1834-
// important. There might be other ways to avoid this, but it seems
1835-
// pretty convoluted.
1836-
//
1837-
// See also https://github.com/rust-lang/rust/issues/13983 where the
1838-
// host vs target dylibs for rustdoc are consistently tricky to deal
1839-
// with.
1840-
//
1841-
// Note that this set the host libdir for `download_rustc`, which uses a normal rust distribution.
1842-
let libdir = if builder.download_rustc() {
1843-
builder.rustc_libdir(compiler)
1844-
} else {
1845-
builder.sysroot_target_libdir(compiler, target).to_path_buf()
1846-
};
1847-
let mut dylib_path = dylib_path();
1848-
dylib_path.insert(0, PathBuf::from(&*libdir));
1849-
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
1850-
1851-
run_cargo_test(
1852-
cargo,
1853-
&[],
1854-
&["rustdoc:0.0.0".to_string()],
1855-
"rustdoc",
1856-
"rustdoc",
1857-
target,
1858-
builder,
1859-
);
1860-
}
1861-
}
1862-
1863-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1864-
pub struct CrateRustdocJsonTypes {
1865-
host: TargetSelection,
1866-
}
1867-
1868-
impl Step for CrateRustdocJsonTypes {
1869-
type Output = ();
1870-
const DEFAULT: bool = true;
1871-
const ONLY_HOSTS: bool = true;
1872-
1873-
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1874-
run.path("src/rustdoc-json-types")
1875-
}
1876-
1877-
fn make_run(run: RunConfig<'_>) {
1878-
let builder = run.builder;
1879-
1880-
builder.ensure(CrateRustdocJsonTypes { host: run.target });
1881-
}
1882-
1883-
fn run(self, builder: &Builder<'_>) {
1884-
let target = self.host;
1885-
1886-
// Use the previous stage compiler to reuse the artifacts that are
1887-
// created when running compiletest for tests/rustdoc. If this used
1888-
// `compiler`, then it would cause rustdoc to be built *again*, which
1889-
// isn't really necessary.
1890-
let compiler = builder.compiler_for(builder.top_stage, target, target);
1891-
builder.ensure(compile::Rustc::new(compiler, target));
1892-
1893-
let cargo = tool::prepare_tool_cargo(
1894-
builder,
1895-
compiler,
1896-
Mode::ToolRustc,
1897-
target,
1898-
builder.kind,
1899-
"src/rustdoc-json-types",
1900-
SourceType::InTree,
1901-
&[],
1902-
);
1903-
1904-
// FIXME: this looks very wrong, libtest doesn't accept `-C` arguments and the quotes are fishy.
1905-
let libtest_args = if self.host.contains("musl") {
1906-
["'-Ctarget-feature=-crt-static'"].as_slice()
1907-
} else {
1908-
&[]
1909-
};
1910-
1911-
run_cargo_test(
1912-
cargo,
1913-
libtest_args,
1914-
&["rustdoc-json-types".to_string()],
1915-
"rustdoc-json-types",
1916-
"rustdoc-json-types",
1917-
target,
1918-
builder,
1919-
);
1920-
}
1921-
}
1922-
19231766
/// Some test suites are run inside emulators or on remote devices, and most
19241767
/// of our test binaries are linked dynamically which means we need to ship
19251768
/// the standard library and such to the emulator ahead of time. This step
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
//! Rustdoc's self-tests and its adjacent crate tests have special logic that isn't observed by
2+
//! other devtool tests, so they are put into their own module.
3+
4+
use std::env;
5+
use std::path::PathBuf;
6+
7+
use super::test_helpers::run_cargo_test;
8+
use crate::Mode;
9+
use crate::core::build_steps::compile;
10+
use crate::core::build_steps::tool::{self, SourceType};
11+
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
12+
use crate::core::config::TargetSelection;
13+
use crate::utils::helpers::{dylib_path, dylib_path_var};
14+
15+
/// Rustdoc is special in various ways, which is why this step is different from `Crate`.
16+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
17+
pub struct CrateRustdoc {
18+
host: TargetSelection,
19+
}
20+
21+
impl Step for CrateRustdoc {
22+
type Output = ();
23+
const DEFAULT: bool = true;
24+
const ONLY_HOSTS: bool = true;
25+
26+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
27+
run.paths(&["src/librustdoc", "src/tools/rustdoc"])
28+
}
29+
30+
fn make_run(run: RunConfig<'_>) {
31+
let builder = run.builder;
32+
33+
builder.ensure(CrateRustdoc { host: run.target });
34+
}
35+
36+
fn run(self, builder: &Builder<'_>) {
37+
let target = self.host;
38+
39+
let compiler = if builder.download_rustc() {
40+
builder.compiler(builder.top_stage, target)
41+
} else {
42+
// Use the previous stage compiler to reuse the artifacts that are created when running
43+
// compiletest for tests/rustdoc. If this used `compiler`, then it would cause rustdoc
44+
// to be built *again*, which isn't really necessary.
45+
builder.compiler_for(builder.top_stage, target, target)
46+
};
47+
// NOTE: normally `ensure(Rustc)` automatically runs `ensure(Std)` for us. However, when
48+
// using `download-rustc`, the rustc_private artifacts may be in a *different sysroot* from
49+
// the target rustdoc (`ci-rustc-sysroot` vs `stage2`). In that case, we need to ensure this
50+
// explicitly to make sure it ends up in the stage2 sysroot.
51+
builder.ensure(compile::Std::new(compiler, target));
52+
builder.ensure(compile::Rustc::new(compiler, target));
53+
54+
let mut cargo = tool::prepare_tool_cargo(
55+
builder,
56+
compiler,
57+
Mode::ToolRustc,
58+
target,
59+
builder.kind,
60+
"src/tools/rustdoc",
61+
SourceType::InTree,
62+
&[],
63+
);
64+
if self.host.contains("musl") {
65+
cargo.arg("'-Ctarget-feature=-crt-static'");
66+
}
67+
68+
// This is needed for running doctests on librustdoc. This is a bit of an unfortunate
69+
// interaction with how bootstrap works and how cargo sets up the dylib path, and the fact
70+
// that the doctest (in html/markdown.rs) links to rustc-private libs. For stage1, the
71+
// compiler host dylibs (in stage1/lib) are not the same as the target dylibs (in
72+
// stage1/lib/rustlib/...). This is different from a normal rust distribution where they are
73+
// the same.
74+
//
75+
// On the cargo side, normal tests use `target_process` which handles setting up the dylib
76+
// for a *target* (stage1/lib/rustlib/... in this case). However, for doctests it uses
77+
// `rustdoc_process` which only sets up the dylib path for the *host* (stage1/lib), which is
78+
// the wrong directory.
79+
//
80+
// Recall that we special-cased `compiler_for(top_stage)` above, so we always use stage1.
81+
//
82+
// It should be considered to just stop running doctests on librustdoc. There is only one
83+
// test, and it doesn't look too important. There might be other ways to avoid this, but it
84+
// seems pretty convoluted.
85+
//
86+
// See also https://github.com/rust-lang/rust/issues/13983 where the host vs target dylibs
87+
// for rustdoc are consistently tricky to deal with.
88+
//
89+
// Note that this set the host libdir for `download_rustc`, which uses a normal rust
90+
// distribution.
91+
let libdir = if builder.download_rustc() {
92+
builder.rustc_libdir(compiler)
93+
} else {
94+
builder.sysroot_target_libdir(compiler, target).to_path_buf()
95+
};
96+
let mut dylib_path = dylib_path();
97+
dylib_path.insert(0, PathBuf::from(&*libdir));
98+
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
99+
100+
run_cargo_test(
101+
cargo,
102+
&[],
103+
&["rustdoc:0.0.0".to_string()],
104+
"rustdoc",
105+
"rustdoc",
106+
target,
107+
builder,
108+
);
109+
}
110+
}
111+
112+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
113+
pub struct CrateRustdocJsonTypes {
114+
host: TargetSelection,
115+
}
116+
117+
impl Step for CrateRustdocJsonTypes {
118+
type Output = ();
119+
const DEFAULT: bool = true;
120+
const ONLY_HOSTS: bool = true;
121+
122+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
123+
run.path("src/rustdoc-json-types")
124+
}
125+
126+
fn make_run(run: RunConfig<'_>) {
127+
let builder = run.builder;
128+
129+
builder.ensure(CrateRustdocJsonTypes { host: run.target });
130+
}
131+
132+
fn run(self, builder: &Builder<'_>) {
133+
let target = self.host;
134+
135+
// Use the previous stage compiler to reuse the artifacts that are created when running
136+
// compiletest for tests/rustdoc. If this used `compiler`, then it would cause rustdoc to be
137+
// built *again*, which isn't really necessary.
138+
let compiler = builder.compiler_for(builder.top_stage, target, target);
139+
builder.ensure(compile::Rustc::new(compiler, target));
140+
141+
let cargo = tool::prepare_tool_cargo(
142+
builder,
143+
compiler,
144+
Mode::ToolRustc,
145+
target,
146+
builder.kind,
147+
"src/rustdoc-json-types",
148+
SourceType::InTree,
149+
&[],
150+
);
151+
152+
// FIXME: this looks very wrong, libtest doesn't accept `-C` arguments and the quotes are
153+
// fishy.
154+
let libtest_args = if self.host.contains("musl") {
155+
["'-Ctarget-feature=-crt-static'"].as_slice()
156+
} else {
157+
&[]
158+
};
159+
160+
run_cargo_test(
161+
cargo,
162+
libtest_args,
163+
&["rustdoc-json-types".to_string()],
164+
"rustdoc-json-types",
165+
"rustdoc-json-types",
166+
target,
167+
builder,
168+
);
169+
}
170+
}

0 commit comments

Comments
 (0)