From aa873690d20cbff775f2d2f329e7e2b1fdc1d35a Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Mon, 16 Sep 2024 14:56:46 +0100 Subject: [PATCH] Fix empty updates in dynamic init scripts opam already ensured that empty segments are never added to environment variables with opam env, but the filter was not there for writing the dynamic init scripts. --- master_changes.md | 1 + src/state/opamEnv.ml | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/master_changes.md b/master_changes.md index ed5e2cce5f0..bdd13eabf56 100644 --- a/master_changes.md +++ b/master_changes.md @@ -89,6 +89,7 @@ users) ## Env * Make the shell environment update hint easier to copy/paste [#6159 @kit-ty-kate - fix #6158] * Add install.exe to the list of non-shadowed programs when adding Cygwin's bin directory to PATH (ocamlfind et al can be affected by Vim for Windows) [#6190 @dra27] + * Don't write empty environment update segments to variables.sh (`FOO += ""` no longer adds `FOO='':"$FOO"; export FOO;`) [#6198 @dra27] ## Opamfile * Make all writes atomic [#5489 @kit-ty-kate] diff --git a/src/state/opamEnv.ml b/src/state/opamEnv.ml index d47b7ce9ec0..054f18dc305 100644 --- a/src/state/opamEnv.ml +++ b/src/state/opamEnv.ml @@ -1184,7 +1184,16 @@ let write_custom_init_scripts root custom = ) custom let write_dynamic_init_scripts st = - let updates = updates ~set_opamroot:false ~set_opamswitch:false st in + (* Empty environment updates must not be written to the scripts *) + let is_not_empty_update = function + | {envu_value = ""; envu_op; _} -> + envu_op = Eq + | _ -> true + in + let updates = + updates ~set_opamroot:false ~set_opamswitch:false st + |> List.filter is_not_empty_update + in try if OpamStateConfig.is_newer_than_self ~lock_kind:`Lock_write st.switch_global then