diff --git a/CHANGELOG.md b/CHANGELOG.md index 6556daf..0371cdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.11.0 + +#### 🚀 Updates + +- Added `install.primary` setting, for advanced configuring the primary bin/shim itself. Supports the same settings as the WASM plugin. +- Added `install.secondary` setting, for configuring secondary bins/shims. Supports the same settings as the WASM plugin. +- Updated to support proto v0.32 release. + ## 0.10.1 #### 🚀 Updates diff --git a/Cargo.lock b/Cargo.lock index b6ad2a3..46f362f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,9 +68,9 @@ checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] name = "anyhow" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" [[package]] name = "arbitrary" @@ -146,6 +146,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9475866fec1451be56a3c2400fd081ff546538961565ccb5b7142cbd22bc7a51" + [[package]] name = "bincode" version = "1.3.3" @@ -840,9 +846,9 @@ dependencies = [ [[package]] name = "extism" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7360c0823a0e303eb0b5bdb1125a5dae0867a77bfc533bd7e306b5989a53aab6" +checksum = "2687bfd28990a4725ddaf8a4374bff6d2debfd239d0fd6e55e2a7f476c5aec99" dependencies = [ "anyhow", "cbindgen", @@ -853,7 +859,7 @@ dependencies = [ "serde", "serde_json", "sha2", - "toml 0.8.10", + "toml 0.8.12", "tracing", "tracing-subscriber", "ureq", @@ -865,12 +871,12 @@ dependencies = [ [[package]] name = "extism-convert" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e78a2317936c20806cb60fa98c15dcc5ccf43458e4cbddad3c6cce17a05b31c" +checksum = "a63bfc6d371d3b51d6094fd96c4c32a084ceefece3b4f4b328f30067d29da064" dependencies = [ "anyhow", - "base64", + "base64 0.22.0", "bytemuck", "extism-convert-macros", "prost", @@ -881,9 +887,9 @@ dependencies = [ [[package]] name = "extism-convert-macros" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d190cc0c058346b7750868de96dab17e047e7588ec91691a29b6db4eafd51a7e" +checksum = "519ccf960500c87244bef99caf8e58222ac95bf1abb06a32f5217b4788857aa6" dependencies = [ "manyhow", "proc-macro-crate", @@ -894,11 +900,11 @@ dependencies = [ [[package]] name = "extism-manifest" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08af46dc0633e0874e6c1a66ac1226bf2fad6fa67568538238af8b316569d06" +checksum = "05c7d16695dc6b72418e23b58c943411a08264332af403ae9870997b4d495c3d" dependencies = [ - "base64", + "base64 0.22.0", "serde", "serde_json", ] @@ -910,7 +916,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f9a87d636d30b75e697642dd4f6cff2054db5a7a5d69d6601041a76265bb681" dependencies = [ "anyhow", - "base64", + "base64 0.21.7", "extism-convert", "extism-manifest", "extism-pdk-derive", @@ -1664,10 +1670,11 @@ dependencies = [ [[package]] name = "miette" -version = "7.1.0" +version = "7.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baed61d13cc3723ee6dbed730a82bfacedc60a85d81da2d77e9c3e8ebc0b504a" +checksum = "4edc8853320c2a0dab800fbda86253c8938f6ea88510dc92c5f1ed20e794afc1" dependencies = [ + "cfg-if", "miette-derive", "thiserror", "unicode-width", @@ -1675,9 +1682,9 @@ dependencies = [ [[package]] name = "miette-derive" -version = "7.1.0" +version = "7.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301c3f54f98abc6c212ee722f5e5c62e472a334415840669e356f04850051ec" +checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c" dependencies = [ "proc-macro2", "quote", @@ -1994,9 +2001,9 @@ dependencies = [ [[package]] name = "proto_core" -version = "0.31.4" +version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74b70ca265bf5c66c905fd42a44a5f3aa2ddc024559353c2e698727855e72104" +checksum = "db090ec8043a89e8bd797cbe2abf562af31d03d684d81d44baf759036be9309e" dependencies = [ "cached", "human-sort", @@ -2023,15 +2030,16 @@ dependencies = [ "thiserror", "tracing", "url", + "uuid", "version_spec", "warpgate", ] [[package]] name = "proto_pdk" -version = "0.17.4" +version = "0.17.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca91c6d676df3d1bd651ab38f274a984528a1cfaafc3e685705d9cf31880040e" +checksum = "744304f2cd3dbf1928eeffaad5538f98d2ca84a8a8e3ab107418bb7b0b277ce0" dependencies = [ "extism-pdk", "proto_pdk_api", @@ -2042,9 +2050,9 @@ dependencies = [ [[package]] name = "proto_pdk_api" -version = "0.17.2" +version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de1e28d245d8af9d8dae9a77647beea080e6800224f8d2734495bf8176065b5a" +checksum = "e73499b8448495fa0021a7c2ebdcdc6b680d1faec2be35cfb6d3de9176a2ea41" dependencies = [ "rustc-hash", "semver", @@ -2058,16 +2066,17 @@ dependencies = [ [[package]] name = "proto_pdk_test_utils" -version = "0.19.7" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0357fd70149b508a96edc74df9e72e7081e3c4e9beed5e23ab9134ce86ef4d89" +checksum = "1f61bbb94802afc75e36e8836e45b28d5c848dfd3a00fe012e60032534f6f590" dependencies = [ "extism", "proto_core", "proto_pdk_api", "serde", "serde_json", - "toml 0.8.10", + "starbase_sandbox", + "toml 0.8.12", "warpgate", ] @@ -2234,11 +2243,11 @@ checksum = "e898588f33fdd5b9420719948f9f2a32c922a246964576f71ba7f24f80610fbc" [[package]] name = "reqwest" -version = "0.11.24" +version = "0.11.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" +checksum = "78bf93c4af7a8bb7d879d51cebe797356ff10ae8516ace542b5182d9dcac10b2" dependencies = [ - "base64", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -2381,7 +2390,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64", + "base64 0.21.7", ] [[package]] @@ -2443,7 +2452,7 @@ dependencies = [ [[package]] name = "schema_plugin" -version = "0.10.1" +version = "0.11.0" dependencies = [ "extism-pdk", "proto_pdk", @@ -2457,9 +2466,9 @@ dependencies = [ [[package]] name = "schematic" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "709e1f0b0a3db267a98da09c89a7818e307cc8daea841e1079eb5f5a02591d54" +checksum = "ac09b4b9c9fe5068fb44ac5cdc6b282acb175ab39e8b0d1eef737df2aeec3a91" dependencies = [ "garde", "indexmap 2.2.5", @@ -2470,15 +2479,15 @@ dependencies = [ "serde_path_to_error", "starbase_styles", "thiserror", - "toml 0.8.10", + "toml 0.8.12", "tracing", ] [[package]] name = "schematic_macros" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31af7347544d97d00870a5865d2077dac07c069a5290c26215ddd1138b302590" +checksum = "910c561ff783c09af4e4a7a4f7d6d733aed0a0374333de7f0b39f474568ba937" dependencies = [ "convert_case", "darling 0.20.8", @@ -2495,7 +2504,7 @@ checksum = "8f3adfbe1c90a6a9643433e490ef1605c6a99f93be37e4c83fe5149fca9698c6" dependencies = [ "indexmap 2.2.5", "serde_json", - "toml 0.8.10", + "toml 0.8.12", ] [[package]] @@ -2709,9 +2718,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "starbase_archive" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11f6c3e3896c0e4eef90967861b7eb54bb6d425846e910ba24d15ffb80d9c451" +checksum = "56bf4ff22495fe4c8384f124f4955373ed9d5c50c0e9bca53d202975c820687f" dependencies = [ "binstall-tar", "flate2", @@ -2752,9 +2761,9 @@ dependencies = [ [[package]] name = "starbase_sandbox" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4e41db850a6d98edb67ba83ea809cdc43d628ed54223c491e0f7fdd69b3194d" +checksum = "46eb2113d05c21fea19742d5df590641a44373eaa75c9178e6c8888d9ab31286" dependencies = [ "assert_cmd", "assert_fs", @@ -2779,9 +2788,9 @@ dependencies = [ [[package]] name = "starbase_utils" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "263d6acfb4522b7a60d349ca181257135c71377ce852c07e97e9eb5adf928efe" +checksum = "602b821bd1b020210432bdc5152056defca02dab1f601e86093cb12e842d0fa5" dependencies = [ "dirs 5.0.1", "fs4", @@ -2789,13 +2798,15 @@ dependencies = [ "miette", "once_cell", "relative-path", + "reqwest", "serde", "serde_json", "starbase_styles", "thiserror", "tokio", - "toml 0.8.10", + "toml 0.8.12", "tracing", + "url", "wax", ] @@ -2930,18 +2941,18 @@ checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", @@ -3038,14 +3049,14 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.10" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a9aad4a3066010876e8dcf5a8a06e70a558751117a145c6ce2b82c2e2054290" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.22.6", + "toml_edit 0.22.8", ] [[package]] @@ -3070,9 +3081,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.6" +version = "0.22.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c1b5fd4128cc8d3e0cb74d4ed9a9cc7c7284becd4df68f5f940e1ad123606f6" +checksum = "c12219811e0c1ba077867254e5ad62ee2c9c190b0d957110750ac0cda1ae96cd" dependencies = [ "indexmap 2.2.5", "serde", @@ -3212,7 +3223,7 @@ version = "2.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11f214ce18d8b2cbe84ed3aa6486ed3f5b285cf8d8fbdbce9f3f767a724adc35" dependencies = [ - "base64", + "base64 0.21.7", "flate2", "log", "once_cell", @@ -3298,9 +3309,9 @@ dependencies = [ [[package]] name = "warpgate" -version = "0.11.4" +version = "0.11.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf956d045a8d1aa24684171dc0f798661edce804d52ddd6e7e21e098aa196a3" +checksum = "f9f3a291841f84d077c092db81a0bdeb144f39865c6bff65ef3c6734959d7260" dependencies = [ "extism", "miette", @@ -3324,9 +3335,9 @@ dependencies = [ [[package]] name = "warpgate_api" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2392138177821e8aa5777655ed765ca0681325bfef597daa7110960d11644074" +checksum = "fb71be920bfea7dce93965ece5f79ed15222a2900a97b4b1039427d2641bf11e" dependencies = [ "anyhow", "rustc-hash", @@ -3339,9 +3350,9 @@ dependencies = [ [[package]] name = "warpgate_pdk" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc1caf7b6cd4fbcb7c8e3cc91a4b33e75b5d5baa607c52b07b3b5b74b2bcf785" +checksum = "1286c9c43a051463251deb81404b639a5bae5b6918fde781d75609d65a67520b" dependencies = [ "extism-pdk", "serde", @@ -3567,7 +3578,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8222c4317b8bc3d8566b0e605fcf9c56d14947d86fb18e83128badd5cb90f237" dependencies = [ "anyhow", - "base64", + "base64 0.21.7", "bincode", "directories-next", "log", diff --git a/Cargo.toml b/Cargo.toml index 461069e..7cce119 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "schema_plugin" -version = "0.10.1" +version = "0.11.0" edition = "2021" license = "MIT" publish = false @@ -10,7 +10,7 @@ crate-type = ['cdylib'] [dependencies] extism-pdk = "1.1.0" -proto_pdk = { version = "0.17.4" } #, path = "../../proto/crates/pdk" } +proto_pdk = { version = "0.17.5" } #, path = "../../proto/crates/pdk" } regex = { version = "1.10.3", default-features = false, features = [ "std", "unicode-perl", @@ -19,10 +19,10 @@ serde = "1.0.197" serde_json = "1.0.114" [dev-dependencies] -proto_pdk_test_utils = { version = "0.19.7", features = [ +proto_pdk_test_utils = { version = "0.20.1", features = [ "schema", ] } #, path = "../../proto/crates/pdk-test-utils" } -starbase_sandbox = "0.4.1" +starbase_sandbox = "0.5.0" tokio = { version = "1.36.0", features = ["full"] } [features] diff --git a/src/proto.rs b/src/proto.rs index c31cdf8..019740b 100644 --- a/src/proto.rs +++ b/src/proto.rs @@ -1,9 +1,10 @@ -use crate::schema::{PlatformMapper, Schema, SchemaType}; +use crate::schema::{ExecutableSchema, PlatformMapper, Schema, SchemaType}; use extism_pdk::*; use proto_pdk::*; use regex::Captures; use serde_json::Value as JsonValue; use std::collections::HashMap; +use std::path::PathBuf; #[host_fn] extern "ExtismHost" { @@ -11,7 +12,7 @@ extern "ExtismHost" { } fn get_schema() -> Result { - let data = config::get("schema")?.expect("Missing schema!"); + let data = config::get("proto_schema")?.expect("Missing schema!"); let schema: Schema = json::from_str(&data)?; Ok(schema) @@ -34,11 +35,11 @@ fn get_platform<'schema>( }) } -fn get_bin_path( - version: &str, - platform: &PlatformMapper, +fn get_platform_exe_path( schema: &Schema, env: &HostEnvironment, + platform: &PlatformMapper, + version: &str, ) -> Result { let id = get_plugin_id()?; @@ -270,6 +271,19 @@ pub fn download_prebuilt( })) } +fn create_executable_config(schema: ExecutableSchema) -> ExecutableConfig { + ExecutableConfig { + exe_path: schema.exe_path, + exe_link_path: schema.exe_link_path, + no_bin: schema.no_bin, + no_shim: schema.no_shim, + parent_exe_name: schema.parent_exe_name, + shim_before_args: schema.shim_before_args.map(StringOrVec::Vec), + shim_after_args: schema.shim_after_args.map(StringOrVec::Vec), + shim_env_vars: schema.shim_env_vars.map(HashMap::from_iter), + } +} + #[plugin_fn] pub fn locate_executables( Json(input): Json, @@ -277,16 +291,59 @@ pub fn locate_executables( let env = get_host_environment()?; let schema = get_schema()?; let platform = get_platform(&schema, &env)?; - let version = input.context.version.to_string(); - let mut primary = ExecutableConfig::new(get_bin_path(&version, platform, &schema, &env)?); - primary.no_bin = schema.install.no_bin; - primary.no_shim = schema.install.no_shim; + + // On Windows, automatically add the `.exe` extension to all executables. + // But only if there is no extension, so that we don't overwrite `.js` and others! + let append_exe_ext = |mut path: PathBuf| -> PathBuf { + if env.os.is_windows() && path.extension().is_none() { + path.set_extension("exe"); + } + + path + }; + + // Primary exe + let mut primary = schema + .install + .primary + .clone() + .map(create_executable_config) + .unwrap_or_default(); + + if platform.bin_path.is_none() && primary.exe_path.is_some() { + primary.exe_path = Some(append_exe_ext(primary.exe_path.unwrap())); + } else { + primary.exe_path = Some(get_platform_exe_path(&schema, &env, platform, &version)?.into()); + } + + if let Some(no_bin) = schema.install.no_bin { + primary.no_bin = no_bin; + } + + if let Some(no_shim) = schema.install.no_shim { + primary.no_shim = no_shim; + } + + // Secondary exe's + let secondary = schema.install.secondary.into_iter().map(|(key, value)| { + let mut config = create_executable_config(value); + + if let Some(exe_path) = config.exe_path.take() { + config.exe_path = Some(append_exe_ext(exe_path)); + } + + if let Some(exe_link_path) = config.exe_link_path.take() { + config.exe_link_path = Some(append_exe_ext(exe_link_path)); + } + + (key, config) + }); Ok(Json(LocateExecutablesOutput { globals_lookup_dirs: schema.packages.globals_lookup_dirs, globals_prefix: schema.packages.globals_prefix, primary: Some(primary), - ..LocateExecutablesOutput::default() + secondary: HashMap::from_iter(secondary), })) } diff --git a/src/schema.rs b/src/schema.rs index 5ab400e..c9d7573 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,6 +1,7 @@ use proto_pdk::{HostArch, HostLibc, HostOS}; use serde::Deserialize; use std::collections::HashMap; +use std::path::PathBuf; #[derive(Debug, Default, Deserialize)] #[serde(default, rename_all = "kebab-case")] @@ -18,6 +19,21 @@ pub struct DetectSchema { pub version_files: Option>, } +// Keep in sync with the `ExecutableConfig` shape! +// We had to create another struct so that we can serde rename... +#[derive(Clone, Debug, Default, Deserialize)] +#[serde(default, rename_all = "kebab-case")] +pub struct ExecutableSchema { + pub exe_path: Option, + pub exe_link_path: Option, + pub no_bin: bool, + pub no_shim: bool, + pub parent_exe_name: Option, + pub shim_before_args: Option>, + pub shim_after_args: Option>, + pub shim_env_vars: Option>, +} + #[derive(Debug, Default, Deserialize)] #[serde(default, rename_all = "kebab-case")] pub struct InstallSchema { @@ -28,8 +44,14 @@ pub struct InstallSchema { pub checksum_url_canary: Option, pub download_url: String, pub download_url_canary: Option, - pub no_bin: bool, - pub no_shim: bool, + + // Primary + pub primary: Option, + pub no_bin: Option, + pub no_shim: Option, + + // Secondary + pub secondary: HashMap, } #[derive(Debug, Default, Deserialize)] diff --git a/tests/__fixtures__/schemas/primary-platform.toml b/tests/__fixtures__/schemas/primary-platform.toml new file mode 100644 index 0000000..afe16c2 --- /dev/null +++ b/tests/__fixtures__/schemas/primary-platform.toml @@ -0,0 +1,15 @@ +bin = "moon-test" +name = "moon-test" +type = "cli" + +[platform.linux] +bin-path = "lin/moon" + +[platform.macos] +bin-path = "mac/moon" + +[platform.windows] +bin-path = "win/moon.exe" + +[install.primary] +exe-path = "bin/moon" diff --git a/tests/__fixtures__/schemas/shim-local.toml b/tests/__fixtures__/schemas/primary.toml similarity index 75% rename from tests/__fixtures__/schemas/shim-local.toml rename to tests/__fixtures__/schemas/primary.toml index 086e554..8e52b53 100644 --- a/tests/__fixtures__/schemas/shim-local.toml +++ b/tests/__fixtures__/schemas/primary.toml @@ -11,6 +11,7 @@ download-file = "moon-{arch}-apple-darwin" [platform.windows] download-file = "moon-{arch}-pc-windows-msvc.exe" -[shim] -local = true -parent_bin = "prnt" +[install.primary] +exe-path = "bin/moon" +no-shim = true +shim-before-args = ["-v"] diff --git a/tests/__fixtures__/schemas/secondary.toml b/tests/__fixtures__/schemas/secondary.toml new file mode 100644 index 0000000..cfb846d --- /dev/null +++ b/tests/__fixtures__/schemas/secondary.toml @@ -0,0 +1,29 @@ +bin = "moon-test" +name = "moon-test" +type = "cli" + +[platform.linux] +download-file = "moon-{arch}-unknown-linux-{libc}" + +[platform.macos] +download-file = "moon-{arch}-apple-darwin" + +[platform.windows] +download-file = "moon-{arch}-pc-windows-msvc.exe" + +[install.secondary.foo] +exe-path = "bin/foo" + +[install.secondary.bar] +exe-path = "bin/bar" +no-bin = true +shim-env-vars = { "BAR" = "bar" } + +[install.secondary.baz] +exe-path = "bin/baz" +exe-link-path = "bin/baz-link" +no-shim = true + +[install.secondary.qux] +exe-path = "bin/qux.js" +parent-exe-name = "node" diff --git a/tests/__fixtures__/schemas/shim-no-global.toml b/tests/__fixtures__/schemas/shim-no-global.toml deleted file mode 100644 index 9b506ca..0000000 --- a/tests/__fixtures__/schemas/shim-no-global.toml +++ /dev/null @@ -1,15 +0,0 @@ -bin = "moon-test" -name = "moon-test" -type = "cli" - -[platform.linux] -download-file = "moon-{arch}-unknown-linux-{libc}" - -[platform.macos] -download-file = "moon-{arch}-apple-darwin" - -[platform.windows] -download-file = "moon-{arch}-pc-windows-msvc.exe" - -[shim] -global = false diff --git a/tests/download_test.rs b/tests/download_test.rs index d5f99b9..8fcefc5 100644 --- a/tests/download_test.rs +++ b/tests/download_test.rs @@ -1,5 +1,7 @@ +#![allow(clippy::disallowed_names)] + use proto_pdk_test_utils::*; -use starbase_sandbox::{create_empty_sandbox, locate_fixture}; +use starbase_sandbox::locate_fixture; use std::collections::HashMap; generate_download_install_tests!( @@ -10,12 +12,13 @@ generate_download_install_tests!( #[test] fn supports_linux_arm64() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin_with_config( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( "schema-test", - sandbox.path(), locate_fixture("schemas").join("bins.toml"), - HashMap::from_iter([map_config_environment(HostOS::Linux, HostArch::Arm64)]), + |config| { + config.host(HostOS::Linux, HostArch::Arm64); + }, ); assert_eq!( @@ -38,12 +41,13 @@ fn supports_linux_arm64() { #[test] fn supports_linux_x64() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin_with_config( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( "schema-test", - sandbox.path(), locate_fixture("schemas").join("bins.toml"), - HashMap::from_iter([map_config_environment(HostOS::Linux, HostArch::X64)]), + |config| { + config.host(HostOS::Linux, HostArch::X64); + }, ); assert_eq!( @@ -66,12 +70,13 @@ fn supports_linux_x64() { #[test] fn supports_macos_arm64() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin_with_config( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( "schema-test", - sandbox.path(), locate_fixture("schemas").join("bins.toml"), - HashMap::from_iter([map_config_environment(HostOS::MacOS, HostArch::Arm64)]), + |config| { + config.host(HostOS::MacOS, HostArch::Arm64); + }, ); assert_eq!( @@ -94,12 +99,13 @@ fn supports_macos_arm64() { #[test] fn supports_macos_x64() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin_with_config( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( "schema-test", - sandbox.path(), locate_fixture("schemas").join("bins.toml"), - HashMap::from_iter([map_config_environment(HostOS::MacOS, HostArch::X64)]), + |config| { + config.host(HostOS::MacOS, HostArch::X64); + }, ); assert_eq!( @@ -122,12 +128,13 @@ fn supports_macos_x64() { #[test] fn supports_windows_arm64() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin_with_config( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( "schema-test", - sandbox.path(), locate_fixture("schemas").join("bins.toml"), - HashMap::from_iter([map_config_environment(HostOS::Windows, HostArch::Arm64)]), + |config| { + config.host(HostOS::Windows, HostArch::Arm64); + }, ); assert_eq!( @@ -150,12 +157,13 @@ fn supports_windows_arm64() { #[test] fn supports_windows_x86() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin_with_config( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( "schema-test", - sandbox.path(), locate_fixture("schemas").join("bins.toml"), - HashMap::from_iter([map_config_environment(HostOS::Windows, HostArch::X86)]), + |config| { + config.host(HostOS::Windows, HostArch::X86); + }, ); assert_eq!( @@ -178,12 +186,13 @@ fn supports_windows_x86() { #[test] fn locates_linux_bin() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin_with_config( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( "schema-test", - sandbox.path(), locate_fixture("schemas").join("bins.toml"), - HashMap::from_iter([map_config_environment(HostOS::Linux, HostArch::Arm64)]), + |config| { + config.host(HostOS::Linux, HostArch::Arm64); + }, ); assert_eq!( @@ -203,12 +212,13 @@ fn locates_linux_bin() { #[test] fn locates_macos_bin() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin_with_config( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( "schema-test", - sandbox.path(), locate_fixture("schemas").join("bins.toml"), - HashMap::from_iter([map_config_environment(HostOS::MacOS, HostArch::X64)]), + |config| { + config.host(HostOS::MacOS, HostArch::X64); + }, ); assert_eq!( @@ -228,12 +238,13 @@ fn locates_macos_bin() { #[test] fn locates_windows_bin() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin_with_config( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( "schema-test", - sandbox.path(), locate_fixture("schemas").join("bins.toml"), - HashMap::from_iter([map_config_environment(HostOS::Windows, HostArch::X64)]), + |config| { + config.host(HostOS::Windows, HostArch::X64); + }, ); assert_eq!( @@ -250,3 +261,175 @@ fn locates_windows_bin() { Some("win/moon.exe".into()) ); } + +mod primary { + use super::*; + + #[test] + fn sets_primary_config() { + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( + "schema-test", + locate_fixture("schemas").join("primary.toml"), + |config| { + config.host(HostOS::MacOS, HostArch::X64); + }, + ); + + let config = plugin + .locate_executables(LocateExecutablesInput { + context: ToolContext { + version: VersionSpec::parse("20.0.0").unwrap(), + ..Default::default() + }, + }) + .primary + .unwrap(); + + assert_eq!(config.exe_path, Some("bin/moon".into())); + assert!(config.no_shim); + assert_eq!( + config.shim_before_args, + Some(StringOrVec::Vec(vec!["-v".into()])) + ); + } + + #[test] + fn auto_adds_exe_to_bin_on_windows() { + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( + "schema-test", + locate_fixture("schemas").join("primary.toml"), + |config| { + config.host(HostOS::Windows, HostArch::X64); + }, + ); + + assert_eq!( + plugin + .locate_executables(LocateExecutablesInput { + context: ToolContext { + version: VersionSpec::parse("20.0.0").unwrap(), + ..Default::default() + }, + }) + .primary + .unwrap() + .exe_path, + Some("bin/moon.exe".into()) + ); + } + + #[test] + fn primary_path_doesnt_override_platform_path() { + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( + "schema-test", + locate_fixture("schemas").join("primary-platform.toml"), + |config| { + config.host(HostOS::Linux, HostArch::X64); + }, + ); + + assert_eq!( + plugin + .locate_executables(LocateExecutablesInput { + context: ToolContext { + version: VersionSpec::parse("20.0.0").unwrap(), + ..Default::default() + }, + }) + .primary + .unwrap() + .exe_path, + Some("lin/moon".into()) + ); + } +} + +mod secondary { + use super::*; + + #[test] + fn sets_secondary_config() { + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( + "schema-test", + locate_fixture("schemas").join("secondary.toml"), + |config| { + config.host(HostOS::MacOS, HostArch::X64); + }, + ); + + let secondary = plugin + .locate_executables(LocateExecutablesInput { + context: ToolContext { + version: VersionSpec::parse("20.0.0").unwrap(), + ..Default::default() + }, + }) + .secondary; + + let foo = secondary.get("foo").unwrap(); + + assert_eq!(foo.exe_path, Some("bin/foo".into())); + + let bar = secondary.get("bar").unwrap(); + + assert_eq!(bar.exe_path, Some("bin/bar".into())); + assert!(bar.no_bin); + assert_eq!( + bar.shim_env_vars, + Some(HashMap::from_iter([("BAR".into(), "bar".into())])) + ); + + let baz = secondary.get("baz").unwrap(); + + assert_eq!(baz.exe_path, Some("bin/baz".into())); + assert_eq!(baz.exe_link_path, Some("bin/baz-link".into())); + assert!(baz.no_shim); + + let qux = secondary.get("qux").unwrap(); + + assert_eq!(qux.exe_path, Some("bin/qux.js".into())); + assert_eq!(qux.parent_exe_name, Some("node".into())); + } + + #[test] + fn auto_adds_exe_to_bin_on_windows() { + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin_with_config( + "schema-test", + locate_fixture("schemas").join("secondary.toml"), + |config| { + config.host(HostOS::Windows, HostArch::X64); + }, + ); + + let secondary = plugin + .locate_executables(LocateExecutablesInput { + context: ToolContext { + version: VersionSpec::parse("20.0.0").unwrap(), + ..Default::default() + }, + }) + .secondary; + + assert_eq!( + secondary.get("foo").unwrap().exe_path, + Some("bin/foo.exe".into()) + ); + assert_eq!( + secondary.get("bar").unwrap().exe_path, + Some("bin/bar.exe".into()) + ); + assert_eq!( + secondary.get("baz").unwrap().exe_path, + Some("bin/baz.exe".into()) + ); + assert_eq!( + secondary.get("qux").unwrap().exe_path, + Some("bin/qux.js".into()) + ); + } +} diff --git a/tests/metadata_test.rs b/tests/metadata_test.rs index 4e68c8a..4410172 100644 --- a/tests/metadata_test.rs +++ b/tests/metadata_test.rs @@ -1,14 +1,11 @@ use proto_pdk_test_utils::*; -use starbase_sandbox::{create_empty_sandbox, locate_fixture}; +use starbase_sandbox::locate_fixture; #[test] fn registers_metadata() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin( - "schema-test", - sandbox.path(), - locate_fixture("schemas").join("base.toml"), - ); + let sandbox = create_empty_proto_sandbox(); + let plugin = + sandbox.create_schema_plugin("schema-test", locate_fixture("schemas").join("base.toml")); assert_eq!( plugin.register_tool(ToolMetadataInput::default()), diff --git a/tests/shims_test.rs b/tests/shims_test.rs index 25c32e3..a9bce30 100644 --- a/tests/shims_test.rs +++ b/tests/shims_test.rs @@ -1,5 +1,5 @@ use proto_pdk_test_utils::*; -use starbase_sandbox::{create_empty_sandbox, locate_fixture}; +use starbase_sandbox::locate_fixture; #[cfg(not(windows))] generate_shims_test!( @@ -7,17 +7,3 @@ generate_shims_test!( [], Some(locate_fixture("schemas").join("base.toml")) ); - -#[tokio::test] -async fn doesnt_create_global_shim() { - let sandbox = create_empty_sandbox(); - let mut plugin = create_schema_plugin( - "schema-test", - sandbox.path(), - locate_fixture("schemas/shim-no-global.toml"), - ); - - plugin.tool.generate_shims(false).await.unwrap(); - - assert!(!sandbox.path().join(".proto/bin/schema-test").exists()); -} diff --git a/tests/versions_test.rs b/tests/versions_test.rs index 7cb661a..233d8b0 100644 --- a/tests/versions_test.rs +++ b/tests/versions_test.rs @@ -1,5 +1,5 @@ use proto_pdk_test_utils::*; -use starbase_sandbox::{create_empty_sandbox, locate_fixture}; +use starbase_sandbox::locate_fixture; generate_resolve_versions_tests!( "schema-test", @@ -13,12 +13,9 @@ generate_resolve_versions_tests!( #[test] fn loads_versions_from_git_tags() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin( - "schema-test", - sandbox.path(), - locate_fixture("schemas").join("base.toml"), - ); + let sandbox = create_empty_proto_sandbox(); + let plugin = + sandbox.create_schema_plugin("schema-test", locate_fixture("schemas").join("base.toml")); let output = plugin.load_versions(LoadVersionsInput::default()); @@ -27,12 +24,9 @@ fn loads_versions_from_git_tags() { #[test] fn sets_latest_alias() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin( - "schema-test", - sandbox.path(), - locate_fixture("schemas").join("base.toml"), - ); + let sandbox = create_empty_proto_sandbox(); + let plugin = + sandbox.create_schema_plugin("schema-test", locate_fixture("schemas").join("base.toml")); let output = plugin.load_versions(LoadVersionsInput::default()); @@ -43,10 +37,9 @@ fn sets_latest_alias() { #[test] fn version_pattern_supports_common_classes() { - let sandbox = create_empty_sandbox(); - let plugin = create_schema_plugin( + let sandbox = create_empty_proto_sandbox(); + let plugin = sandbox.create_schema_plugin( "schema-test", - sandbox.path(), locate_fixture("schemas").join("version-pattern.toml"), );