Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dra27 authored and rjbou committed May 10, 2024
1 parent acfd7d2 commit bf3c669
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
26 changes: 16 additions & 10 deletions src/state/opamEnv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions tests/reftests/env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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 :
### <pkg:foo.1>
opam-version: "2.0"
Expand Down Expand Up @@ -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:
Expand All @@ -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 :
### <pkg:av.1>
Expand Down

0 comments on commit bf3c669

Please sign in to comment.