diff --git a/Cargo.lock b/Cargo.lock index 7b369ef7b..af07db962 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -139,6 +139,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "anyhow" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" + [[package]] name = "arbitrary" version = "1.3.2" @@ -222,6 +228,17 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "binstall-tar" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3620d72763b5d8df3384f3b2ec47dc5885441c2abbd94dd32197167d08b014a" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "bit-set" version = "0.6.0" @@ -832,6 +849,15 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "document-features" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb6969eaabd2421f8a2775cfd2471a2b634372b4a25d41e3bd647b79912850a0" +dependencies = [ + "litrs", +] + [[package]] name = "dotenvy" version = "0.15.7" @@ -1707,6 +1733,29 @@ dependencies = [ "thiserror", ] +[[package]] +name = "lazy-regex" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d8e41c97e6bc7ecb552016274b99fbb5d035e8de288c582d9b933af6677bfda" +dependencies = [ + "lazy-regex-proc_macros", + "once_cell", + "regex", +] + +[[package]] +name = "lazy-regex-proc_macros" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76e1d8b05d672c53cb9c7b920bbba8783845ae4f0b076e02a3db1d02c81b4163" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn 2.0.79", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -1788,6 +1837,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litrs" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5" + [[package]] name = "lock_api" version = "0.4.12" @@ -2040,6 +2095,7 @@ dependencies = [ "tokio", "toml", "toml_edit", + "ubi", "url", "usage-lib", "versions", @@ -2555,6 +2611,12 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" +[[package]] +name = "platforms" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14e6ab3f592e6fb464fc9712d8d6e6912de6473954635fd76a589d832cffcbb0" + [[package]] name = "portable-atomic" version = "1.9.0" @@ -3960,6 +4022,32 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "ubi" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d478e9147a27f8a8d973dead8057eb4cac66ec9e4ecbcfd46545a80375802c" +dependencies = [ + "anyhow", + "binstall-tar", + "bzip2", + "document-features", + "flate2", + "itertools 0.13.0", + "lazy-regex", + "log", + "platforms", + "regex", + "reqwest", + "serde", + "strum", + "tempfile", + "thiserror", + "url", + "xz", + "zip", +] + [[package]] name = "ucd-trie" version = "0.1.7" @@ -4064,6 +4152,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -4570,6 +4659,15 @@ dependencies = [ "zip", ] +[[package]] +name = "xz" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c887690ff2a2e233e8e49633461521f98ec57fbff9d59a884c9a4f04ec1da34" +dependencies = [ + "xz2", +] + [[package]] name = "xz2" version = "0.1.7" diff --git a/Cargo.toml b/Cargo.toml index 94c4af3b2..1722319ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -115,6 +115,7 @@ tokio = { version = "1.37.0", features = [ ] } toml = { version = "0.8", features = ["parse"] } toml_edit = { version = "0.22", features = ["parse"] } +ubi = { version = "0.2", default-features = false } url = "2.5.0" # usage-lib = { path = "../usage/lib", features = ["clap", "docs"] } usage-lib = { version = "0.8", features = ["clap", "docs"] } @@ -160,9 +161,9 @@ test-log = "0.2" [features] default = ["native-tls"] timings = [] -native-tls = ["reqwest/native-tls"] -rustls = ["reqwest/rustls-tls", "self_update/rustls"] -rustls-native-roots = ["reqwest/rustls-tls-native-roots", "self_update/rustls"] +native-tls = ["reqwest/native-tls", "ubi/native-tls"] +rustls = ["reqwest/rustls-tls", "self_update/rustls", "ubi/rustls-tls"] +rustls-native-roots = ["reqwest/rustls-tls-native-roots", "self_update/rustls", "ubi/rustls-tls-native-roots"] [package.metadata.binstall] bin-dir = "mise/bin/mise" diff --git a/docs/dev-tools/backends/ubi.md b/docs/dev-tools/backends/ubi.md index f7cd21929..667d60846 100644 --- a/docs/dev-tools/backends/ubi.md +++ b/docs/dev-tools/backends/ubi.md @@ -4,15 +4,6 @@ You may install GitHub Releases and URL packages directly using [ubi](https://gi The code for this is inside of the mise repository at [`./src/backend/ubi.rs`](https://github.com/jdx/mise/blob/main/src/backend/ubi.rs). -## Dependencies - -This relies on having `ubi` installed. You can install it with or without mise. -Here is how to install `ubi-cli` with mise: - -```sh -mise use -g cargo:ubi-cli -``` - ## Usage The following installs the latest version of goreleaser diff --git a/docs/registry.md b/docs/registry.md index 419fdb91a..c1c99bee9 100644 --- a/docs/registry.md +++ b/docs/registry.md @@ -730,7 +730,6 @@ editLink: false | typos | [asdf:aschiavon91/asdf-typos](https://github.com/aschiavon91/asdf-typos) | | typst | [asdf:stephane-klein/asdf-typst](https://github.com/stephane-klein/asdf-typst) | | uaa-cli | [asdf:vmware-tanzu/tanzu-plug-in-for-asdf](https://github.com/vmware-tanzu/tanzu-plug-in-for-asdf) | -| ubi | [cargo:ubi-cli](https://crates.io/crates/ubi-cli) | | unison | [asdf:susurri/asdf-unison](https://github.com/susurri/asdf-unison) | | updatecli | [asdf:updatecli/asdf-updatecli](https://github.com/updatecli/asdf-updatecli) | | upt | [asdf:ORCID/asdf-upt](https://github.com/ORCID/asdf-upt) | diff --git a/e2e/backend/test_ubi b/e2e/backend/test_ubi index 1f15844b6..6aa561347 100644 --- a/e2e/backend/test_ubi +++ b/e2e/backend/test_ubi @@ -1,5 +1,3 @@ #!/usr/bin/env bash -curl -sSf -L https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh | TARGET="$HOME/bin" sh - assert "mise x ubi:goreleaser/goreleaser@v1.25.0 -- goreleaser -v | grep -o 1.25.0" "1.25.0" diff --git a/e2e/backend/test_ubi_token b/e2e/backend/test_ubi_token deleted file mode 100644 index 03f57810e..000000000 --- a/e2e/backend/test_ubi_token +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -unset GITHUB_TOKEN GITHUB_API_TOKEN - -# Create an ubi stub that just output the value of GITHUB_TOKEN -cat >~/bin/ubi <<'EOF' -#!/usr/bin/env bash -echo "token=$GITHUB_TOKEN" -EOF -chmod u+x ~/bin/ubi -export PATH="$HOME/bin:$PATH" - -# This should reuse the existing GITHUB_TOKEN variable -assert_contains "GITHUB_TOKEN=foobar mise install -f ubi:goreleaser/goreleaser@v1.25.0 2>&1" "token=foobar" - -# This should use the GITHUB_API_TOKEN variable -assert_contains "GITHUB_API_TOKEN=foobar mise install -f ubi:goreleaser/goreleaser@v1.25.0 2>&1" "token=foobar" - -# This should prefer GITHUB_API_TOKEN -assert_contains "GITHUB_TOKEN=foobar GITHUB_API_TOKEN=barquz mise install -f ubi:goreleaser/goreleaser@v1.25.0 2>&1" "token=foobar" diff --git a/src/backend/ubi.rs b/src/backend/ubi.rs index 499cacd19..26035900c 100644 --- a/src/backend/ubi.rs +++ b/src/backend/ubi.rs @@ -1,10 +1,12 @@ use std::fmt::Debug; +use eyre::eyre; +use ubi::UbiBuilder; + use crate::backend::{Backend, BackendType}; use crate::cache::{CacheManager, CacheManagerBuilder}; use crate::cli::args::BackendArg; -use crate::cmd::CmdLineRunner; -use crate::config::{Config, Settings, SETTINGS}; +use crate::config::SETTINGS; use crate::env::GITHUB_TOKEN; use crate::github; use crate::install_context::InstallContext; @@ -17,7 +19,6 @@ pub struct UbiBackend { } // Uses ubi for installations https://github.com/houseabsolute/ubi -// it can be installed via mise install cargo:ubi-cli impl Backend for UbiBackend { fn get_type(&self) -> BackendType { BackendType::Ubi @@ -28,10 +29,9 @@ impl Backend for UbiBackend { } fn get_dependencies(&self, _tvr: &ToolRequest) -> eyre::Result> { - Ok(vec!["ubi".into()]) + Ok(vec![]) } - // TODO: v0.0.3 is stripped of 'v' such that it reports incorrectly in tool :-/ fn _list_remote_versions(&self) -> eyre::Result> { if name_is_url(self.name()) { Ok(vec!["latest".to_string()]) @@ -49,32 +49,39 @@ impl Backend for UbiBackend { } fn install_version_impl(&self, ctx: &InstallContext) -> eyre::Result<()> { - let config = Config::try_get()?; - let settings = Settings::get(); - let version = &ctx.tv.version; - settings.ensure_experimental("ubi backend")?; + SETTINGS.ensure_experimental("ubi backend")?; // Workaround because of not knowing how to pull out the value correctly without quoting let path_with_bin = ctx.tv.install_path().join("bin"); - let mut cmd = CmdLineRunner::new("ubi") - .arg("--in") - .arg(path_with_bin) - .arg("--project") - .arg(self.name()) - .with_pr(ctx.pr.as_ref()) - .envs(ctx.ts.env_with_path(&config)?) - .prepend_path(ctx.ts.list_paths())? - .prepend_path(self.dependency_toolset()?.list_paths())?; + let mut builder = UbiBuilder::new() + .project(self.name()) + .install_dir(path_with_bin); if let Some(token) = &*GITHUB_TOKEN { - cmd = cmd.env("GITHUB_TOKEN", token); + builder = builder.github_token(token); } + let version = &ctx.tv.version; if version != "latest" { - cmd = cmd.arg("--tag").arg(version); + builder = builder.tag(version); } - cmd.execute() + let exe = std::env::var("MISE_TOOL_OPTS__EXE").unwrap_or_default(); + if !exe.is_empty() { + builder = builder.exe(&exe); + } + let matching = std::env::var("MISE_TOOL_OPTS__MATCHING").unwrap_or_default(); + if !matching.is_empty() { + builder = builder.matching(&matching); + } + + let u = builder.build().map_err(|e| eyre!(e))?; + + let rt = tokio::runtime::Builder::new_current_thread() + .enable_io() + .enable_time() + .build()?; + rt.block_on(u.install_binary()).map_err(|e| eyre!(e)) } } diff --git a/src/registry.rs b/src/registry.rs index efc2bfb26..73ef7fd35 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -5,7 +5,6 @@ use once_cell::sync::Lazy; use std::collections::BTreeMap; const _REGISTRY: &[(&str, &str)] = &[ - ("ubi", "cargo:ubi-cli"), ("cargo-binstall", "cargo:cargo-binstall"), // ("elixir", "asdf:mise-plugins/mise-elixir"), ];