Skip to content

Commit

Permalink
Work around rustdoc bugs for proc-macros
Browse files Browse the repository at this point in the history
Use documentation in /target/doc if /target/$target/doc doesn't exist.

Partially addresses rust-lang#422.

Note: this does _not_ fix the issue mentioned above, it doesn't link
to the right CSS files. See
https://cdn.discordapp.com/attachments/541978667522195476/649031211913838592/unknown.png
for an example.
  • Loading branch information
jyn514 committed Nov 27, 2019
1 parent a6e6aa9 commit d1043c9
Showing 1 changed file with 50 additions and 37 deletions.
87 changes: 50 additions & 37 deletions src/docbuilder/rustwide_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl RustwideBuilder {
.build(&self.toolchain, &krate, sandbox)
.run(|build| {
let mut files_list = None;
let mut has_docs = false;
let (mut has_docs, mut in_target) = (false, false);
let mut successful_targets = Vec::new();

// Do an initial build and then copy the sources in the database
Expand All @@ -281,54 +281,43 @@ impl RustwideBuilder {
build.host_source_dir(),
)?);

has_docs = res
.cargo_metadata
.root()
.library_name()
.map(|name| {
build
.host_target_dir()
.join(&res.target)
.join("doc")
.join(name)
.is_dir()
})
.unwrap_or(false);
if let Some(name) = res
.cargo_metadata
.root()
.library_name() {
let host_target = build.host_target_dir();
if host_target.join(&res.target)
.join("doc")
.join(&name)
.is_dir() {
has_docs = true;
in_target = true;
// hack for proc-macro documentation:
// it really should be in target/$target/doc,
// but rustdoc has a bug and puts it in target/doc
} else if host_target.join("doc").join(name).is_dir() {
has_docs = true;
}
}
}

if has_docs {
debug!("adding documentation for the default target to the database");
self.copy_docs(
&build.host_target_dir(),
local_storage.path(),
&res.target,
if in_target { &res.target } else { "" },
true,
)?;
successful_targets.push(DEFAULT_TARGET.to_string());

// Then build the documentation for all the targets
for target in TARGETS {
debug!("building package {} {} for {}", name, version, target);
let target_res = self.execute_build(Some(target), &build, &limits)?;
if target_res.successful {
// Cargo is not giving any error and not generating documentation of some crates
// when we use a target compile options. Check documentation exists before
// adding target to successfully_targets.
if build.host_target_dir().join(target).join("doc").is_dir() {
debug!(
"adding documentation for target {} to the database",
target
);
self.copy_docs(
&build.host_target_dir(),
local_storage.path(),
target,
false,
)?;
successful_targets.push(target.to_string());
}
if in_target {
// Then build the documentation for all the targets
for target in TARGETS {
debug!("building package {} {} for {}", name, version, target);
self.build_target(target, &build, &limits, &local_storage.path(), &mut successful_targets)?;
}
}

self.upload_docs(&conn, name, version, local_storage.path())?;
}

Expand Down Expand Up @@ -362,6 +351,30 @@ impl RustwideBuilder {
Ok(res.successful)
}

fn build_target(&self, target: &str, build: &Build, limits: &Limits,
local_storage: &Path, successful_targets: &mut Vec<String>) -> Result<()> {
let target_res = self.execute_build(Some(target), build, limits)?;
if target_res.successful {
// Cargo is not giving any error and not generating documentation of some crates
// when we use a target compile options. Check documentation exists before
// adding target to successfully_targets.
if build.host_target_dir().join(target).join("doc").is_dir() {
debug!(
"adding documentation for target {} to the database",
target,
);
self.copy_docs(
&build.host_target_dir(),
local_storage,
target,
false,
)?;
successful_targets.push(target.to_string());
}
}
Ok(())
}

fn execute_build(
&self,
target: Option<&str>,
Expand Down

0 comments on commit d1043c9

Please sign in to comment.