Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,31 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
) -> CargoResult<Arc<Vec<OutputFile>>> {
let ret = match unit.mode {
CompileMode::Doc { .. } => {
let path = self
.out_dir(unit)
.join(unit.target.crate_name())
.join("index.html");
let json_output = if let Some(extra_rustdoc_args) = bcx.extra_args_for(unit) {
extra_rustdoc_args
.iter()
.find(|arg| {
*arg == "--output-format=json"
|| *arg == "-wjson"
|| *arg == "-w json"
|| *arg == "--output-format json"
})
.is_some()
} else {
false
};
// If the output format is JSON, then rustdoc will output
// a <crate name>.json file rather than the usual index.html
// We compute its expected path here in order to track it as
// the correct output file.
let path = if json_output {
self.out_dir(unit)
.join(format!("{}.json", unit.target.crate_name()))
} else {
self.out_dir(unit)
.join(unit.target.crate_name())
.join("index.html")
};
vec![OutputFile {
path,
hardlink: None,
Expand Down
68 changes: 68 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,74 @@ fn doc_json_artifacts() {
.run();
}

#[cargo_test(nightly, reason = "rustdoc-json")]
fn doc_json_artifacts_are_cached_correctly() {
let p = project().file("src/lib.rs", "").build();

// The first run should emit the unit as dirty ("fresh": false), while showing
// the correct output filenames.
p.cargo("rustdoc --lib --message-format=json -- -Zunstable-options --output-format=json")
.with_json_contains_unordered(
r#"
{
"reason": "compiler-artifact",
"package_id": "foo 0.0.1 [..]",
"manifest_path": "[ROOT]/foo/Cargo.toml",
"target":
{
"kind": ["lib"],
"crate_types": ["lib"],
"name": "foo",
"src_path": "[ROOT]/foo/src/lib.rs",
"edition": "2015",
"doc": true,
"doctest": true,
"test": true
},
"profile": "{...}",
"features": [],
"filenames": ["[ROOT]/foo/target/doc/foo.json"],
"executable": null,
"fresh": false
}

{"reason":"build-finished","success":true}
"#,
)
.run();

// We then run it again and check that the unit is now marked as fresh.
p.cargo("rustdoc --lib --message-format=json -- -Zunstable-options --output-format=json")
.with_json_contains_unordered(
r#"
{
"reason": "compiler-artifact",
"package_id": "foo 0.0.1 [..]",
"manifest_path": "[ROOT]/foo/Cargo.toml",
"target":
{
"kind": ["lib"],
"crate_types": ["lib"],
"name": "foo",
"src_path": "[ROOT]/foo/src/lib.rs",
"edition": "2015",
"doc": true,
"doctest": true,
"test": true
},
"profile": "{...}",
"features": [],
"filenames": ["[ROOT]/foo/target/doc/foo.json"],
"executable": null,
"fresh": true
}

{"reason":"build-finished","success":true}
"#,
)
.run();
}

#[cargo_test]
fn short_message_format() {
let p = project().file("src/lib.rs", BAD_INTRA_LINK_LIB).build();
Expand Down