From a35a1e66aed38b714cfbe55696471bbbd7453f1e 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 791d3f0dd88..a92dbb76419 100644 --- a/master_changes.md +++ b/master_changes.md @@ -57,6 +57,7 @@ users) ## Clean ## Env + * Don't write empty environment update segments to variables.sh (`FOO += ""` no longer adds `FOO='':"$FOO"; export FOO;`) [#6198 @dra27] ## Opamfile 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