Skip to content

Commit 9b5aef2

Browse files
committed
Read docs.rs metadata when running rustdoc
- Add tests for doc runs - Only give an error when docs.rs feature is set This allows distinguishing between 'any doc run' and 'doc run that uses docs.rs features'
1 parent b55a557 commit 9b5aef2

File tree

12 files changed

+367
-8
lines changed

12 files changed

+367
-8
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ chrono-humanize = "0.1.1"
2020
crates-index = "0.16.2"
2121
crossbeam-utils = "0.5"
2222
csv = "1.0.2"
23+
docsrs-metadata = { git = "https://github.com/rust-lang/docs.rs/" }
2324
dotenv = "0.13"
2425
failure = "0.1.3"
2526
flate2 = "1"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "docs-rs-features"
3+
version = "0.1.0"
4+
authors = ["Joshua Nelson <jyn514@gmail.com>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
11+
[package.metadata.docs.rs]
12+
features = ["docs_rs_feature"]
13+
14+
[features]
15+
docs_rs_feature = []
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[cfg(feature = "docs_rs_feature")]
2+
compile_error!("oh no, a hidden regression!");
3+
4+
fn main() {
5+
println!("Hello, world!");
6+
}

src/runner/test.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ use crate::runner::tasks::TaskCtx;
66
use crate::runner::OverrideResult;
77
use cargo_metadata::diagnostic::DiagnosticLevel;
88
use cargo_metadata::{Message, Metadata, PackageId};
9+
use docsrs_metadata::Metadata as DocsrsMetadata;
910
use failure::Error;
1011
use remove_dir_all::remove_dir_all;
1112
use rustwide::cmd::{CommandError, ProcessLinesActions, SandboxBuilder};
1213
use rustwide::{Build, PrepareError};
13-
use std::collections::{BTreeSet, HashSet};
14+
use std::collections::{BTreeSet, HashMap, HashSet};
1415
use std::convert::TryFrom;
1516

1617
fn failure_reason(err: &Error) -> FailureReason {
@@ -83,6 +84,7 @@ fn run_cargo<DB: WriteResults>(
8384
args: &[&str],
8485
check_errors: bool,
8586
local_packages_id: &HashSet<PackageId>,
87+
env: HashMap<&'static str, String>,
8688
) -> Fallible<()> {
8789
let mut rustflags = format!("--cap-lints={}", ctx.experiment.cap_lints.to_str());
8890
if let Some(ref tc_rustflags) = ctx.toolchain.rustflags {
@@ -151,6 +153,9 @@ fn run_cargo<DB: WriteResults>(
151153
.env("CARGO_INCREMENTAL", "0")
152154
.env("RUST_BACKTRACE", "full")
153155
.env(rustflags_env, rustflags);
156+
for (var, data) in env {
157+
command = command.env(var, data);
158+
}
154159

155160
if check_errors {
156161
command = command.process_lines(&mut detect_error);
@@ -241,13 +246,15 @@ fn build<DB: WriteResults>(
241246
&["build", "--frozen", "--message-format=json"],
242247
true,
243248
local_packages_id,
249+
HashMap::default(),
244250
)?;
245251
run_cargo(
246252
ctx,
247253
build_env,
248254
&["test", "--frozen", "--no-run", "--message-format=json"],
249255
true,
250256
local_packages_id,
257+
HashMap::default(),
251258
)?;
252259
Ok(())
253260
}
@@ -259,6 +266,7 @@ fn test<DB: WriteResults>(ctx: &TaskCtx<DB>, build_env: &Build) -> Fallible<()>
259266
&["test", "--frozen"],
260267
false,
261268
&HashSet::new(),
269+
HashMap::default(),
262270
)
263271
}
264272

@@ -311,6 +319,7 @@ pub(super) fn test_check_only<DB: WriteResults>(
311319
],
312320
true,
313321
local_packages_id,
322+
HashMap::default(),
314323
) {
315324
Ok(TestResult::BuildFail(failure_reason(&err)))
316325
} else {
@@ -335,6 +344,7 @@ pub(super) fn test_clippy_only<DB: WriteResults>(
335344
],
336345
true,
337346
local_packages_id,
347+
HashMap::default(),
338348
) {
339349
Ok(TestResult::BuildFail(failure_reason(&err)))
340350
} else {
@@ -347,18 +357,26 @@ pub(super) fn test_rustdoc<DB: WriteResults>(
347357
build_env: &Build,
348358
local_packages_id: &HashSet<PackageId>,
349359
) -> Fallible<TestResult> {
360+
let src = build_env.host_source_dir();
361+
let metadata = DocsrsMetadata::from_crate_root(src)?;
362+
let cargo_args = metadata.cargo_args(
363+
&[
364+
"--frozen".into(),
365+
"--document-private-items".into(),
366+
"--message-format=json".into(),
367+
],
368+
&[],
369+
);
370+
assert_eq!(cargo_args[0], "rustdoc");
371+
let cargo_args: Vec<_> = cargo_args.iter().map(|s| s.as_str()).collect();
372+
350373
let res = run_cargo(
351374
ctx,
352375
build_env,
353-
&[
354-
"doc",
355-
"--frozen",
356-
"--no-deps",
357-
"--document-private-items",
358-
"--message-format=json",
359-
],
376+
&cargo_args,
360377
true,
361378
local_packages_id,
379+
metadata.environment_variables(),
362380
);
363381

364382
// Make sure to remove the built documentation

tests/minicrater/doc/config.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[server.bot-acl]
2+
rust-teams = true
3+
github = ["pietroalbini"]
4+
5+
[server.labels]
6+
remove = "^S-"
7+
experiment-queued = "S-waiting-on-crater"
8+
experiment-completed = "S-waiting-on-review"
9+
10+
[server.distributed]
11+
chunk-size = 32
12+
13+
[demo-crates]
14+
crates = []
15+
github-repos = []
16+
local-crates = ["build-pass", "docs-rs-features"]
17+
18+
[sandbox]
19+
memory-limit = "512M"
20+
build-log-max-size = "2M"
21+
build-log-max-lines = 1000
22+
23+
[crates]
24+
25+
[github-repos]
26+
27+
[local-crates]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"available_archives": [
3+
{
4+
"name": "All the crates",
5+
"path": "logs-archives/all.tar.gz"
6+
},
7+
{
8+
"name": "error crates",
9+
"path": "logs-archives/error.tar.gz"
10+
}
11+
],
12+
"crates_count": 2,
13+
"nav": [
14+
{
15+
"active": false,
16+
"label": "Summary",
17+
"url": "index.html"
18+
},
19+
{
20+
"active": false,
21+
"label": "Full report",
22+
"url": "full.html"
23+
},
24+
{
25+
"active": true,
26+
"label": "Downloads",
27+
"url": "downloads.html"
28+
}
29+
]
30+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"categories": [
3+
[
4+
"error",
5+
{
6+
"Plain": [
7+
{
8+
"name": "build-pass (local)",
9+
"res": "error",
10+
"runs": [
11+
{
12+
"log": "stable/local/build-pass",
13+
"res": 0
14+
},
15+
{
16+
"log": "beta/local/build-pass",
17+
"res": 0
18+
}
19+
],
20+
"url": "https://github.com/rust-lang/crater/tree/master/local-crates/build-pass"
21+
},
22+
{
23+
"name": "docs-rs-features (local)",
24+
"res": "error",
25+
"runs": [
26+
{
27+
"log": "stable/local/docs-rs-features",
28+
"res": 0
29+
},
30+
{
31+
"log": "beta/local/docs-rs-features",
32+
"res": 0
33+
}
34+
],
35+
"url": "https://github.com/rust-lang/crater/tree/master/local-crates/docs-rs-features"
36+
}
37+
]
38+
}
39+
]
40+
],
41+
"comparison_colors": {
42+
"error": {
43+
"Single": "#d77026"
44+
}
45+
},
46+
"crates_count": 2,
47+
"full": true,
48+
"info": {
49+
"error": 2
50+
},
51+
"nav": [
52+
{
53+
"active": false,
54+
"label": "Summary",
55+
"url": "index.html"
56+
},
57+
{
58+
"active": true,
59+
"label": "Full report",
60+
"url": "full.html"
61+
},
62+
{
63+
"active": false,
64+
"label": "Downloads",
65+
"url": "downloads.html"
66+
}
67+
],
68+
"result_colors": [
69+
{
70+
"Single": "#d77026"
71+
}
72+
],
73+
"result_names": [
74+
"error"
75+
]
76+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"categories": [
3+
[
4+
"error",
5+
{
6+
"Plain": [
7+
{
8+
"name": "build-pass (local)",
9+
"res": "error",
10+
"runs": [
11+
{
12+
"log": "stable/local/build-pass",
13+
"res": 0
14+
},
15+
{
16+
"log": "beta/local/build-pass",
17+
"res": 0
18+
}
19+
],
20+
"url": "https://github.com/rust-lang/crater/tree/master/local-crates/build-pass"
21+
},
22+
{
23+
"name": "docs-rs-features (local)",
24+
"res": "error",
25+
"runs": [
26+
{
27+
"log": "stable/local/docs-rs-features",
28+
"res": 0
29+
},
30+
{
31+
"log": "beta/local/docs-rs-features",
32+
"res": 0
33+
}
34+
],
35+
"url": "https://github.com/rust-lang/crater/tree/master/local-crates/docs-rs-features"
36+
}
37+
]
38+
}
39+
]
40+
],
41+
"comparison_colors": {
42+
"error": {
43+
"Single": "#d77026"
44+
}
45+
},
46+
"crates_count": 2,
47+
"full": false,
48+
"info": {
49+
"error": 2
50+
},
51+
"nav": [
52+
{
53+
"active": true,
54+
"label": "Summary",
55+
"url": "index.html"
56+
},
57+
{
58+
"active": false,
59+
"label": "Full report",
60+
"url": "full.html"
61+
},
62+
{
63+
"active": false,
64+
"label": "Downloads",
65+
"url": "downloads.html"
66+
}
67+
],
68+
"result_colors": [
69+
{
70+
"Single": "#d77026"
71+
}
72+
],
73+
"result_names": [
74+
"error"
75+
]
76+
}

0 commit comments

Comments
 (0)