diff --git a/Cargo.lock b/Cargo.lock index 268138260a..c2f26506c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,9 +60,9 @@ dependencies = [ [[package]] name = "age" -version = "0.10.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77de71da1ca673855aacea507a7aed363beb8934cf61b62364fc4b479d2e8cda" +checksum = "edeef7d7b199195a2d7d7a8155d2d04aee736e60c5c7bdd7097d115369a8817d" dependencies = [ "age-core", "base64 0.21.7", @@ -693,15 +693,15 @@ dependencies = [ [[package]] name = "console" -version = "0.15.10" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" dependencies = [ "encode_unicode", + "lazy_static", "libc", - "once_cell", - "unicode-width 0.2.0", - "windows-sys 0.59.0", + "unicode-width 0.1.14", + "windows-sys 0.52.0", ] [[package]] @@ -1155,9 +1155,9 @@ dependencies = [ [[package]] name = "encode_unicode" -version = "1.0.0" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "encoding_rs" @@ -1269,7 +1269,7 @@ dependencies = [ "pest_derive", "regex", "strum", - "thiserror 2.0.8", + "thiserror 2.0.7", ] [[package]] @@ -1339,7 +1339,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", - "miniz_oxide 0.8.2", + "miniz_oxide 0.8.0", ] [[package]] @@ -1698,11 +1698,11 @@ dependencies = [ [[package]] name = "home" -version = "0.5.11" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] @@ -1774,9 +1774,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "1.5.2" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "256fb8d4bd6413123cc9d91832d78325c48ff41677595be797d90f42969beae0" +checksum = "97818827ef4f364230e16705d4706e2897df2bb60617d6ca15d598025a3c481f" dependencies = [ "bytes", "futures-channel", @@ -1794,9 +1794,9 @@ dependencies = [ [[package]] name = "hyper-rustls" -version = "0.27.4" +version = "0.27.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6884a48c6826ec44f524c7456b163cebe9e55a18d7b5e307cb4f100371cc767" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" dependencies = [ "futures-util", "http", @@ -2576,9 +2576,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.8.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" dependencies = [ "adler2", ] @@ -2678,7 +2678,7 @@ dependencies = [ "tera", "terminal_size", "test-log", - "thiserror 2.0.8", + "thiserror 2.0.7", "tokio", "toml 0.8.19", "toml_edit", @@ -3035,7 +3035,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b7cafe60d6cf8e62e1b9b2ea516a089c008945bb5a275416789e7db0bc199dc" dependencies = [ "memchr", - "thiserror 2.0.8", + "thiserror 2.0.7", "ucd-trie", ] @@ -3306,7 +3306,7 @@ dependencies = [ "rustc-hash 2.1.0", "rustls", "socket2", - "thiserror 2.0.8", + "thiserror 2.0.7", "tokio", "tracing", ] @@ -3325,7 +3325,7 @@ dependencies = [ "rustls", "rustls-pki-types", "slab", - "thiserror 2.0.8", + "thiserror 2.0.7", "tinyvec", "tracing", "web-time", @@ -3333,9 +3333,9 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.9" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c40286217b4ba3a71d644d752e6a0b71f13f1b6a2c5311acfcbe0c2418ed904" +checksum = "52cd4b1eff68bf27940dd39811292c49e007f4d0b4c357358dc9b0197be6b527" dependencies = [ "cfg_aliases", "libc", @@ -3703,7 +3703,7 @@ dependencies = [ "openssl-probe", "rustls-pki-types", "schannel", - "security-framework 3.1.0", + "security-framework 3.0.1", ] [[package]] @@ -3815,9 +3815,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "3.1.0" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81d3f8c9bfcc3cbb6b0179eb57042d75b1582bdc65c3cb95f3fa999509c03cbc" +checksum = "e1415a607e92bec364ea2cf9264646dcce0f91e6d65281bd6f2819cca3bf39c8" dependencies = [ "bitflags", "core-foundation 0.10.0", @@ -3828,9 +3828,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.13.0" +version = "2.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1863fd3768cd83c56a7f60faa4dc0d403f1b6df0a38c3c25f44b7894e45370d5" +checksum = "fa39c7303dc58b5543c94d22c1766b0d31f2ee58306363ea622b10bbc075eaa2" dependencies = [ "core-foundation-sys", "libc", @@ -4467,11 +4467,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.8" +version = "2.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f5383f3e0071702bf93ab5ee99b52d26936be9dedd9413067cbdcddcb6141a" +checksum = "93605438cbd668185516ab499d589afb7ee1859ea3d5fc8f6b0755e1c7443767" dependencies = [ - "thiserror-impl 2.0.8", + "thiserror-impl 2.0.7", ] [[package]] @@ -4487,9 +4487,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.8" +version = "2.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f357fcec90b3caef6623a099691be676d033b40a058ac95d2a6ade6fa0c943" +checksum = "e1d8749b4531af2117677a5fcd12b1348a3fe2b81e36e61ffeac5c4aa3273e36" dependencies = [ "proc-macro2", "quote", @@ -4790,7 +4790,7 @@ dependencies = [ "serde", "strum", "tempfile", - "thiserror 2.0.8", + "thiserror 2.0.7", "url", "which 7.0.0", "xz2", @@ -4938,9 +4938,9 @@ checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" [[package]] name = "usage-lib" -version = "1.7.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df120279033104f58e593407d0a5303dc918b7fb06c1a13365f799ae0d88c398" +checksum = "bd75b195d7d5e9232b7b0f5a76d2e13ca4b8ac765180aa37737adec4baa28ad1" dependencies = [ "clap", "heck 0.5.0", @@ -4955,7 +4955,7 @@ dependencies = [ "shell-words", "strum", "tera", - "thiserror 2.0.8", + "thiserror 2.0.7", "versions", "xx", ] @@ -5023,7 +5023,7 @@ dependencies = [ "serde", "serde_json", "tempfile", - "thiserror 2.0.8", + "thiserror 2.0.7", "tokio", "url", "xx", @@ -5540,7 +5540,7 @@ dependencies = [ "reqwest", "sha2", "tar", - "thiserror 2.0.8", + "thiserror 2.0.7", "tokio", "xz2", "zip", @@ -5671,9 +5671,9 @@ dependencies = [ [[package]] name = "zip" -version = "2.2.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae9c1ea7b3a5e1f4b922ff856a129881167511563dc219869afe3787fc0c1a45" +checksum = "99d52293fc86ea7cf13971b3bb81eb21683636e7ae24c729cdaf1b7c4157a352" dependencies = [ "aes", "arbitrary", @@ -5691,7 +5691,7 @@ dependencies = [ "pbkdf2", "rand", "sha1", - "thiserror 2.0.8", + "thiserror 2.0.7", "time", "zeroize", "zopfli", diff --git a/e2e/env/test_env_source b/e2e/env/test_env_source index fc8e087aab..baa5aa3cc0 100644 --- a/e2e/env/test_env_source +++ b/e2e/env/test_env_source @@ -7,6 +7,8 @@ EOF cat >"$MISE_CONFIG_DIR/source.sh" <)>, + paths: &mut Vec<(PathBuf, PathBuf)>, r: &mut EnvResults, normalize_path: fn(&Path, PathBuf) -> PathBuf, source: &Path, @@ -19,13 +21,25 @@ impl EnvResults { if let Ok(s) = r.parse_template(ctx, tera, source, &input) { for p in xx::file::glob(normalize_path(config_root, s.into())).unwrap_or_default() { r.env_scripts.push(p.clone()); - let env_diff = EnvDiff::from_bash_script(&p, config_root, env_vars.clone()) + let orig_path = env_vars.get(&*env::PATH_KEY).cloned().unwrap_or_default(); + let mut env_diff_opts = EnvDiffOptions::default(); + env_diff_opts.ignore_keys.shift_remove(&*env::PATH_KEY); // allow modifying PATH + let env_diff = EnvDiff::from_bash_script(&p, config_root, env_vars.clone(), env_diff_opts) .unwrap_or_default(); for p in env_diff.to_patches() { match p { EnvDiffOperation::Add(k, v) | EnvDiffOperation::Change(k, v) => { - r.env_remove.remove(&k); - env.insert(k.clone(), (v.clone(), Some(source.to_path_buf()))); + if k == *env::PATH_KEY { + // TODO: perhaps deal with path removals as well + if let Some(new_path) = v.strip_suffix(&orig_path) { + for p in env::split_paths(new_path) { + paths.push((p, source.to_path_buf())); + } + } + } else { + r.env_remove.remove(&k); + env.insert(k.clone(), (v.clone(), Some(source.to_path_buf()))); + } } EnvDiffOperation::Remove(k) => { env.shift_remove(&k); diff --git a/src/env_diff.rs b/src/env_diff.rs index 3082988795..53355ccd27 100644 --- a/src/env_diff.rs +++ b/src/env_diff.rs @@ -2,14 +2,16 @@ use std::collections::BTreeMap; use std::ffi::OsString; use std::fmt::Debug; use std::io::prelude::*; +use std::iter::once; use std::path::{Path, PathBuf}; use base64::prelude::*; use eyre::Result; use flate2::write::{ZlibDecoder, ZlibEncoder}; use flate2::Compression; -use indexmap::IndexMap; +use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; +use once_cell::sync::Lazy; use serde_derive::{Deserialize, Serialize}; use crate::env::PATH_KEY; @@ -60,7 +62,7 @@ impl EnvDiff { diff } - pub fn from_bash_script(script: &Path, dir: &Path, env: T) -> Result + pub fn from_bash_script(script: &Path, dir: &Path, env: T, opts: EnvDiffOptions) -> Result where T: IntoIterator, U: Into, @@ -92,7 +94,7 @@ impl EnvDiff { match line.strip_prefix("declare -x ") { Some(line) => { let (k, v) = line.split_once('=').unwrap_or_default(); - if valid_key(k) { + if invalid_key(k, &opts) { continue; } cur_key = Some(k.to_string()); @@ -161,20 +163,9 @@ impl EnvDiff { } } -fn valid_key(k: &str) -> bool { +fn invalid_key(k: &str, opts: &EnvDiffOptions) -> bool { k.is_empty() - || k == "_" - || k == "SHLVL" - || k == *PATH_KEY - || k == "PWD" - || k == "OLDPWD" - || k == "HOME" - || k == "USER" - || k == "SHELL" - || k == "SHELLOPTS" - || k == "COMP_WORDBREAKS" - || k == "PS1" - || k == "PROMPT_DIRTRIM" + || opts.ignore_keys.contains(k) // following two ignores are for exported bash functions and exported bash // functions which are multiline, they appear in the environment as e.g.: // BASH_FUNC_exported-bash-function%%=() { echo "this is an" @@ -185,6 +176,25 @@ fn valid_key(k: &str) -> bool { || k.starts_with(' ') } +static DEFAULT_IGNORE_KEYS: Lazy> = Lazy::new(|| { + [ + "_", + "SHLVL", + "PWD", + "OLDPWD", + "HOME", + "USER", + "SHELL", + "SHELLOPTS", + "COMP_WORDBREAKS", + "PS1", + "PROMPT_DIRTRIM", + ] + .iter() + .map(|s| s.to_string()) + .collect() +}); + impl Debug for EnvDiff { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let print_sorted = |hashmap: &IndexMap| { @@ -248,6 +258,22 @@ fn normalize_escape_sequences(input: &str) -> String { result } +pub struct EnvDiffOptions { + pub ignore_keys: IndexSet, +} + +impl Default for EnvDiffOptions { + fn default() -> Self { + Self { + ignore_keys: DEFAULT_IGNORE_KEYS + .iter() + .cloned() + .chain(once(PATH_KEY.to_string())) + .collect() + } + } +} + #[cfg(test)] mod tests { use super::*; @@ -356,7 +382,7 @@ mod tests { .map(|(k, v)| (k.into(), v.into())) .collect::>(); let cwd = dirs::CWD.clone().unwrap(); - let ed = EnvDiff::from_bash_script(path.as_path(), &cwd, orig).unwrap(); + let ed = EnvDiff::from_bash_script(path.as_path(), &cwd, orig, Default::default()).unwrap(); assert_debug_snapshot!(ed); } diff --git a/tasks.toml b/tasks.toml index b214f2dc9f..20f339c0d7 100644 --- a/tasks.toml +++ b/tasks.toml @@ -130,5 +130,5 @@ run = "cargo install --path . --debug" [xxx] hide = true tools = { gh = "2.60.0" } -run = "echo {{arg(name='greeting')}}" +run = "gh --version" description = "a task for testing" diff --git a/xtasks/release-plz b/xtasks/release-plz index 893271d2bc..67bc445dab 100755 --- a/xtasks/release-plz +++ b/xtasks/release-plz @@ -38,7 +38,8 @@ sed -i.bak "s/version = \"[0-9]\+\.[0-9]\+\.[0-9]\+\(-rc\.[0-9]\+\)\?\";$/versio mise run render ::: lint-fix -cargo update +# disable until next kdl-rs has compatible miette +#cargo update git add \ Cargo.lock \ Cargo.toml \