From e40d2c289345efaec6181bcdfa44886b99e601fd Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Mon, 28 Oct 2024 22:36:15 -0700 Subject: [PATCH] cmm: Clean up Signed-off-by: Nick Spinale --- hacking/cargo-manifest-management/Makefile | 22 +++++----- .../src/main.rs | 40 +++++++++---------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/hacking/cargo-manifest-management/Makefile b/hacking/cargo-manifest-management/Makefile index 463ee1d64..316b55cb4 100644 --- a/hacking/cargo-manifest-management/Makefile +++ b/hacking/cargo-manifest-management/Makefile @@ -11,15 +11,15 @@ tools_manifest_path_arg := --manifest-path=tool/Cargo.toml run := cargo run \ $(tools_manifest_path_arg) -p manage-cargo-manifests -- -run_allow := cargo run \ +run_allowlist := cargo run \ $(tools_manifest_path_arg) -p manage-direct-dependency-allow-list -- project_manifest_path_arg := --manifest-path=../../Cargo.toml allowlist := direct-dependency-allow-list.toml -run_allow_check_workspace := $(run_allow) check-workspace --allowlist $(allowlist) $(project_manifest_path_arg) -run_allow_update := $(run_allow) update --allowlist $(allowlist) -o $(allowlist) +run_allowlist_check_workspace := $(run_allowlist) check-workspace --allowlist $(allowlist) $(project_manifest_path_arg) +run_allowlist_update := $(run_allowlist) update --allowlist $(allowlist) -o $(allowlist) .PHONY: none none: @@ -35,21 +35,19 @@ $(blueprint): .PHONY: update update: $(blueprint) $(run) --blueprint $< - $(run_allow_check_workspace) .PHONY: check check: $(blueprint) $(run) --blueprint $< --just-check - $(run_allow_check_workspace) .PHONY: check-workspace-direct-dependencies check-workspace-direct-dependencies: - $(run_allow_check_workspace) + $(run_allowlist_check_workspace) -.PHONY: update-workspace-direct-dependencies -update-workspace-direct-dependencies: - $(run_allow_update) +.PHONY: update-direct-dependency-allowlist +update-direct-dependency-allowlist: + $(run_allowlist_update) -.PHONY: dry-update-workspace-direct-dependencies -dry-update-workspace-direct-dependencies: - $(run_allow_update) --dry-run +.PHONY: check-direct-dependency-allow-list +check-direct-dependency-allow-list: + $(run_allowlist_update) --check diff --git a/hacking/cargo-manifest-management/tool/crates/manage-direct-dependency-allow-list/src/main.rs b/hacking/cargo-manifest-management/tool/crates/manage-direct-dependency-allow-list/src/main.rs index 8a37a1e08..a0fd90037 100644 --- a/hacking/cargo-manifest-management/tool/crates/manage-direct-dependency-allow-list/src/main.rs +++ b/hacking/cargo-manifest-management/tool/crates/manage-direct-dependency-allow-list/src/main.rs @@ -43,8 +43,8 @@ struct UpdateArgs { #[arg(short = 'o')] out: Option, - #[arg(long)] - dry_run: bool, + #[arg(long = "check")] + just_check: bool, } fn main() -> anyhow::Result<()> { @@ -70,7 +70,7 @@ fn main() -> anyhow::Result<()> { let mut view = AllowListUpdateView::new(&mut doc); let out_of_date = view.update(); if out_of_date { - if args.dry_run { + if args.just_check { bail!("out of date"); } else { let doc_str = doc.to_string(); @@ -98,25 +98,23 @@ impl AllowListCheckWorkspaceView { fn new(table: &Table) -> Self { let mut this = Self::default(); for (source_key, v) in table["allow"].as_table().unwrap().iter() { - match v { - Item::Value(Value::String(req_str)) => { - let req = VersionReq::parse(req_str.value()).unwrap(); - this.insert_version(source_key, req, source_key); - } - Item::Table(v) => { - let req = VersionReq::parse(v["version"].as_str().unwrap()).unwrap(); - for package_name in v["applies-to"] - .as_array() - .unwrap() - .iter() - .map(|v| v.as_str().unwrap()) - { - this.insert_version(package_name, req.clone(), source_key); - } - } - _ => { - panic!(); + if let Item::Value(Value::String(req_str)) = v { + let req = VersionReq::parse(req_str.value()).unwrap(); + this.insert_version(source_key, req, source_key); + } else if let Some(v) = v.as_table_like() { + let req = VersionReq::parse(v.get("version").unwrap().as_str().unwrap()).unwrap(); + for package_name in v + .get("applies-to") + .unwrap() + .as_array() + .unwrap() + .iter() + .map(|v| v.as_str().unwrap()) + { + this.insert_version(package_name, req.clone(), source_key); } + } else { + panic!() } } this