Skip to content

Commit

Permalink
Auto merge of #2448 - alexcrichton:docs-dirty, r=brson
Browse files Browse the repository at this point in the history
Fix rerunning rustdoc when output deleted

If `crate/index.html` is missing, we need to rerun rustdoc!

Closes #2379
  • Loading branch information
bors committed Mar 10, 2016
2 parents 9b9e893 + 2c089cf commit d6e148d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/cargo/ops/cargo_rustc/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
/// Returns the appropriate output directory for the specified package and
/// target.
pub fn out_dir(&self, unit: &Unit) -> PathBuf {
self.layout(unit.pkg, unit.kind).out_dir(unit.pkg, unit.target)
if unit.profile.doc {
self.layout(unit.pkg, unit.kind).doc_root()
} else {
self.layout(unit.pkg, unit.kind).out_dir(unit.pkg, unit.target)
}
}

/// Return the (prefix, suffix) pair for dynamic libraries.
Expand Down
5 changes: 4 additions & 1 deletion src/cargo/ops/cargo_rustc/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ pub fn prepare_target<'a, 'cfg>(cx: &mut Context<'a, 'cfg>,

let root = cx.out_dir(unit);
let mut missing_outputs = false;
if !unit.profile.doc {
if unit.profile.doc {
missing_outputs = !root.join(unit.target.crate_name())
.join("index.html").exists();
} else {
for filename in try!(cx.target_filenames(unit)).iter() {
missing_outputs |= fs::metadata(root.join(filename)).is_err();
}
Expand Down
6 changes: 6 additions & 0 deletions src/cargo/ops/cargo_rustc/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,10 @@ impl<'a> LayoutProxy<'a> {
self.root().to_path_buf()
}
}

pub fn doc_root(&self) -> PathBuf {
// the "root" directory ends in 'debug' or 'release', and we want it to
// end in 'doc' instead
self.root.root().parent().unwrap().join("doc")
}
}
5 changes: 1 addition & 4 deletions src/cargo/ops/cargo_rustc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,7 @@ fn rustdoc(cx: &mut Context, unit: &Unit) -> CargoResult<Work> {
rustdoc.arg("--target").arg(target);
}

// the "root" directory ends in 'debug' or 'release', and we want it to end
// in 'doc' instead
let doc_dir = cx.layout(unit.pkg, unit.kind).proxy().root();
let doc_dir = doc_dir.parent().unwrap().join("doc");
let doc_dir = cx.out_dir(unit);

// Create the documentation directory ahead of time as rustdoc currently has
// a bug where concurrent invocations will race to create this directory if
Expand Down
24 changes: 24 additions & 0 deletions tests/test_cargo_doc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::str;
use std::fs;

use support::{project, execs, path2url};
use support::{COMPILING, DOCUMENTING, RUNNING};
Expand Down Expand Up @@ -525,3 +526,26 @@ test!(features {
assert_that(&p.root().join("target/doc/foo/fn.foo.html"), existing_file());
assert_that(&p.root().join("target/doc/bar/fn.bar.html"), existing_file());
});

test!(rerun_when_dir_removed {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
"#)
.file("src/lib.rs", r#"
/// dox
pub fn foo() {}
"#);
assert_that(p.cargo_process("doc"),
execs().with_status(0));
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());

fs::remove_dir_all(p.root().join("target/doc/foo")).unwrap();

assert_that(p.cargo_process("doc"),
execs().with_status(0));
assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
});

0 comments on commit d6e148d

Please sign in to comment.