From 3afde3a972c47693a7049501def0a5e4de83e352 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:57:11 -0600 Subject: [PATCH 1/2] chore: format toml with taplo --- cliff.toml | 4 +--- registry.toml | 47 ++++++++++++++++++----------------------------- settings.toml | 16 ++++++++-------- 3 files changed, 27 insertions(+), 40 deletions(-) diff --git a/cliff.toml b/cliff.toml index 7d2ebb2314..694bbfdc65 100644 --- a/cliff.toml +++ b/cliff.toml @@ -66,9 +66,7 @@ footer = """ """ # remove the leading and trailing whitespace from the template trim = true -postprocessors = [ - { pattern = '\$REPO', replace = "https://github.com/jdx/mise" }, -] +postprocessors = [{ pattern = '\$REPO', replace = "https://github.com/jdx/mise" }] [git] # parse the commits based on https://www.conventionalcommits.org diff --git a/registry.toml b/registry.toml index bc0f39233d..c39f8aee97 100644 --- a/registry.toml +++ b/registry.toml @@ -13,9 +13,9 @@ aapt2.test = ["aapt2 version", "Android Asset Packaging Tool (aapt)"] act.backends = ["aqua:nektos/act", "ubi:nektos/act", "asdf:gr1m0h/asdf-act"] act.test = ["act --version", "act version {{version}}"] action-validator.backends = [ - "aqua:mpalmer/action-validator", - "ubi:mpalmer/action-validator", - "asdf:mpalmer/action-validator" + "aqua:mpalmer/action-validator", + "ubi:mpalmer/action-validator", + "asdf:mpalmer/action-validator", ] action-validator.os = ["linux", "macos"] action-validator.test = [ @@ -58,8 +58,8 @@ alp.test = ["alp --version", "{{version}}"] amass.backends = ["ubi:owasp-amass/amass", "asdf:dhoeric/asdf-amass"] amass.test = ["amass -version", "v{{version}}"] amazon-ecr-credential-helper.backends = [ - "aqua:awslabs/amazon-ecr-credential-helper", - "asdf:dex4er/asdf-amazon-ecr-credential-helper" + "aqua:awslabs/amazon-ecr-credential-helper", + "asdf:dex4er/asdf-amazon-ecr-credential-helper", ] # this isn't working with pipx yet since it is missing ansible # ansible-base.backends = ["pipx:ansible-base[with=ansible]", "asdf:amrox/asdf-pyapp"] @@ -106,8 +106,8 @@ aws-cli.test = ["aws --version", "aws-cli/{{version}}"] aws-cli.os = ["linux", "macos"] aws-copilot.backends = ["aqua:aws/copilot-cli", "asdf:NeoHsu/asdf-copilot"] aws-iam-authenticator.backends = [ - "aqua:kubernetes-sigs/aws-iam-authenticator", - "asdf:zekker6/asdf-aws-iam-authenticator" + "aqua:kubernetes-sigs/aws-iam-authenticator", + "asdf:zekker6/asdf-aws-iam-authenticator", ] aws-nuke.backends = ["aqua:rebuy-de/aws-nuke", "asdf:bersalazar/asdf-aws-nuke"] aws-sam.aliases = ["aws-sam-cli"] @@ -1225,24 +1225,13 @@ pre-commit.backends = [ pre-commit.description = "A framework for managing and maintaining multi-language pre-commit hooks" promtool.backends = ["asdf:asdf-community/asdf-promtool"] protobuf.backends = ["vfox:ahai-code/vfox-protobuf"] -protoc.backends = [ - "aqua:protocolbuffers/protobuf/protoc", - "asdf:paxosglobal/asdf-protoc" -] -protoc-gen-connect-go.backends = [ - "asdf:dylanrayboss/asdf-protoc-gen-connect-go" -] -protoc-gen-go.backends = [ - "aqua:protocolbuffers/protobuf-go/protoc-gen-go", - "asdf:pbr0ck3r/asdf-protoc-gen-go" -] -protoc-gen-go-grpc.backends = [ - "aqua:grpc/grpc-go/protoc-gen-go-grpc", - "asdf:pbr0ck3r/asdf-protoc-gen-go-grpc" -] +protoc.backends = ["aqua:protocolbuffers/protobuf/protoc", "asdf:paxosglobal/asdf-protoc"] +protoc-gen-connect-go.backends = ["asdf:dylanrayboss/asdf-protoc-gen-connect-go"] +protoc-gen-go.backends = ["aqua:protocolbuffers/protobuf-go/protoc-gen-go", "asdf:pbr0ck3r/asdf-protoc-gen-go"] +protoc-gen-go-grpc.backends = ["aqua:grpc/grpc-go/protoc-gen-go-grpc", "asdf:pbr0ck3r/asdf-protoc-gen-go-grpc"] protoc-gen-go-grpc.test = [ - "protoc-gen-go-grpc --version", - "protoc-gen-go-grpc" + "protoc-gen-go-grpc --version", + "protoc-gen-go-grpc", ] # TODO: use version_prefix and put version back in protoc-gen-grpc-web.backends = ["asdf:pbr0ck3r/asdf-protoc-gen-grpc-web"] protoc-gen-js.backends = ["asdf:pbr0ck3r/asdf-protoc-gen-js"] @@ -1294,9 +1283,9 @@ richgo.backends = ["aqua:kyoh86/richgo", "asdf:paxosglobal/asdf-richgo"] riff.backends = ["asdf:abinet/asdf-riff"] ripgrep.aliases = ["rg"] ripgrep.backends = [ - "aqua:BurntSushi/ripgrep", - "ubi:BurntSushi/ripgrep[exe=rg]", - "asdf:https://gitlab.com/wt0f/asdf-ripgrep" + "aqua:BurntSushi/ripgrep", + "ubi:BurntSushi/ripgrep[exe=rg]", + "asdf:https://gitlab.com/wt0f/asdf-ripgrep", ] ripgrep.test = ["rg --version", "ripgrep {{version}}"] ripgrep.description = "ripgrep recursively searches directories for a regex pattern while respecting your gitignore" @@ -1645,8 +1634,8 @@ yarn.backends = ["asdf:mise-plugins/asdf-yarn"] yay.backends = ["asdf:aaaaninja/asdf-yay"] yazi.backends = ["aqua:sxyazi/yazi"] yazi.test = [ - "yazi -V", - "" + "yazi -V", + "", ] # Version is in format Yazi {{version}} (buildid DATE) so it failed Yazi 0.4.1 (2275719 2024-12-10) yj.backends = ["ubi:sclevine/yj", "asdf:ryodocx/asdf-yj"] yor.backends = ["aqua:bridgecrewio/yor", "asdf:ordinaryexperts/asdf-yor"] diff --git a/settings.toml b/settings.toml index 3108d08f79..941148313f 100644 --- a/settings.toml +++ b/settings.toml @@ -946,14 +946,14 @@ rust_type = "crate::cli::run::TaskOutput" optional = true description = "Change output style when executing tasks." enum = [ - [ - "prefix", - "(default if jobs > 1) print by line with the prefix of the task name" - ], - [ - "interleave", - "(default if jobs == 1 or all tasks run sequentially) print output as it comes in" - ] + [ + "prefix", + "(default if jobs > 1) print by line with the prefix of the task name", + ], + [ + "interleave", + "(default if jobs == 1 or all tasks run sequentially) print output as it comes in", + ], ] docs = """ Change output style when executing tasks. This controls the output of `mise run`. From 927cdb7b0f607ebb764ec769658f4bf543402383 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:36:51 -0600 Subject: [PATCH 2/2] chore: add platform field to registry backends Fixes #3624 --- build.rs | 47 +++++++++++++++++++++---------- cliff.toml | 4 ++- docs/registry.md | 2 +- registry.toml | 57 +++++++++++++++++++++++++------------- settings.toml | 16 +++++------ src/backend/aqua.rs | 2 +- src/plugins/vfox_plugin.rs | 4 +-- src/registry.rs | 19 +++++++++++-- 8 files changed, 102 insertions(+), 49 deletions(-) diff --git a/build.rs b/build.rs index 2bea5bbd87..940aa50950 100644 --- a/build.rs +++ b/build.rs @@ -1,6 +1,5 @@ use heck::ToUpperCamelCase; use indexmap::IndexMap; -use std::collections::HashSet; use std::path::{Path, PathBuf}; use std::{env, fs}; @@ -29,7 +28,6 @@ fn codegen_registry() { .unwrap(); let tools = registry.get("tools").unwrap().as_table().unwrap(); - let mut trusted_ids = HashSet::new(); for (short, info) in tools { let info = info.as_table().unwrap(); let aliases = info @@ -48,20 +46,41 @@ fn codegen_registry() { t[1].as_str().unwrap().to_string(), ) }); - let backends = info.get("backends").unwrap().as_array().unwrap(); - let mut fulls = vec![]; - for backend in backends { + let mut backends = vec![]; + for backend in info.get("backends").unwrap().as_array().unwrap() { match backend { toml::Value::String(backend) => { - fulls.push(backend.to_string()); + backends.push(format!( + r##"RegistryBackend{{ + full: r#"{backend}"#, + platforms: &[], + }}"##, + backend = backend + )); } toml::Value::Table(backend) => { - fulls.push(backend.get("full").unwrap().as_str().unwrap().to_string()); - if let Some(trust) = backend.get("trust") { - if trust.as_bool().unwrap() { - trusted_ids.insert(short); - } - } + let full = backend.get("full").unwrap().as_str().unwrap(); + let platforms = backend + .get("platforms") + .map(|p| { + p.as_array() + .unwrap() + .iter() + .map(|p| p.as_str().unwrap().to_string()) + .collect::>() + }) + .unwrap_or_default(); + backends.push(format!( + r##"RegistryBackend{{ + full: r#"{full}"#, + platforms: &[{platforms}], + }}"##, + platforms = platforms + .into_iter() + .map(|p| format!("\"{p}\"")) + .collect::>() + .join(", ") + )); } _ => panic!("Unknown backend type"), } @@ -105,11 +124,11 @@ fn codegen_registry() { }) .unwrap_or_default(); let rt = format!( - r#"RegistryTool{{short: "{short}", description: {description}, backends: vec!["{backends}"], aliases: &[{aliases}], test: &{test}, os: &[{os}], depends: &[{depends}], idiomatic_files: &[{idiomatic_files}]}}"#, + r#"RegistryTool{{short: "{short}", description: {description}, backends: &[{backends}], aliases: &[{aliases}], test: &{test}, os: &[{os}], depends: &[{depends}], idiomatic_files: &[{idiomatic_files}]}}"#, description = description .map(|d| format!("Some(r###\"{}\"###)", d)) .unwrap_or("None".to_string()), - backends = fulls.join("\", \""), + backends = backends.into_iter().collect::>().join(", "), aliases = aliases .iter() .map(|a| format!("\"{a}\"")) diff --git a/cliff.toml b/cliff.toml index 694bbfdc65..7d2ebb2314 100644 --- a/cliff.toml +++ b/cliff.toml @@ -66,7 +66,9 @@ footer = """ """ # remove the leading and trailing whitespace from the template trim = true -postprocessors = [{ pattern = '\$REPO', replace = "https://github.com/jdx/mise" }] +postprocessors = [ + { pattern = '\$REPO', replace = "https://github.com/jdx/mise" }, +] [git] # parse the commits based on https://www.conventionalcommits.org diff --git a/docs/registry.md b/docs/registry.md index afe442cf8f..e403200df6 100644 --- a/docs/registry.md +++ b/docs/registry.md @@ -74,7 +74,7 @@ You can also specify the full name for a tool using `mise use aqua:1password/cli | balena | [ubi:balena-io/balena-cli](https://github.com/balena-io/balena-cli) [asdf:boatkit-io/asdf-balena-cli](https://github.com/boatkit-io/asdf-balena-cli) | | bashbot | [aqua:mathew-fleisch/bashbot](https://github.com/mathew-fleisch/bashbot) [asdf:mathew-fleisch/asdf-bashbot](https://github.com/mathew-fleisch/asdf-bashbot) | | bashly | [asdf:pcrockett/asdf-bashly](https://github.com/pcrockett/asdf-bashly) | -| bat | [ubi:sharkdp/bat](https://github.com/sharkdp/bat) [asdf:https://gitlab.com/wt0f/asdf-bat](https://gitlab.com/wt0f/asdf-bat) | +| bat | [ubi:sharkdp/bat](https://github.com/sharkdp/bat) [cargo:bat](https://crates.io/crates/bat) [asdf:https://gitlab.com/wt0f/asdf-bat](https://gitlab.com/wt0f/asdf-bat) | | bat-extras | [asdf:vhdirk/asdf-bat-extras](https://github.com/vhdirk/asdf-bat-extras) | | bats | [aqua:bats-core/bats-core](https://github.com/bats-core/bats-core) [asdf:timgluz/asdf-bats](https://github.com/timgluz/asdf-bats) | | bazel | [ubi:bazelbuild/bazel](https://github.com/bazelbuild/bazel) [asdf:rajatvig/asdf-bazel](https://github.com/rajatvig/asdf-bazel) | diff --git a/registry.toml b/registry.toml index c39f8aee97..cef7616738 100644 --- a/registry.toml +++ b/registry.toml @@ -13,9 +13,9 @@ aapt2.test = ["aapt2 version", "Android Asset Packaging Tool (aapt)"] act.backends = ["aqua:nektos/act", "ubi:nektos/act", "asdf:gr1m0h/asdf-act"] act.test = ["act --version", "act version {{version}}"] action-validator.backends = [ - "aqua:mpalmer/action-validator", - "ubi:mpalmer/action-validator", - "asdf:mpalmer/action-validator", + "aqua:mpalmer/action-validator", + "ubi:mpalmer/action-validator", + "asdf:mpalmer/action-validator" ] action-validator.os = ["linux", "macos"] action-validator.test = [ @@ -58,8 +58,8 @@ alp.test = ["alp --version", "{{version}}"] amass.backends = ["ubi:owasp-amass/amass", "asdf:dhoeric/asdf-amass"] amass.test = ["amass -version", "v{{version}}"] amazon-ecr-credential-helper.backends = [ - "aqua:awslabs/amazon-ecr-credential-helper", - "asdf:dex4er/asdf-amazon-ecr-credential-helper", + "aqua:awslabs/amazon-ecr-credential-helper", + "asdf:dex4er/asdf-amazon-ecr-credential-helper" ] # this isn't working with pipx yet since it is missing ansible # ansible-base.backends = ["pipx:ansible-base[with=ansible]", "asdf:amrox/asdf-pyapp"] @@ -106,8 +106,8 @@ aws-cli.test = ["aws --version", "aws-cli/{{version}}"] aws-cli.os = ["linux", "macos"] aws-copilot.backends = ["aqua:aws/copilot-cli", "asdf:NeoHsu/asdf-copilot"] aws-iam-authenticator.backends = [ - "aqua:kubernetes-sigs/aws-iam-authenticator", - "asdf:zekker6/asdf-aws-iam-authenticator", + "aqua:kubernetes-sigs/aws-iam-authenticator", + "asdf:zekker6/asdf-aws-iam-authenticator" ] aws-nuke.backends = ["aqua:rebuy-de/aws-nuke", "asdf:bersalazar/asdf-aws-nuke"] aws-sam.aliases = ["aws-sam-cli"] @@ -159,7 +159,15 @@ bashbot.backends = [ ] bashly.backends = ["asdf:pcrockett/asdf-bashly"] # aqua is available but uses cargo -bat.backends = ["ubi:sharkdp/bat", "asdf:https://gitlab.com/wt0f/asdf-bat"] +bat.backends = [ + {full = "ubi:sharkdp/bat", platforms = [ + "linux", + "macos", + "windows" + ]}, + "cargo:bat", + "asdf:https://gitlab.com/wt0f/asdf-bat" +] bat.test = ["bat --version", "bat {{version}}"] bat-extras.backends = ["asdf:vhdirk/asdf-bat-extras"] bats.backends = ["aqua:bats-core/bats-core", "asdf:timgluz/asdf-bats"] @@ -1225,13 +1233,24 @@ pre-commit.backends = [ pre-commit.description = "A framework for managing and maintaining multi-language pre-commit hooks" promtool.backends = ["asdf:asdf-community/asdf-promtool"] protobuf.backends = ["vfox:ahai-code/vfox-protobuf"] -protoc.backends = ["aqua:protocolbuffers/protobuf/protoc", "asdf:paxosglobal/asdf-protoc"] -protoc-gen-connect-go.backends = ["asdf:dylanrayboss/asdf-protoc-gen-connect-go"] -protoc-gen-go.backends = ["aqua:protocolbuffers/protobuf-go/protoc-gen-go", "asdf:pbr0ck3r/asdf-protoc-gen-go"] -protoc-gen-go-grpc.backends = ["aqua:grpc/grpc-go/protoc-gen-go-grpc", "asdf:pbr0ck3r/asdf-protoc-gen-go-grpc"] +protoc.backends = [ + "aqua:protocolbuffers/protobuf/protoc", + "asdf:paxosglobal/asdf-protoc" +] +protoc-gen-connect-go.backends = [ + "asdf:dylanrayboss/asdf-protoc-gen-connect-go" +] +protoc-gen-go.backends = [ + "aqua:protocolbuffers/protobuf-go/protoc-gen-go", + "asdf:pbr0ck3r/asdf-protoc-gen-go" +] +protoc-gen-go-grpc.backends = [ + "aqua:grpc/grpc-go/protoc-gen-go-grpc", + "asdf:pbr0ck3r/asdf-protoc-gen-go-grpc" +] protoc-gen-go-grpc.test = [ - "protoc-gen-go-grpc --version", - "protoc-gen-go-grpc", + "protoc-gen-go-grpc --version", + "protoc-gen-go-grpc" ] # TODO: use version_prefix and put version back in protoc-gen-grpc-web.backends = ["asdf:pbr0ck3r/asdf-protoc-gen-grpc-web"] protoc-gen-js.backends = ["asdf:pbr0ck3r/asdf-protoc-gen-js"] @@ -1283,9 +1302,9 @@ richgo.backends = ["aqua:kyoh86/richgo", "asdf:paxosglobal/asdf-richgo"] riff.backends = ["asdf:abinet/asdf-riff"] ripgrep.aliases = ["rg"] ripgrep.backends = [ - "aqua:BurntSushi/ripgrep", - "ubi:BurntSushi/ripgrep[exe=rg]", - "asdf:https://gitlab.com/wt0f/asdf-ripgrep", + "aqua:BurntSushi/ripgrep", + "ubi:BurntSushi/ripgrep[exe=rg]", + "asdf:https://gitlab.com/wt0f/asdf-ripgrep" ] ripgrep.test = ["rg --version", "ripgrep {{version}}"] ripgrep.description = "ripgrep recursively searches directories for a regex pattern while respecting your gitignore" @@ -1634,8 +1653,8 @@ yarn.backends = ["asdf:mise-plugins/asdf-yarn"] yay.backends = ["asdf:aaaaninja/asdf-yay"] yazi.backends = ["aqua:sxyazi/yazi"] yazi.test = [ - "yazi -V", - "", + "yazi -V", + "" ] # Version is in format Yazi {{version}} (buildid DATE) so it failed Yazi 0.4.1 (2275719 2024-12-10) yj.backends = ["ubi:sclevine/yj", "asdf:ryodocx/asdf-yj"] yor.backends = ["aqua:bridgecrewio/yor", "asdf:ordinaryexperts/asdf-yor"] diff --git a/settings.toml b/settings.toml index 941148313f..3108d08f79 100644 --- a/settings.toml +++ b/settings.toml @@ -946,14 +946,14 @@ rust_type = "crate::cli::run::TaskOutput" optional = true description = "Change output style when executing tasks." enum = [ - [ - "prefix", - "(default if jobs > 1) print by line with the prefix of the task name", - ], - [ - "interleave", - "(default if jobs == 1 or all tasks run sequentially) print output as it comes in", - ], + [ + "prefix", + "(default if jobs > 1) print by line with the prefix of the task name" + ], + [ + "interleave", + "(default if jobs == 1 or all tasks run sequentially) print output as it comes in" + ] ] docs = """ Change output style when executing tasks. This controls the output of `mise run`. diff --git a/src/backend/aqua.rs b/src/backend/aqua.rs index 5430a15a10..68c9952b4e 100644 --- a/src/backend/aqua.rs +++ b/src/backend/aqua.rs @@ -158,7 +158,7 @@ impl AquaBackend { if !id.contains("/") { id = REGISTRY .get(id) - .and_then(|t| t.backends.iter().find_map(|s| s.strip_prefix("aqua:"))) + .and_then(|t| t.backends.iter().find_map(|s| s.full.strip_prefix("aqua:"))) .unwrap_or_else(|| { warn!("invalid aqua tool: {}", id); id diff --git a/src/plugins/vfox_plugin.rs b/src/plugins/vfox_plugin.rs index 27692486bd..acf81b1ba4 100644 --- a/src/plugins/vfox_plugin.rs +++ b/src/plugins/vfox_plugin.rs @@ -227,8 +227,8 @@ fn vfox_to_url(name: &str) -> eyre::Result { let name = name.strip_prefix("vfox:").unwrap_or(name); if let Some(rt) = registry::REGISTRY.get(name.trim_start_matches("vfox-")) { // bun -> version-fox/vfox-bun - if let Some(full) = rt.backends.iter().find(|f| f.starts_with("vfox:")) { - return vfox_to_url(full.split_once(':').unwrap().1); + if let Some((_, tool_name)) = rt.backends.iter().find_map(|f| f.full.split_once("vfox:")) { + return vfox_to_url(tool_name); } } let res = if let Some(caps) = regex!(r#"^([^/]+)/([^/]+)$"#).captures(name) { diff --git a/src/registry.rs b/src/registry.rs index 88ab7c87d0..9e60517f5a 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -3,7 +3,7 @@ use crate::cli::args::BackendArg; use crate::config::SETTINGS; use once_cell::sync::Lazy; use std::collections::{BTreeMap, HashMap, HashSet}; -use std::env::consts::OS; +use std::env::consts::{ARCH, OS}; use std::fmt::Display; use std::iter::Iterator; use strum::IntoEnumIterator; @@ -17,7 +17,7 @@ pub static REGISTRY: Lazy> = pub struct RegistryTool { pub short: &'static str, pub description: Option<&'static str>, - pub backends: Vec<&'static str>, + pub backends: &'static [RegistryBackend], #[allow(unused)] pub aliases: &'static [&'static str], pub test: &'static Option<(&'static str, &'static str)>, @@ -26,6 +26,12 @@ pub struct RegistryTool { pub idiomatic_files: &'static [&'static str], } +#[derive(Debug, Clone)] +pub struct RegistryBackend { + pub full: &'static str, + pub platforms: &'static [&'static str], +} + impl RegistryTool { pub fn backends(&self) -> Vec<&'static str> { static BACKEND_TYPES: Lazy> = Lazy::new(|| { @@ -42,14 +48,21 @@ impl RegistryTool { } backend_types }); + let platform = format!("{OS}-{ARCH}"); self.backends .iter() + .filter(|rb| { + rb.platforms.is_empty() + || rb.platforms.contains(&OS) + || rb.platforms.contains(&ARCH) + || rb.platforms.contains(&&*platform) + }) + .map(|rb| rb.full) .filter(|full| { full.split(':') .next() .is_some_and(|b| BACKEND_TYPES.contains(b)) }) - .copied() .collect() }