Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print the full path to the generated documentation #5592

Closed
wants to merge 4 commits into from
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
30 changes: 19 additions & 11 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::fs;
use std::iter::FromIterator;
use std::path::Path;
use std::process::Command;

Expand Down Expand Up @@ -65,6 +66,23 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
}
}

// Don't bother locking here as if this is getting deleted there's
// nothing we can do about it and otherwise if it's getting overwritten
// then that's also ok!
let mut target_dir = ws.clone().target_dir().clone();
if let Some(ref triple) = options.compile_opts.build_config.requested_target {
target_dir.push(Path::new(triple).file_stem().unwrap());
}

let unit_names = Vec::from_iter(lib_names.keys().chain(bin_names.keys()));
for unit_name in &unit_names {
let path = target_dir.join("doc").join(&unit_name).join("index.html");
// Duplicating shell here and not declaring it outside the loop to avoid
// a BorrowMutError
let mut shell = options.compile_opts.config.shell();
shell.status("Generating", path.display())?;
}

ops::compile(ws, &options.compile_opts)?;

if options.open_result {
Expand All @@ -79,19 +97,9 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
.join("\n ")
);
} else {
match lib_names.keys().chain(bin_names.keys()).nth(0) {
Some(s) => s.to_string(),
None => return Ok(()),
}
unit_names[0].to_string()
};

// Don't bother locking here as if this is getting deleted there's
// nothing we can do about it and otherwise if it's getting overwritten
// then that's also ok!
let mut target_dir = ws.target_dir();
if let Some(ref triple) = options.compile_opts.build_config.requested_target {
target_dir.push(Path::new(triple).file_stem().unwrap());
}
let path = target_dir.join("doc").join(&name).join("index.html");
let path = path.into_path_unlocked();
if fs::metadata(&path).is_ok() {
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/cargotest/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@ fn substitute_macros(input: &str) -> String {
("[REPLACING]", " Replacing"),
("[UNPACKING]", " Unpacking"),
("[SUMMARY]", " Summary"),
("[GENERATING]", " Generating"),
("[EXE]", if cfg!(windows) { ".exe" } else { "" }),
("[/]", if cfg!(windows) { "\\" } else { "/" }),
];
Expand Down
14 changes: 14 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn simple() {
p.cargo("doc"),
execs().with_status(0).with_stderr(&format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[..] foo v0.0.1 ({dir})
[..] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -98,6 +99,7 @@ fn doc_twice() {
p.cargo("doc"),
execs().with_status(0).with_stderr(&format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[DOCUMENTING] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
Expand Down Expand Up @@ -151,6 +153,7 @@ fn doc_deps() {
p.cargo("doc"),
execs().with_status(0).with_stderr(&format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[..] bar v0.0.1 ({dir}/bar)
[..] bar v0.0.1 ({dir}/bar)
[DOCUMENTING] foo v0.0.1 ({dir})
Expand Down Expand Up @@ -232,6 +235,7 @@ fn doc_no_deps() {
p.cargo("doc").arg("--no-deps"),
execs().with_status(0).with_stderr(&format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[CHECKING] bar v0.0.1 ({dir}/bar)
[DOCUMENTING] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -505,6 +509,8 @@ fn doc_lib_bin_same_name_documents_lib() {
p.cargo("doc"),
execs().with_status(0).with_stderr(&format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[DOCUMENTING] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
Expand Down Expand Up @@ -558,6 +564,8 @@ fn doc_lib_bin_same_name_documents_lib_when_requested() {
p.cargo("doc").arg("--lib"),
execs().with_status(0).with_stderr(&format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[DOCUMENTING] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
Expand Down Expand Up @@ -611,6 +619,8 @@ fn doc_lib_bin_same_name_documents_named_bin_when_requested() {
p.cargo("doc").arg("--bin").arg("foo"),
execs().with_status(0).with_stderr(&format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[CHECKING] foo v0.0.1 ({dir})
[DOCUMENTING] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -665,6 +675,8 @@ fn doc_lib_bin_same_name_documents_bins_when_requested() {
p.cargo("doc").arg("--bins"),
execs().with_status(0).with_stderr(&format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[CHECKING] foo v0.0.1 ({dir})
[DOCUMENTING] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
Expand Down Expand Up @@ -729,6 +741,7 @@ fn doc_dash_p() {
p.cargo("doc").arg("-p").arg("a"),
execs().with_status(0).with_stderr(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]a[/]index.html
[..] b v0.0.1 (file://[..])
[..] b v0.0.1 (file://[..])
[DOCUMENTING] a v0.0.1 (file://[..])
Expand Down Expand Up @@ -1001,6 +1014,7 @@ fn doc_release() {
p.cargo("doc").arg("--release").arg("-v"),
execs().with_status(0).with_stderr(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[DOCUMENTING] foo v0.0.1 ([..])
[RUNNING] `rustdoc [..] src[/]lib.rs [..]`
[FINISHED] release [optimized] target(s) in [..]
Expand Down
2 changes: 2 additions & 0 deletions tests/testsuite/profile_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,8 @@ fn profile_selection_doc() {
//
// `*` = wants panic, but it is cleared when args are built.
assert_that(p.cargo("doc -vv"), execs().with_status(0).with_stderr_unordered("\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[COMPILING] bar [..]
[DOCUMENTING] bar [..]
[RUNNING] `rustc --crate-name bar bar[/]src[/]lib.rs --crate-type lib --emit=dep-info,link -C codegen-units=1 -C debuginfo=2 [..]
Expand Down
7 changes: 7 additions & 0 deletions tests/testsuite/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn rustdoc_simple() {
p.cargo("rustdoc").arg("-v"),
execs().with_status(0).with_stderr(format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[DOCUMENTING] foo v0.0.1 ({url})
[RUNNING] `rustdoc --crate-name foo src[/]lib.rs \
-o {dir}[/]target[/]doc \
Expand Down Expand Up @@ -51,6 +52,7 @@ fn rustdoc_args() {
p.cargo("rustdoc").arg("-v").arg("--").arg("--cfg=foo"),
execs().with_status(0).with_stderr(format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[DOCUMENTING] foo v0.0.1 ({url})
[RUNNING] `rustdoc --crate-name foo src[/]lib.rs \
-o {dir}[/]target[/]doc \
Expand Down Expand Up @@ -109,6 +111,7 @@ fn rustdoc_foo_with_bar_dependency() {
foo.cargo("rustdoc").arg("-v").arg("--").arg("--cfg=foo"),
execs().with_status(0).with_stderr(format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[CHECKING] bar v0.0.1 ([..])
[RUNNING] `rustc [..]bar[/]src[/]lib.rs [..]`
[DOCUMENTING] foo v0.0.1 ({url})
Expand Down Expand Up @@ -177,6 +180,7 @@ fn rustdoc_only_bar_dependency() {
.arg("--cfg=foo"),
execs().with_status(0).with_stderr(format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]bar[/]index.html
[DOCUMENTING] bar v0.0.1 ([..])
[RUNNING] `rustdoc --crate-name bar [..]bar[/]src[/]lib.rs \
-o {dir}[/]target[/]doc \
Expand Down Expand Up @@ -214,6 +218,8 @@ fn rustdoc_same_name_documents_lib() {
p.cargo("rustdoc").arg("-v").arg("--").arg("--cfg=foo"),
execs().with_status(0).with_stderr(format!(
"\
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[DOCUMENTING] foo v0.0.1 ([..])
[RUNNING] `rustdoc --crate-name foo src[/]lib.rs \
-o {dir}[/]target[/]doc \
Expand Down Expand Up @@ -271,6 +277,7 @@ fn rustdoc_target() {
assert_that(
p.cargo("rustdoc --verbose --target x86_64-unknown-linux-gnu"),
execs().with_status(0).with_stderr("\
[GENERATING] [..][/]foo[/]target[/][..][/]doc[/]a[/]index.html
[DOCUMENTING] a v0.0.1 ([..])
[RUNNING] `rustdoc --crate-name a src[/]lib.rs \
--target x86_64-unknown-linux-gnu \
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/rustdocflags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ fn rerun() {
execs().with_status(0).with_stderr(
"\
[DOCUMENTING] foo v0.0.1 ([..])
[GENERATING] [..][/]foo[/]target[/]doc[/]foo[/]index.html
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
),
Expand Down