diff --git a/src/main.rs b/src/main.rs index 7e247a76..ef037b44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,16 +1,16 @@ #![forbid(unsafe_code)] -mod baseline; mod check_release; mod config; -mod dump; mod manifest; mod query; +mod rustdoc_cmd; +mod rustdoc_gen; mod templating; mod util; -use dump::RustDocCommand; use itertools::Itertools; +use rustdoc_cmd::RustdocCommand; use semver::Version; use std::path::{Path, PathBuf}; @@ -91,13 +91,13 @@ fn main() -> anyhow::Result<()> { Some(SemverChecksCommands::CheckRelease(args)) => { let mut config = GlobalConfig::new().set_level(args.verbosity.log_level()); - let loader: Box = + let loader: Box = if let Some(path) = args.baseline_rustdoc.as_deref() { - Box::new(baseline::RustdocBaseline::new(path.to_owned())) + Box::new(rustdoc_gen::RustdocBaseline::new(path.to_owned())) } else if let Some(root) = args.baseline_root.as_deref() { let metadata = args.manifest.metadata().no_deps().exec()?; let target = metadata.target_directory.as_std_path().join(util::SCOPE); - Box::new(baseline::PathBaseline::new(root, &target)?) + Box::new(rustdoc_gen::PathBaseline::new(root, &target)?) } else if let Some(rev) = args.baseline_rev.as_deref() { let metadata = args.manifest.metadata().no_deps().exec()?; let source = metadata.workspace_root.as_std_path(); @@ -107,7 +107,7 @@ fn main() -> anyhow::Result<()> { .as_std_path() .join(util::SCOPE) .join(format!("git-{slug}")); - Box::new(baseline::GitBaseline::with_rev( + Box::new(rustdoc_gen::GitBaseline::with_rev( source, &target, rev, @@ -116,14 +116,14 @@ fn main() -> anyhow::Result<()> { } else { let metadata = args.manifest.metadata().no_deps().exec()?; let target = metadata.target_directory.as_std_path().join(util::SCOPE); - let mut registry = baseline::RegistryBaseline::new(&target, &mut config)?; + let mut registry = rustdoc_gen::RegistryBaseline::new(&target, &mut config)?; if let Some(version) = args.baseline_version.as_deref() { let version = semver::Version::parse(version)?; registry.set_version(version); } Box::new(registry) }; - let rustdoc_cmd = dump::RustDocCommand::new() + let rustdoc_cmd = rustdoc_cmd::RustdocCommand::new() .deps(false) .silence(!config.is_verbose()); @@ -212,8 +212,8 @@ enum CurrentCratePath<'a> { fn generate_versioned_crates( config: &mut GlobalConfig, current_crate_path: CurrentCratePath, - loader: &dyn baseline::BaselineLoader, - rustdoc_cmd: &RustDocCommand, + loader: &dyn rustdoc_gen::BaselineLoader, + rustdoc_cmd: &RustdocCommand, crate_name: &str, version: Option<&Version>, ) -> anyhow::Result<(VersionedCrate, VersionedCrate)> { @@ -233,9 +233,9 @@ fn generate_versioned_crates( let baseline_path = loader.load_rustdoc( config, rustdoc_cmd, - baseline::CrateDataForRustdoc { + rustdoc_gen::CrateDataForRustdoc { name: crate_name, - crate_type: baseline::CrateType::Baseline { + crate_type: rustdoc_gen::CrateType::Baseline { highest_allowed_version: version, }, }, diff --git a/src/dump.rs b/src/rustdoc_cmd.rs similarity index 96% rename from src/dump.rs rename to src/rustdoc_cmd.rs index 67a6cbfd..a18776bd 100644 --- a/src/dump.rs +++ b/src/rustdoc_cmd.rs @@ -1,10 +1,10 @@ #[derive(Clone, Debug, PartialEq, Eq)] -pub struct RustDocCommand { +pub struct RustdocCommand { deps: bool, silence: bool, } -impl RustDocCommand { +impl RustdocCommand { pub fn new() -> Self { Self { deps: false, @@ -152,7 +152,7 @@ impl RustDocCommand { } } -impl Default for RustDocCommand { +impl Default for RustdocCommand { fn default() -> Self { Self::new() } @@ -162,11 +162,11 @@ impl Default for RustDocCommand { mod tests { use std::path::Path; - use super::RustDocCommand; + use super::RustdocCommand; #[test] fn rustdoc_for_lib_crate_without_lib_section() { - RustDocCommand::default() + RustdocCommand::default() .dump( Path::new("./test_rustdoc/implicit_lib/Cargo.toml"), None, @@ -177,7 +177,7 @@ mod tests { #[test] fn rustdoc_for_lib_crate_with_lib_section() { - RustDocCommand::default() + RustdocCommand::default() .dump( Path::new("./test_rustdoc/renamed_lib/Cargo.toml"), None, @@ -188,7 +188,7 @@ mod tests { #[test] fn rustdoc_for_bin_crate_without_bin_section() { - RustDocCommand::default() + RustdocCommand::default() .dump( Path::new("./test_rustdoc/implicit_bin/Cargo.toml"), None, @@ -199,7 +199,7 @@ mod tests { #[test] fn rustdoc_for_bin_crate_with_bin_section() { - RustDocCommand::default() + RustdocCommand::default() .dump( Path::new("./test_rustdoc/renamed_bin/Cargo.toml"), None, diff --git a/src/baseline.rs b/src/rustdoc_gen.rs similarity index 97% rename from src/baseline.rs rename to src/rustdoc_gen.rs index 4f5e21c1..7f34a592 100644 --- a/src/baseline.rs +++ b/src/rustdoc_gen.rs @@ -3,8 +3,8 @@ use std::path::{Path, PathBuf}; use anyhow::Context as _; use crates_index::Crate; -use crate::dump::RustDocCommand; use crate::manifest::Manifest; +use crate::rustdoc_cmd::RustdocCommand; use crate::util::slugify; use crate::GlobalConfig; @@ -177,7 +177,7 @@ fn save_placeholder_rustdoc_manifest( } #[allow(dead_code)] -#[derive(Debug)] +#[derive(Debug, Clone)] pub(crate) enum CrateType<'a> { Current, Baseline { @@ -188,26 +188,25 @@ pub(crate) enum CrateType<'a> { }, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub(crate) struct CrateDataForRustdoc<'a> { pub(crate) crate_type: CrateType<'a>, pub(crate) name: &'a str, // TODO: pass an enum describing which features to enable } -impl<'a> ToString for CrateType<'a> { - fn to_string(&self) -> String { +impl<'a> CrateType<'a> { + fn type_name(&self) -> &'static str { match self { CrateType::Current => "current", CrateType::Baseline { .. } => "baseline", } - .to_string() } } fn generate_rustdoc( config: &mut GlobalConfig, - rustdoc: &RustDocCommand, + rustdoc: &RustdocCommand, target_root: PathBuf, crate_source: CrateSource, crate_data: CrateDataForRustdoc, @@ -240,7 +239,7 @@ fn generate_rustdoc( "Parsing", format_args!( "{name} v{version} ({}, cached)", - crate_data.crate_type.to_string() + crate_data.crate_type.type_name() ), )?; return Ok(cached_rustdoc); @@ -259,8 +258,10 @@ fn generate_rustdoc( config.shell_status( "Parsing", - format_args!("{name} v{version} ({})", crate_data.crate_type.to_string()), + format_args!("{name} v{version} ({})", crate_data.crate_type.type_name()), )?; + // TODO: replace "baseline" with a string passed as a function argument + // (the plan is to make this function work for both baseline and current). let rustdoc_path = rustdoc.dump( placeholder_manifest_path.as_path(), @@ -295,7 +296,7 @@ pub(crate) trait BaselineLoader { fn load_rustdoc( &self, config: &mut GlobalConfig, - rustdoc: &RustDocCommand, + rustdoc: &RustdocCommand, crate_data: CrateDataForRustdoc, ) -> anyhow::Result; } @@ -314,7 +315,7 @@ impl BaselineLoader for RustdocBaseline { fn load_rustdoc( &self, _config: &mut GlobalConfig, - _rustdoc: &RustDocCommand, + _rustdoc: &RustdocCommand, _crate_data: CrateDataForRustdoc, ) -> anyhow::Result { Ok(self.path.clone()) @@ -358,7 +359,7 @@ impl BaselineLoader for PathBaseline { fn load_rustdoc( &self, config: &mut GlobalConfig, - rustdoc: &RustDocCommand, + rustdoc: &RustdocCommand, crate_data: CrateDataForRustdoc, ) -> anyhow::Result { let manifest: &Manifest = self.lookup.get(crate_data.name).with_context(|| { @@ -442,7 +443,7 @@ impl BaselineLoader for GitBaseline { fn load_rustdoc( &self, config: &mut GlobalConfig, - rustdoc: &RustDocCommand, + rustdoc: &RustdocCommand, crate_data: CrateDataForRustdoc, ) -> anyhow::Result { self.path.load_rustdoc(config, rustdoc, crate_data) @@ -543,7 +544,7 @@ impl BaselineLoader for RegistryBaseline { fn load_rustdoc( &self, config: &mut GlobalConfig, - rustdoc: &RustDocCommand, + rustdoc: &RustdocCommand, crate_data: CrateDataForRustdoc, ) -> anyhow::Result { let crate_ = self