Skip to content

Commit

Permalink
Merge branch 'main' into add_all_features_in_baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
tonowak committed Nov 9, 2022
2 parents d5e3c59 + 7bc59ab commit 69ba63a
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

# local-only data
localdata/

# Editor-local configuration
.vscode/
95 changes: 69 additions & 26 deletions src/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ pub struct RustDocCommand {
silence: bool,
}

// #[derive(Clone, Debug, PartialEq, Eq)]
// pub enum RustdocPackageSpec<'a> {
// Implicit,
// ExplicitInManifest(&'a str),
// ExplicitExternal(&'a str),
// }

// impl<'a> RustdocPackageSpec<'a> {
// fn as_explicit_spec(&self) -> Option<&'a str> {
// match self {
// RustdocPackageSpec::Implicit => None,
// RustdocPackageSpec::ExplicitInManifest(spec) => Some(*spec),
// RustdocPackageSpec::ExplicitExternal(spec) => Some(*spec),
// }
// }
// }

impl RustDocCommand {
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -34,6 +51,9 @@ impl RustDocCommand {
self
}

/// Produce a rustdoc JSON file for the specified configuration.
///
/// - If
pub fn dump(
&self,
manifest_path: &std::path::Path,
Expand Down Expand Up @@ -94,35 +114,58 @@ impl RustDocCommand {
}
}

let manifest = crate::manifest::Manifest::parse(manifest_path)?;
if let Some(pkg_spec) = pkg_spec {
// N.B.: This package spec is not necessarily part of the manifest at `manifest_path`!
// For example, when getting rustdoc JSON for a crate version from the registry,
// the manifest is "synthetic" with only a dependency on that crate and version
// and therefore is not a manifest *for* that crate itself.
let crate_name = pkg_spec
.split_once('@')
.map(|s| s.0)
.unwrap_or(pkg_spec)
.to_owned();

let json_path = target_dir.join(format!("doc/{}.json", crate_name));
if json_path.exists() {
Ok(json_path)
} else {
anyhow::bail!(
"Could not find expected rustdoc output for `{}`: {}",
crate_name,
json_path.display()
);
}
} else {
let manifest = crate::manifest::Manifest::parse(manifest_path)?;

let lib_target_name = crate::manifest::get_lib_target_name(&manifest)?;
let json_path = target_dir.join(format!("doc/{}.json", lib_target_name));
if json_path.exists() {
return Ok(json_path);
}
let lib_target_name = crate::manifest::get_lib_target_name(&manifest)?;
let json_path = target_dir.join(format!("doc/{}.json", lib_target_name));
if json_path.exists() {
return Ok(json_path);
}

let first_bin_target_name = crate::manifest::get_first_bin_target_name(&manifest)?;
let json_path = target_dir.join(format!("doc/{}.json", first_bin_target_name));
if !json_path.exists() {
let crate_name = if let Some(pkg_spec) = pkg_spec {
pkg_spec
.split_once('@')
.map(|s| s.0)
.unwrap_or(pkg_spec)
.to_owned()
} else {
crate::manifest::get_package_name(&manifest)?
};

anyhow::bail!(
"Could not find expected rustdoc output for `{}`: {}",
crate_name,
json_path.display()
);
}
let first_bin_target_name = crate::manifest::get_first_bin_target_name(&manifest)?;
let json_path = target_dir.join(format!("doc/{}.json", first_bin_target_name));
if !json_path.exists() {
let crate_name = if let Some(pkg_spec) = pkg_spec {
pkg_spec
.split_once('@')
.map(|s| s.0)
.unwrap_or(pkg_spec)
.to_owned()
} else {
crate::manifest::get_package_name(&manifest)?
};

Ok(json_path)
anyhow::bail!(
"Could not find expected rustdoc output for `{}`: {}",
crate_name,
json_path.display()
);
}

Ok(json_path)
}
}
}

Expand Down

0 comments on commit 69ba63a

Please sign in to comment.