Skip to content

Commit 2562146

Browse files
committed
Add a mode to 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' - Set RUSTC_BOOTSTRAP for doc runs This is required for both docs.rs features and the flags passed by docsrs_metadata to cargo. - Add instructions for running a single test to the readme
1 parent b55a557 commit 2562146

17 files changed

+415
-7
lines changed

Cargo.lock

Lines changed: 16 additions & 3 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 <[email protected]>"]
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/experiments.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ string_enum!(pub enum Mode {
3232
CheckOnly => "check-only",
3333
Clippy => "clippy",
3434
Rustdoc => "rustdoc",
35+
RustdocWithDocsrsMetadata => "rustdoc-with-docsrs-metadata",
3536
UnstableFeatures => "unstable-features",
3637
});
3738

src/runner/graph.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ pub(super) fn build_graph(ex: &Experiment, crates: &[Crate], config: &Config) ->
310310
},
311311
Mode::Rustdoc => TaskStep::Rustdoc {
312312
tc: tc.clone(),
313+
docsrs_metadata: false,
314+
quiet,
315+
},
316+
Mode::RustdocWithDocsrsMetadata => TaskStep::Rustdoc {
317+
tc: tc.clone(),
318+
docsrs_metadata: true,
313319
quiet,
314320
},
315321
Mode::UnstableFeatures => TaskStep::UnstableFeatures { tc: tc.clone() },

src/runner/tasks.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub(super) enum TaskStep {
5656
BuildOnly { tc: Toolchain, quiet: bool },
5757
CheckOnly { tc: Toolchain, quiet: bool },
5858
Clippy { tc: Toolchain, quiet: bool },
59-
Rustdoc { tc: Toolchain, quiet: bool },
59+
Rustdoc { tc: Toolchain, docsrs_metadata: bool, quiet: bool },
6060
UnstableFeatures { tc: Toolchain },
6161
}
6262

@@ -70,7 +70,8 @@ impl fmt::Debug for TaskStep {
7070
TaskStep::BuildOnly { ref tc, quiet } => ("build", quiet, Some(tc)),
7171
TaskStep::CheckOnly { ref tc, quiet } => ("check", quiet, Some(tc)),
7272
TaskStep::Clippy { ref tc, quiet } => ("clippy", quiet, Some(tc)),
73-
TaskStep::Rustdoc { ref tc, quiet } => ("doc", quiet, Some(tc)),
73+
TaskStep::Rustdoc { ref tc, docsrs_metadata: false, quiet } => ("doc", quiet, Some(tc)),
74+
TaskStep::Rustdoc { ref tc, docsrs_metadata: true, quiet } => ("doc+docs.rs-metadata", quiet, Some(tc)),
7475
TaskStep::UnstableFeatures { ref tc } => ("find unstable features on", false, Some(tc)),
7576
};
7677

@@ -184,9 +185,12 @@ impl Task {
184185
TaskStep::Clippy { ref tc, quiet } => {
185186
("linting", test::test_clippy_only, tc, quiet)
186187
}
187-
TaskStep::Rustdoc { ref tc, quiet } => {
188+
TaskStep::Rustdoc { ref tc, docsrs_metadata: false, quiet } => {
188189
("documenting", test::test_rustdoc, tc, quiet)
189190
}
191+
TaskStep::Rustdoc { ref tc, docsrs_metadata: true, quiet } => {
192+
("documenting with docs.rs metadata", test::test_rustdoc_with_metadata, tc, quiet)
193+
}
190194
TaskStep::UnstableFeatures { ref tc } => (
191195
"checking unstable",
192196
crate::runner::unstable_features::find_unstable_features,

src/runner/test.rs

Lines changed: 49 additions & 1 deletion
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 {
@@ -359,6 +369,7 @@ pub(super) fn test_rustdoc<DB: WriteResults>(
359369
],
360370
true,
361371
local_packages_id,
372+
HashMap::new(),
362373
);
363374

364375
// Make sure to remove the built documentation
@@ -371,3 +382,40 @@ pub(super) fn test_rustdoc<DB: WriteResults>(
371382
Ok(TestResult::TestPass)
372383
}
373384
}
385+
386+
pub(super) fn test_rustdoc_with_metadata<DB: WriteResults>(
387+
ctx: &TaskCtx<DB>,
388+
build_env: &Build,
389+
local_packages_id: &HashSet<PackageId>,
390+
) -> Fallible<TestResult> {
391+
let src = build_env.host_source_dir();
392+
let metadata = DocsrsMetadata::from_crate_root(src)?;
393+
let cargo_args = metadata.cargo_args(
394+
&[
395+
"--frozen".into(),
396+
"--no-deps".into(),
397+
"--document-private-items".into(),
398+
"--message-format=json".into(),
399+
],
400+
&[],
401+
);
402+
assert_eq!(cargo_args[0], "rustdoc");
403+
let cargo_args: Vec<_> = cargo_args.iter().map(|s| s.as_str()).collect();
404+
let mut env = metadata.environment_variables();
405+
// docsrs-metadata requires a nightly environment, but crater sometimes runs tests on beta and
406+
// stable.
407+
// TODO: only allow this for the crate currently being built?
408+
env.insert("RUSTC_BOOTSTRAP", "1".to_string());
409+
410+
let res = run_cargo(ctx, build_env, &cargo_args, true, local_packages_id, env);
411+
412+
// Make sure to remove the built documentation
413+
// There is no point in storing it after the build is done
414+
remove_dir_all(&build_env.host_target_dir().join("doc"))?;
415+
416+
if let Err(err) = res {
417+
Ok(TestResult::BuildFail(failure_reason(&err)))
418+
} else {
419+
Ok(TestResult::TestPass)
420+
}
421+
}

src/server/routes/ui/experiments.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ impl ExperimentData {
4444
Mode::CheckOnly => "cargo check",
4545
Mode::Clippy => "cargo clippy",
4646
Mode::Rustdoc => "cargo doc",
47+
Mode::RustdocWithDocsrsMetadata => "cargo doc (with docs.rs metadata)",
4748
Mode::UnstableFeatures => "unstable features",
4849
},
4950
assigned_to: experiment.assigned_to.as_ref().map(|a| a.to_string()),

tests/minicrater/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ The runs' output is hidden by default, but you can show it by setting the
2424
$ MINICRATER_SHOW_OUTPUT=1 cargo test minicrater -- --ignored --test-threads 1
2525
```
2626

27+
To run a single test, use `::`:
28+
```
29+
$ cargo test minicrater::single_thread_small -- --ignored
30+
```
31+
2732
## Adding tests to minicrater
2833

2934
There are two ways to add a test to minicrater:

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+
}

0 commit comments

Comments
 (0)