Skip to content
New issue

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

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

Already on GitHub? # to your account

Renamed baseline.rs and dump.rs files #348

Merged
merged 7 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
45 changes: 27 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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<dyn baseline::BaselineLoader> =
let loader: Box<dyn rustdoc_gen::BaselineLoader> =
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();
Expand All @@ -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,
Expand All @@ -116,29 +116,29 @@ 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());

let all_outcomes: Vec<anyhow::Result<bool>> = if let Some(current_rustdoc_path) =
args.current_rustdoc.as_deref()
{
let name = "<unknown>";
let version = None;
let baseline_highest_allowed_version = None;
let (current_crate, baseline_crate) = generate_versioned_crates(
&mut config,
CurrentCratePath::CurrentRustdocPath(current_rustdoc_path),
&*loader,
&rustdoc_cmd,
name,
version,
baseline_highest_allowed_version,
)?;

let success = run_check_release(&mut config, name, current_crate, baseline_crate)?;
Expand All @@ -151,21 +151,21 @@ fn main() -> anyhow::Result<()> {
.map(|selected| {
let manifest_path = selected.manifest_path.as_std_path();
let crate_name = &selected.name;
let version = &selected.version;
let current_version = &selected.version;

let is_implied = args.workspace.all || args.workspace.workspace;
if is_implied && selected.publish == Some(vec![]) {
config.verbose(|config| {
config.shell_status(
"Skipping",
format_args!("{crate_name} v{version} (current)"),
format_args!("{crate_name} v{current_version} (current)"),
)
})?;
Ok(true)
} else {
config.shell_status(
"Parsing",
format_args!("{crate_name} v{version} (current)"),
format_args!("{crate_name} v{current_version} (current)"),
)?;

let (current_crate, baseline_crate) = generate_versioned_crates(
Expand All @@ -174,7 +174,7 @@ fn main() -> anyhow::Result<()> {
&*loader,
&rustdoc_cmd,
crate_name,
Some(version),
Some(current_version),
)?;

Ok(run_check_release(
Expand Down Expand Up @@ -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)> {
Expand All @@ -230,7 +230,16 @@ fn generate_versioned_crates(
// For example, this happens when target-dir is specified in `.cargo/config.toml`.
// That's the reason why we're immediately loading the rustdocs into memory.
// See: https://github.com/obi1kenobi/cargo-semver-checks/issues/269
let baseline_path = loader.load_rustdoc(config, rustdoc_cmd, crate_name, version)?;
let baseline_path = loader.load_rustdoc(
config,
rustdoc_cmd,
rustdoc_gen::CrateDataForRustdoc {
name: crate_name,
crate_type: rustdoc_gen::CrateType::Baseline {
highest_allowed_version: version,
},
},
)?;
let baseline_crate = load_rustdoc(&baseline_path)?;

Ok((current_crate, baseline_crate))
Expand Down
16 changes: 8 additions & 8 deletions src/dump.rs → src/rustdoc_cmd.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -152,7 +152,7 @@ impl RustDocCommand {
}
}

impl Default for RustDocCommand {
impl Default for RustdocCommand {
fn default() -> Self {
Self::new()
}
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Loading