From 3eb490dd329df52390775c5b48982d3cf6be601c Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Tue, 30 Apr 2024 14:59:54 +0100 Subject: [PATCH] Fix #5926 --- src/state/opamEnv.ml | 26 ++++++++++++++---------- tests/reftests/env.test | 44 ++++++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/src/state/opamEnv.ml b/src/state/opamEnv.ml index d3a5eb00382..07c4a8ad6b7 100644 --- a/src/state/opamEnv.ml +++ b/src/state/opamEnv.ml @@ -278,13 +278,6 @@ let rezip_to_string ?insert z = let apply_op_zip ~sepfmt var op arg (rl1,l2 as zip) = let (_, _, sep) as arg = transform_format ~sepfmt var arg in - let colon_eq ?(eqcol=false) = function (* prepend a, but keep ":"s *) - | [] | [("", _, _)] -> [], [arg; ("", "", sep)] - | ("", _, _) :: l -> - (* keep surrounding colons *) - if eqcol then l@[("", "", sep)], [arg] else l, [("", "", sep); arg] - | l -> l, [arg] - in let cygwin path = let contains_in (dir, _, _) item = Sys.file_exists (Filename.concat dir item) @@ -336,10 +329,23 @@ let apply_op_zip ~sepfmt var op arg (rl1,l2 as zip) = without the rezip) *) rl1, arg::l2 | ColonEq -> - let l, add = colon_eq (rezip zip) in [], add @ l + begin match rezip zip with + | [("", _, _)] | [] -> (* empty or unset *) + [], [arg; ("", "", sep)] + | (("", _, _) as lead)::("", _, _)::([] as zip) -> (* VAR=':' *) + [], lead::arg::zip + | zip -> + [], arg::zip + end | EqColon -> - let l, add = colon_eq ~eqcol:true (List.rev_append l2 rl1) in - l, List.rev add + begin match List.rev_append l2 rl1 with + | [("", _, _)] | [] -> (* empty or unset *) + [], [("", "", sep); arg] + | (("", _, _) as lead)::("", _, _)::([] as zip) -> (* VAR=':' *) + [], List.rev (lead::arg::zip) + | zip -> + [], List.rev (arg::zip) + end (** Undoes previous updates done by opam, useful for not duplicating already done updates; this is obviously not perfect, as all operators are not diff --git a/tests/reftests/env.test b/tests/reftests/env.test index 9fea14fa18f..b9ac0d6f6ea 100644 --- a/tests/reftests/env.test +++ b/tests/reftests/env.test @@ -204,8 +204,8 @@ NV_VARS_5926_L_1=b::a NV_VARS_5926_L_2=b::a NV_VARS_5926_L_3=:a:b NV_VARS_5926_L_4=:a:b -NV_VARS_5926_L_5=:b:a -NV_VARS_5926_L_6=:b:a +NV_VARS_5926_L_5=b::a +NV_VARS_5926_L_6=b::a NV_VARS_5926_L_7=:a:b NV_VARS_5926_L_8=:a:b NV_VARS_5926_M_1=b:a1::a2 @@ -222,8 +222,8 @@ NV_VARS_5926_T_3=a::b NV_VARS_5926_T_4=a::b NV_VARS_5926_T_5=b:a: NV_VARS_5926_T_6=b:a: -NV_VARS_5926_T_7=:a:b -NV_VARS_5926_T_8=:a:b +NV_VARS_5926_T_7=a::b +NV_VARS_5926_T_8=a::b ### opam env | sort | grep "NV_VARS" | ';' -> ':' NV_VARS3='foo:': export NV_VARS3: NV_VARS4='': export NV_VARS4: @@ -239,8 +239,8 @@ NV_VARS_5926_L_1='b::a': export NV_VARS_5926_L_1: NV_VARS_5926_L_2='b::a': export NV_VARS_5926_L_2: NV_VARS_5926_L_3=':a:b': export NV_VARS_5926_L_3: NV_VARS_5926_L_4=':a:b': export NV_VARS_5926_L_4: -NV_VARS_5926_L_5=':b:a': export NV_VARS_5926_L_5: -NV_VARS_5926_L_6=':b:a': export NV_VARS_5926_L_6: +NV_VARS_5926_L_5='b::a': export NV_VARS_5926_L_5: +NV_VARS_5926_L_6='b::a': export NV_VARS_5926_L_6: NV_VARS_5926_L_7=':a:b': export NV_VARS_5926_L_7: NV_VARS_5926_L_8=':a:b': export NV_VARS_5926_L_8: NV_VARS_5926_M_1='b:a1::a2': export NV_VARS_5926_M_1: @@ -257,8 +257,8 @@ NV_VARS_5926_T_3='a::b': export NV_VARS_5926_T_3: NV_VARS_5926_T_4='a::b': export NV_VARS_5926_T_4: NV_VARS_5926_T_5='b:a:': export NV_VARS_5926_T_5: NV_VARS_5926_T_6='b:a:': export NV_VARS_5926_T_6: -NV_VARS_5926_T_7=':a:b': export NV_VARS_5926_T_7: -NV_VARS_5926_T_8=':a:b': export NV_VARS_5926_T_8: +NV_VARS_5926_T_7='a::b': export NV_VARS_5926_T_7: +NV_VARS_5926_T_8='a::b': export NV_VARS_5926_T_8: ### opam exec -- opam env --revert | grep "NV_VARS" | ';' -> ':' NV_VARS3='': export NV_VARS3: NV_VARS4='': export NV_VARS4: @@ -293,7 +293,7 @@ NV_VARS_5926_T_4=':a': export NV_VARS_5926_T_4: NV_VARS_5926_T_5='': export NV_VARS_5926_T_5: NV_VARS_5926_T_6='a:': export NV_VARS_5926_T_6: NV_VARS_5926_T_7='': export NV_VARS_5926_T_7: -NV_VARS_5926_T_8='a:': export NV_VARS_5926_T_8: +NV_VARS_5926_T_8=':a': export NV_VARS_5926_T_8: ### NV_VARS=/another/path ### NV_VARS2=/another/different/path ### NV_VARS3=/yet/another/different/path @@ -315,8 +315,8 @@ NV_VARS_5926_L_1=b::a NV_VARS_5926_L_2=b::a NV_VARS_5926_L_3=:a:b NV_VARS_5926_L_4=:a:b -NV_VARS_5926_L_5=:b:a -NV_VARS_5926_L_6=:b:a +NV_VARS_5926_L_5=b::a +NV_VARS_5926_L_6=b::a NV_VARS_5926_L_7=:a:b NV_VARS_5926_L_8=:a:b NV_VARS_5926_M_1=b:a1::a2 @@ -333,8 +333,8 @@ NV_VARS_5926_T_3=a::b NV_VARS_5926_T_4=a::b NV_VARS_5926_T_5=b:a: NV_VARS_5926_T_6=b:a: -NV_VARS_5926_T_7=:a:b -NV_VARS_5926_T_8=:a:b +NV_VARS_5926_T_7=a::b +NV_VARS_5926_T_8=a::b ### opam env | sort | grep "NV_VARS" | ';' -> ':' NV_VARS3='foo:/yet/another/different/path': export NV_VARS3: NV_VARS4='': export NV_VARS4: @@ -350,8 +350,8 @@ NV_VARS_5926_L_1='b::a': export NV_VARS_5926_L_1: NV_VARS_5926_L_2='b::a': export NV_VARS_5926_L_2: NV_VARS_5926_L_3=':a:b': export NV_VARS_5926_L_3: NV_VARS_5926_L_4=':a:b': export NV_VARS_5926_L_4: -NV_VARS_5926_L_5=':b:a': export NV_VARS_5926_L_5: -NV_VARS_5926_L_6=':b:a': export NV_VARS_5926_L_6: +NV_VARS_5926_L_5='b::a': export NV_VARS_5926_L_5: +NV_VARS_5926_L_6='b::a': export NV_VARS_5926_L_6: NV_VARS_5926_L_7=':a:b': export NV_VARS_5926_L_7: NV_VARS_5926_L_8=':a:b': export NV_VARS_5926_L_8: NV_VARS_5926_M_1='b:a1::a2': export NV_VARS_5926_M_1: @@ -368,8 +368,8 @@ NV_VARS_5926_T_3='a::b': export NV_VARS_5926_T_3: NV_VARS_5926_T_4='a::b': export NV_VARS_5926_T_4: NV_VARS_5926_T_5='b:a:': export NV_VARS_5926_T_5: NV_VARS_5926_T_6='b:a:': export NV_VARS_5926_T_6: -NV_VARS_5926_T_7=':a:b': export NV_VARS_5926_T_7: -NV_VARS_5926_T_8=':a:b': export NV_VARS_5926_T_8: +NV_VARS_5926_T_7='a::b': export NV_VARS_5926_T_7: +NV_VARS_5926_T_8='a::b': export NV_VARS_5926_T_8: ### opam exec -- opam env --revert | grep "NV_VARS" | ';' -> ':' NV_VARS3='/yet/another/different/path': export NV_VARS3: NV_VARS4='': export NV_VARS4: @@ -404,7 +404,7 @@ NV_VARS_5926_T_4=':a': export NV_VARS_5926_T_4: NV_VARS_5926_T_5='': export NV_VARS_5926_T_5: NV_VARS_5926_T_6='a:': export NV_VARS_5926_T_6: NV_VARS_5926_T_7='': export NV_VARS_5926_T_7: -NV_VARS_5926_T_8='a:': export NV_VARS_5926_T_8: +NV_VARS_5926_T_8=':a': export NV_VARS_5926_T_8: ### : Full revert of uninstalled package with setenv : ### opam-version: "2.0" @@ -472,8 +472,8 @@ NV_VARS_5926_L_1='b::a': export NV_VARS_5926_L_1: NV_VARS_5926_L_2='b::a': export NV_VARS_5926_L_2: NV_VARS_5926_L_3=':a:b': export NV_VARS_5926_L_3: NV_VARS_5926_L_4=':a:b': export NV_VARS_5926_L_4: -NV_VARS_5926_L_5=':b:a': export NV_VARS_5926_L_5: -NV_VARS_5926_L_6=':b:a': export NV_VARS_5926_L_6: +NV_VARS_5926_L_5='b::a': export NV_VARS_5926_L_5: +NV_VARS_5926_L_6='b::a': export NV_VARS_5926_L_6: NV_VARS_5926_L_7=':a:b': export NV_VARS_5926_L_7: NV_VARS_5926_L_8=':a:b': export NV_VARS_5926_L_8: NV_VARS_5926_M_1='b:a1::a2': export NV_VARS_5926_M_1: @@ -490,8 +490,8 @@ NV_VARS_5926_T_3='a::b': export NV_VARS_5926_T_3: NV_VARS_5926_T_4='a::b': export NV_VARS_5926_T_4: NV_VARS_5926_T_5='b:a:': export NV_VARS_5926_T_5: NV_VARS_5926_T_6='b:a:': export NV_VARS_5926_T_6: -NV_VARS_5926_T_7=':a:b': export NV_VARS_5926_T_7: -NV_VARS_5926_T_8=':a:b': export NV_VARS_5926_T_8: +NV_VARS_5926_T_7='a::b': export NV_VARS_5926_T_7: +NV_VARS_5926_T_8='a::b': export NV_VARS_5926_T_8: ### OPAMNOENVNOTICE=1 ### : Env hooks : ###