Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Allow to only analyze the root crate #242

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
9 changes: 3 additions & 6 deletions cargo-geiger/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ OPTIONS:
--offline Run without accessing the network.
-Z \"<FLAG>...\" Unstable (nightly-only) flags to Cargo.
--include-tests Count unsafe usage in tests.
--build-dependencies Also analyze build dependencies.
--dev-dependencies Also analyze dev dependencies.
--no-dependencies Analyze no dependencies.
--all-dependencies Analyze all dependencies, including build and
dev.
--forbid-only Don't build or clean anything, only scan
Expand Down Expand Up @@ -105,8 +104,7 @@ impl Args {
color: raw_args.opt_value_from_str("--color")?,
deps_args: DepsArgs {
all_deps: raw_args.contains("--all-dependencies"),
build_deps: raw_args.contains("--build-dependencies"),
dev_deps: raw_args.contains("--dev-dependencies"),
no_deps: raw_args.contains("--no-dependencies"),
},
features_args: FeaturesArgs {
all_features: raw_args.contains("--all-features"),
Expand Down Expand Up @@ -209,8 +207,7 @@ impl Args {
#[derive(Debug, Default)]
pub struct DepsArgs {
pub all_deps: bool,
pub build_deps: bool,
pub dev_deps: bool,
pub no_deps: bool,
}

#[derive(Debug, Default)]
Expand Down
7 changes: 2 additions & 5 deletions cargo-geiger/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl fmt::Display for FormatError {

pub fn get_kind_group_name(dep_kind: DependencyKind) -> Option<&'static str> {
match dep_kind {
DependencyKind::Build => Some("[build-dependencies]"),
DependencyKind::Build => None,
DependencyKind::Development => Some("[dev-dependencies]"),
DependencyKind::Normal => None,
_ => panic!("Unrecognised Dependency Kind"),
Expand Down Expand Up @@ -115,10 +115,7 @@ mod format_tests {

#[rstest]
fn get_kind_group_name_test() {
assert_eq!(
get_kind_group_name(DependencyKind::Build),
Some("[build-dependencies]")
);
assert_eq!(get_kind_group_name(DependencyKind::Build), None);

assert_eq!(
get_kind_group_name(DependencyKind::Development),
Expand Down
5 changes: 1 addition & 4 deletions cargo-geiger/src/format/table/handle_text_tree_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,7 @@ mod handle_text_tree_line_tests {
#[rstest(
input_dep_kind,
expected_kind_group_name,
case(
DependencyKind::Build,
Some(String::from("[build-dependencies]"))
),
case(DependencyKind::Build, None),
case(
DependencyKind::Development,
Some(String::from("[dev-dependencies]"))
Expand Down
29 changes: 8 additions & 21 deletions cargo-geiger/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,10 @@ fn build_graph_prerequisites<'a>(
) -> (ExtraDeps, Option<&'a str>) {
let extra_deps = if deps_args.all_deps {
ExtraDeps::All
} else if deps_args.build_deps {
ExtraDeps::Build
} else if deps_args.dev_deps {
ExtraDeps::Dev
} else {
} else if deps_args.no_deps {
ExtraDeps::NoMore
} else {
ExtraDeps::Build
};

let target = if target_args.all_targets {
Expand Down Expand Up @@ -211,34 +209,23 @@ mod graph_tests {
case(
DepsArgs {
all_deps: true,
build_deps: false,
dev_deps: false
no_deps: false,
},
ExtraDeps::All
),
case(
DepsArgs {
all_deps: false,
build_deps: true,
dev_deps: false
no_deps: true,
},
ExtraDeps::Build
),
case(
DepsArgs {
all_deps: false,
build_deps: false,
dev_deps: true
},
ExtraDeps::Dev
ExtraDeps::NoMore
),
case(
DepsArgs {
all_deps: false,
build_deps: false,
dev_deps: false
no_deps: false,
},
ExtraDeps::NoMore
ExtraDeps::Build
)
)]
fn build_graph_prerequisites_extra_deps_test(
Expand Down
12 changes: 3 additions & 9 deletions cargo-geiger/src/graph/extra_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use cargo_metadata::DependencyKind;
pub enum ExtraDeps {
All,
Build,
Dev,
NoMore,
}

Expand All @@ -13,10 +12,10 @@ impl ExtraDeps {
#[allow(clippy::match_like_matches_macro)]
pub fn allows(&self, dependency_kind: DependencyKind) -> bool {
match (self, dependency_kind) {
(_, DependencyKind::Normal) => true,
(ExtraDeps::All, _) => true,
(ExtraDeps::NoMore, _) => false,
(_, DependencyKind::Normal) => true,
(ExtraDeps::Build, DependencyKind::Build) => true,
(ExtraDeps::Dev, DependencyKind::Development) => true,
_ => false,
}
}
Expand All @@ -33,14 +32,9 @@ mod extra_deps_tests {
expected_allows,
case(ExtraDeps::All, DependencyKind::Normal, true),
case(ExtraDeps::Build, DependencyKind::Normal, true),
case(ExtraDeps::Dev, DependencyKind::Normal, true),
case(ExtraDeps::NoMore, DependencyKind::Normal, true),
case(ExtraDeps::NoMore, DependencyKind::Normal, false),
case(ExtraDeps::All, DependencyKind::Build, true),
case(ExtraDeps::All, DependencyKind::Development, true),
case(ExtraDeps::Build, DependencyKind::Build, true),
case(ExtraDeps::Build, DependencyKind::Development, false),
case(ExtraDeps::Dev, DependencyKind::Build, false),
case(ExtraDeps::Dev, DependencyKind::Development, true)
)]
fn extra_deps_allows_test(
input_extra_deps: ExtraDeps,
Expand Down