Skip to content

Commit

Permalink
refactor: common roots
Browse files Browse the repository at this point in the history
  • Loading branch information
dnbln committed Feb 6, 2024
1 parent ab401b4 commit a4ed37a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 38 deletions.
26 changes: 26 additions & 0 deletions cargo-difftests/src/bin/cargo-difftests/cli_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,29 @@ impl AnalyzeAllActionArgs {
Ok(())
}
}

#[derive(Args, Debug, Clone)]
pub struct DifftestsRoot {
/// The root directory where all the difftests were stored.
///
/// Needs to be known to be able to properly remap the paths
/// to the index files, and is therefore only required if the
/// `--index-strategy` is `always`, `always-and-clean`, or
/// `if-available`.
#[clap(long)]
pub root: Option<PathBuf>,
}

#[derive(Args, Debug, Clone)]
pub struct DifftestsRootDir {
/// The root directory where all the difftests were stored.
///
/// Needs to be known to be able to properly remap the paths
/// to the index files, and is therefore only required if the
/// `--index-strategy` is `always`, `always-and-clean`, or
/// `if-available`.
///
/// (Also for discovery)
#[clap(long, default_value = "target/tmp/cargo-difftests")]
pub dir: PathBuf,
}
16 changes: 5 additions & 11 deletions cargo-difftests/src/bin/cargo-difftests/ops/analyze/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use clap::Parser;

use crate::{
cli_core::{
AlgoArgs, AnalysisIndex, DifftestDir, DirtyAlgorithm, ExportProfdataConfigFlags,
IgnoreRegistryFilesFlag,
AlgoArgs, AnalysisIndex, DifftestDir, DifftestsRoot, DirtyAlgorithm, ExportProfdataConfigFlags, IgnoreRegistryFilesFlag
},
CargoDifftestsResult,
};
Expand All @@ -29,14 +28,9 @@ pub struct AnalyzeCommand {
export_profdata_config_flags: ExportProfdataConfigFlags,
#[clap(flatten)]
analysis_index: AnalysisIndex,
/// The root directory where all the difftests were stored.
///
/// Needs to be known to be able to properly remap the paths
/// to the index files, and is therefore only required if the
/// `--index-strategy` is `always`, `always-and-clean`, or
/// `if-available`.
#[clap(long, default_value = "target/tmp/cargo-difftests")]
root: Option<PathBuf>,

#[clap(flatten)]
root: DifftestsRoot,

#[clap(flatten)]
ignore_registry_files: IgnoreRegistryFilesFlag,
Expand All @@ -51,7 +45,7 @@ impl AnalyzeCommand {
self.algo.algo,
self.algo.commit,
self.export_profdata_config_flags,
self.root,
self.root.root,
self.analysis_index,
self.ignore_registry_files,
)
Expand Down
14 changes: 5 additions & 9 deletions cargo-difftests/src/bin/cargo-difftests/ops/analyze_all/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use prodash::unit;

use crate::{
cli_core::{
AlgoArgs, AnalysisIndex, AnalyzeAllActionArgs, DirtyAlgorithm, ExportProfdataConfigFlags,
IgnoreRegistryFilesFlag,
AlgoArgs, AnalysisIndex, AnalyzeAllActionArgs, DifftestsRootDir, DirtyAlgorithm,
ExportProfdataConfigFlags, IgnoreRegistryFilesFlag,
},
CargoDifftestsResult,
};
Expand All @@ -16,12 +16,8 @@ use crate::ops::core::{analyze_single_test, discover_difftests};

#[derive(Parser, Debug)]
pub struct AnalyzeAllCommand {
/// The root directory where all the difftests were stored.
///
/// This should be some common ancestor directory of all
/// the paths passed to `cargo_difftests_testclient::init`.
#[clap(long, default_value = "target/tmp/cargo-difftests")]
dir: PathBuf,
#[clap(flatten)]
dir: DifftestsRootDir,
#[clap(flatten)]
ignore_registry_files: IgnoreRegistryFilesFlag,
/// Whether to force the generation of intermediary files.
Expand Down Expand Up @@ -51,7 +47,7 @@ impl AnalyzeAllCommand {
pub fn run(self, ctxt: &CargoDifftestsContext) -> CargoDifftestsResult {
run_analyze_all(
ctxt,
self.dir,
self.dir.dir,
self.force,
self.algo.algo,
self.algo.commit,
Expand Down
14 changes: 4 additions & 10 deletions cargo-difftests/src/bin/cargo-difftests/ops/analyze_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use cargo_difftests::bin_context::CargoDifftestsContext;
use clap::Parser;

use crate::{
cli_core::{AlgoArgs, AnalysisIndex, IgnoreRegistryFilesFlag, OtherBinaries},
cli_core::{AlgoArgs, AnalysisIndex, DifftestsRoot, IgnoreRegistryFilesFlag, OtherBinaries},
CargoDifftestsResult,
};

Expand All @@ -27,14 +27,8 @@ pub struct AnalyzeGroupCommand {
other_binaries: OtherBinaries,
#[clap(flatten)]
analysis_index: AnalysisIndex,
/// The root directory where all the difftests were stored.
///
/// Needs to be known to be able to properly remap the paths
/// to the index files, and is therefore only required if the
/// `--index-strategy` is `always`, `always-and-clean`, or
/// `if-available`.
#[clap(long, default_value = "target/tmp/cargo-difftests")]
root: Option<PathBuf>,
#[clap(flatten)]
root: DifftestsRoot,

#[clap(flatten)]
ignore_registry_files: IgnoreRegistryFilesFlag,
Expand All @@ -44,7 +38,7 @@ impl AnalyzeGroupCommand {
pub fn run(self, ctxt: &CargoDifftestsContext) -> CargoDifftestsResult {
run_analyze_group(
ctxt,
self.root,
self.root.root,
self.force,
self.algo,
self.other_binaries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ use std::path::PathBuf;
use cargo_difftests::bin_context::CargoDifftestsContext;
use clap::Parser;

use crate::{ops::core::discover_difftests, CargoDifftestsResult};
use crate::{cli_core::DifftestsRootDir, ops::core::discover_difftests, CargoDifftestsResult};

#[derive(Parser, Debug)]
pub struct DiscoverDifftestsCommand {
/// The root directory where all the difftests were stored.
///
/// This should be some common ancestor directory of all
/// the paths passed to `cargo_difftests_testclient::init`.
#[clap(long, default_value = "target/tmp/cargo-difftests")]
dir: PathBuf,
#[clap(flatten)]
root: DifftestsRootDir,
/// The directory where the index files were stored, if any.
#[clap(long)]
index_root: Option<PathBuf>,
Expand All @@ -23,12 +19,18 @@ pub struct DiscoverDifftestsCommand {
#[clap(long)]
ignore_incompatible: bool,
}

impl DiscoverDifftestsCommand {
pub fn run(
self,
ctxt: &cargo_difftests::bin_context::CargoDifftestsContext,
) -> CargoDifftestsResult {
run_discover_difftests(ctxt, self.dir, self.index_root, self.ignore_incompatible)
run_discover_difftests(
ctxt,
self.root.dir,
self.index_root,
self.ignore_incompatible,
)
}
}

Expand Down

0 comments on commit a4ed37a

Please sign in to comment.