Skip to content

Commit a038726

Browse files
authored
Rollup merge of rust-lang#62950 - mati865:linkcheck, r=alexcrichton
Check rustbook links on all platforms when running locally cc rust-lang#62739
2 parents 03c524e + c7e16c5 commit a038726

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

src/bootstrap/tool.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use build_helper::t;
99
use crate::Mode;
1010
use crate::Compiler;
1111
use crate::builder::{Step, RunConfig, ShouldRun, Builder};
12-
use crate::util::{exe, add_lib_path};
12+
use crate::util::{exe, add_lib_path, CiEnv};
1313
use crate::compile;
1414
use crate::channel::GitInfo;
1515
use crate::channel;
@@ -279,11 +279,26 @@ pub fn prepare_tool_cargo(
279279
cargo
280280
}
281281

282+
fn rustbook_features() -> Vec<String> {
283+
let mut features = Vec::new();
284+
285+
// Due to CI budged and risk of spurious failures we want to limit jobs running this check.
286+
// At same time local builds should run it regardless of the platform.
287+
// `CiEnv::None` means it's local build and `CHECK_LINKS` is defined in x86_64-gnu-tools to
288+
// explicitly enable it on single job
289+
if CiEnv::current() == CiEnv::None || env::var("CHECK_LINKS").is_ok() {
290+
features.push("linkcheck".to_string());
291+
}
292+
293+
features
294+
}
295+
282296
macro_rules! bootstrap_tool {
283297
($(
284298
$name:ident, $path:expr, $tool_name:expr
285299
$(,llvm_tools = $llvm:expr)*
286300
$(,is_external_tool = $external:expr)*
301+
$(,features = $features:expr)*
287302
;
288303
)+) => {
289304
#[derive(Copy, PartialEq, Eq, Clone)]
@@ -350,7 +365,12 @@ macro_rules! bootstrap_tool {
350365
} else {
351366
SourceType::InTree
352367
},
353-
extra_features: Vec::new(),
368+
extra_features: {
369+
// FIXME(#60643): avoid this lint by using `_`
370+
let mut _tmp = Vec::new();
371+
$(_tmp.extend($features);)*
372+
_tmp
373+
},
354374
}).expect("expected to build -- essential tool")
355375
}
356376
}
@@ -359,7 +379,7 @@ macro_rules! bootstrap_tool {
359379
}
360380

361381
bootstrap_tool!(
362-
Rustbook, "src/tools/rustbook", "rustbook";
382+
Rustbook, "src/tools/rustbook", "rustbook", features = rustbook_features();
363383
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen";
364384
Tidy, "src/tools/tidy", "tidy";
365385
Linkchecker, "src/tools/linkchecker", "linkchecker";

src/ci/docker/x86_64-gnu-tools/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ COPY x86_64-gnu-tools/checkregression.py /tmp/
2121
COPY x86_64-gnu-tools/checktools.sh /tmp/
2222
COPY x86_64-gnu-tools/repo.sh /tmp/
2323

24+
# Run rustbook with `linkcheck` feature enabled
25+
ENV CHECK_LINKS 1
26+
2427
ENV RUST_CONFIGURE_ARGS \
2528
--build=x86_64-unknown-linux-gnu \
2629
--save-toolstates=/tmp/toolstates.json

src/tools/rustbook/Cargo.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ version = "0.1.0"
55
license = "MIT OR Apache-2.0"
66
edition = "2018"
77

8+
[features]
9+
linkcheck = ["mdbook-linkcheck"]
10+
811
[dependencies]
912
clap = "2.25.0"
1013
failure = "0.1"
14+
mdbook-linkcheck = { version = "0.3.0", optional = true }
1115

1216
[dependencies.mdbook]
1317
version = "0.3.0"
1418
default-features = false
1519
features = ["search"]
16-
17-
[target.'cfg(all(target_arch = "x86_64", target_os = "linux"))'.dependencies]
18-
mdbook-linkcheck = "0.3.0"

src/tools/rustbook/src/main.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ use clap::{App, ArgMatches, SubCommand, AppSettings};
88
use mdbook::MDBook;
99
use mdbook::errors::{Result as Result3};
1010

11-
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
11+
#[cfg(feature = "linkcheck")]
1212
use mdbook::renderer::RenderContext;
13-
14-
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
13+
#[cfg(feature = "linkcheck")]
1514
use mdbook_linkcheck::{self, errors::BrokenLinks};
1615
use failure::Error;
1716

@@ -52,7 +51,7 @@ fn main() {
5251
if let Err(err) = linkcheck(sub_matches) {
5352
eprintln!("Error: {}", err);
5453

55-
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
54+
#[cfg(feature = "linkcheck")]
5655
{
5756
if let Ok(broken_links) = err.downcast::<BrokenLinks>() {
5857
for cause in broken_links.links().iter() {
@@ -68,7 +67,7 @@ fn main() {
6867
};
6968
}
7069

71-
#[cfg(all(target_arch = "x86_64", target_os = "linux"))]
70+
#[cfg(feature = "linkcheck")]
7271
pub fn linkcheck(args: &ArgMatches<'_>) -> Result<(), Error> {
7372
let book_dir = get_book_dir(args);
7473
let book = MDBook::load(&book_dir).unwrap();
@@ -78,9 +77,9 @@ pub fn linkcheck(args: &ArgMatches<'_>) -> Result<(), Error> {
7877
mdbook_linkcheck::check_links(&render_ctx)
7978
}
8079

81-
#[cfg(not(all(target_arch = "x86_64", target_os = "linux")))]
80+
#[cfg(not(feature = "linkcheck"))]
8281
pub fn linkcheck(_args: &ArgMatches<'_>) -> Result<(), Error> {
83-
println!("mdbook-linkcheck only works on x86_64 linux targets.");
82+
println!("mdbook-linkcheck is disabled.");
8483
Ok(())
8584
}
8685

0 commit comments

Comments
 (0)