Skip to content

Commit

Permalink
cmm: Clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Oct 29, 2024
1 parent ae5da5a commit e40d2c2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
22 changes: 10 additions & 12 deletions hacking/cargo-manifest-management/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct UpdateArgs {
#[arg(short = 'o')]
out: Option<PathBuf>,

#[arg(long)]
dry_run: bool,
#[arg(long = "check")]
just_check: bool,
}

fn main() -> anyhow::Result<()> {
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e40d2c2

Please sign in to comment.