diff --git a/src/state/opamEnv.ml b/src/state/opamEnv.ml index f23350e57a6..96dce2d2d84 100644 --- a/src/state/opamEnv.ml +++ b/src/state/opamEnv.ml @@ -45,9 +45,11 @@ type sep_path_format = [ | `rewrite of separator * path_format (* path, rewrite using sep & fmt *) ] -let transform_format ~(sepfmt:sep_path_format) = +let transform_format ~(sepfmt:sep_path_format) var = match sepfmt with - | `norewrite -> fun x -> x + | `norewrite -> + fun arg -> + (arg, arg, OpamTypesBase.char_of_separator (fst (default_sep_fmt var))) | (`rewrite_default _ | `rewrite _) as sepfmt -> let separator, format = match sepfmt with @@ -64,14 +66,20 @@ let transform_format ~(sepfmt:sep_path_format) = (* noop on non windows *) (Lazy.force OpamSystem.get_cygpath_path_transform) ~pathlist:false in + let separator = OpamTypesBase.char_of_separator separator in match format with - | Target | Host -> translate + | Target | Host -> + fun arg -> + let path = translate arg in + (path, path, separator) | Target_quoted | Host_quoted -> fun arg -> let path = translate arg in - let separator = OpamTypesBase.char_of_separator separator in - if String.contains path separator then - "\""^path^"\"" else path + let quoted_path = + if String.contains path separator then + "\""^path^"\"" else path + in + (path, quoted_path, separator) let resolve_separator_and_format : type r. (r, 'a) env_update -> (spf_resolved, 'a) env_update = @@ -134,14 +142,38 @@ let resolve_separator_and_format : in { upd with envu_rewrite } +let split_path_variable path sep = + let length = String.length path in + let rec f acc index current current_raw last normal = + if index = length then + let final = String.sub path last (index - last) in + let current = current ^ final in + let current_raw = current_raw ^ final in + List.rev ((current, current_raw, sep)::acc) + else + let c = path.[index] + and next = succ index in + if c = sep && normal || c = '"' then + let segment = String.sub path last (index - last) in + let current = current ^ segment in + let current_raw = current_raw ^ segment in + if c = '"' then + f acc next current (current_raw ^ "\"") next (not normal) + else if next = length then (* path ends with a separator *) + List.rev (("", "", sep)::(current, current_raw, sep)::acc) + else (* c = sep; text follows *) + f ((current, current_raw, sep)::acc) next "" "" next true + else + f acc next current current_raw last normal + in + f [] 0 "" "" 0 true + (* - Environment and updates handling - *) let split_var ~(sepfmt:sep_path_format) var value = match sepfmt with | `norewrite -> - default_sep_fmt var - |> fst - |> char_of_separator - |> OpamStd.String.split value + let sep = char_of_separator (fst (default_sep_fmt var)) in + List.map (fun s -> (s, s, sep)) (OpamStd.String.split_delim value sep) | (`rewrite_default _ | `rewrite _) as sepfmt -> let separator, format = match sepfmt with @@ -149,23 +181,45 @@ let split_var ~(sepfmt:sep_path_format) var value = | `rewrite (sep, fmt) -> sep, fmt in let sep = OpamTypesBase.char_of_separator separator in - match format with - | Target | Host -> - OpamStd.String.split value sep - | Target_quoted | Host_quoted -> - OpamStd.String.split_quoted value sep - -let join_var ~(sepfmt:sep_path_format) var values = - let separator = + if value = String.make 1 sep then + [("", value, sep)] + else + match format with + | Target | Host -> + List.map (fun s -> (s, s, sep)) (OpamStd.String.split_delim value sep) + | Target_quoted | Host_quoted -> + split_path_variable value sep + +(* Auxiliaries for join_var - cf. String.concat *) +let rec sum_lengths acc = function +| [(_, raw, _)] -> acc + String.length raw +| (_, raw, _)::tl -> sum_lengths (acc + String.length raw + 1) tl +| [] -> acc (* semantically unreachable *) + +let rec unsafe_blits dst pos = function +| [] -> + Bytes.unsafe_to_string dst +| [(_, raw, _)] -> + String.unsafe_blit raw 0 dst pos (String.length raw); + Bytes.unsafe_to_string dst +| (_, raw, sep)::tl -> + let length = String.length raw in + String.unsafe_blit raw 0 dst pos length; + Bytes.unsafe_set dst (pos + length) sep; + unsafe_blits dst (pos + length + 1) tl + +let join_var values = + if values = [] then "" else + unsafe_blits (Bytes.create (sum_lengths 0 values)) 0 values + +let separator_char_for ~sepfmt var = + let (separator, _) = match sepfmt with - | `norewrite -> fst (default_sep_fmt var) - | `rewrite_default var -> fst (default_sep_fmt_str var) - | `rewrite (sep, _) -> sep + | `norewrite -> default_sep_fmt var + | `rewrite_default var -> default_sep_fmt_str var + | `rewrite spf -> spf in - String.concat - (String.make 1 (OpamTypesBase.char_of_separator separator)) - values - + OpamTypesBase.char_of_separator separator (* To allow in-place updates, we store intermediate values of path-like as a pair of list [(rl1, l2)] such that the value is [List.rev_append rl1 l2] and @@ -176,44 +230,43 @@ let unzip_to ~sepfmt var elt current = (* If [r = l @ rs] then [remove_prefix l r] is [Some rs], otherwise [None] *) let rec remove_prefix l r = match l, r with - | (l::ls, r::rs) when l = r -> + | ((l, _, _)::ls, (r, _, _)::rs) when l = r -> remove_prefix ls rs | ([], rs) -> Some rs | _ -> None in - match (if String.equal elt "" then [""] + match (if String.equal elt "" then [("", "", separator_char_for ~sepfmt var)] else split_var ~sepfmt var elt) with | [] -> invalid_arg "OpamEnv.unzip_to" - | hd::tl -> + | (hd, _, _)::tl -> let rec aux acc = function | [] -> None - | x::r -> + | ((x, _, _) as v)::r -> if String.equal x hd then match remove_prefix tl r with | Some r -> Some (acc, r) - | None -> aux (x::acc) r - else aux (x::acc) r + | None -> aux (v::acc) r + else aux (v::acc) r in aux [] current let rezip ?insert (l1, l2) = List.rev_append l1 (match insert with None -> l2 | Some i -> i::l2) -let rezip_to_string ~sepfmt var ?insert z = - join_var ~sepfmt var (rezip ?insert z) - +let rezip_to_string ?insert z = + join_var (rezip ?insert z) -let apply_op_zip ~sepfmt op arg (rl1,l2 as zip) = - let arg = transform_format ~sepfmt arg in +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; ""] - | "" :: l -> + | [] | [("", _, _)] -> [], [arg; ("", "", sep)] + | ("", _, _) :: l -> (* keep surrounding colons *) - if eqcol then l@[""], [arg] else l, [""; arg] + if eqcol then l@[("", "", sep)], [arg] else l, [("", "", sep); arg] | l -> l, [arg] in let cygwin path = - let contains_in dir item = + let contains_in (dir, _, _) item = Sys.file_exists (Filename.concat dir item) in let shadow_list = @@ -235,7 +288,11 @@ let apply_op_zip ~sepfmt op arg (rl1,l2 as zip) = | PlusEq -> (* New value goes at head of existing list; no prefix *) begin match rezip zip with - | [""] -> [], [arg] + | [("", raw, _)] -> + if raw = "" then + [], [arg] + else + [], [arg; ("", "", sep)] | zip -> [], arg::zip end | EqPlus -> @@ -243,7 +300,11 @@ let apply_op_zip ~sepfmt op arg (rl1,l2 as zip) = List.rev (List.rev_append rl1 l2) Place new value at the end *) begin match List.rev_append l2 rl1 with - | [""] -> [], [arg] + | [("", raw, _)] -> + if raw = "" then + [], [arg] + else + [], [("", "", sep); arg] | zip -> zip, [arg] end | Cygwin -> @@ -267,11 +328,11 @@ let apply_op_zip ~sepfmt op arg (rl1,l2 as zip) = or empty lists is returned if the variable should be unset or has an unknown previous value. *) let reverse_env_update ~sepfmt var op arg cur_value = - let arg = transform_format ~sepfmt arg in - if String.equal arg "" && op <> Eq then None else + let (arg, _, _) = transform_format ~sepfmt var arg in + if String.equal arg "" && op <> Eq then None else match op with | Eq -> - if arg = join_var ~sepfmt var cur_value + if arg = join_var cur_value then Some ([],[]) else None | PlusEq | EqPlusEq -> unzip_to var ~sepfmt arg cur_value | EqPlus | Cygwin -> @@ -280,11 +341,11 @@ let reverse_env_update ~sepfmt var op arg cur_value = | Some (rl1, l2) -> Some (List.rev l2, List.rev rl1)) | ColonEq -> (match unzip_to var ~sepfmt arg cur_value with - | Some ([], [""]) -> Some ([], []) + | Some ([], [("", _, _)]) -> Some ([], []) | r -> r) | EqColon -> (match unzip_to ~sepfmt var arg (List.rev cur_value) with - | Some ([], [""]) -> Some ([], []) + | Some ([], [("", _, _)]) -> Some ([], []) | Some (rl1, l2) -> Some (List.rev l2, List.rev rl1) | None -> None) @@ -423,7 +484,7 @@ let expand updates = in let acc = if String.equal arg "" && op <> Eq then acc else - ((var, apply_op_zip ~sepfmt op arg zip, doc, sepfmt) + ((var, apply_op_zip ~sepfmt var op arg zip, doc, sepfmt) :: acc) in apply_updates @@ -433,10 +494,10 @@ let expand updates = | [] -> List.rev @@ List.rev_append - (List.rev_map (fun (var, z, doc, sepfmt) -> - var, rezip_to_string ~sepfmt var z, doc) acc) - @@ List.rev_map (fun (var, z, sepfmt) -> - var, rezip_to_string ~sepfmt var z, + (List.rev_map (fun (var, z, doc, _sepfmt) -> + var, rezip_to_string z, doc) acc) + @@ List.rev_map (fun (var, z, _sepfmt) -> + var, rezip_to_string z, Some "Reverting previous opam update") reverts in @@ -957,15 +1018,8 @@ let string_of_update st shell updates = | Some (SPF_Resolved None) -> `rewrite_default envu_var | Some (SPF_Resolved (Some spf)) -> `rewrite spf in - let string = - transform_format ~sepfmt string - in - let sep = - OpamTypesBase.char_of_separator - (match envu_rewrite with - | Some (SPF_Resolved (Some (sep, _))) -> sep - | None | Some (SPF_Resolved None) -> - fst @@ default_sep_fmt_str envu_var) + let (_, string, sep) = + transform_format ~sepfmt (OpamStd.Env.Name.of_string envu_var) string in let key, value = envu_var, match (envu_op : euok_writeable env_update_op_kind) with diff --git a/tests/reftests/env.test b/tests/reftests/env.test index af606232144..9fea14fa18f 100644 --- a/tests/reftests/env.test +++ b/tests/reftests/env.test @@ -201,29 +201,29 @@ NV_VARS_5925_6=foo: NV_VARS_5925_7=:foo NV_VARS_5925_8=:foo NV_VARS_5926_L_1=b::a -NV_VARS_5926_L_2=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_4=:a:b NV_VARS_5926_L_5=:b:a -NV_VARS_5926_L_6=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 -NV_VARS_5926_M_2=a1:a2:b -NV_VARS_5926_M_3=b:a1:a2 -NV_VARS_5926_M_4=a1:a2:b -NV_VARS_5926_S_1=a -NV_VARS_5926_S_2=a +NV_VARS_5926_L_8=:a:b +NV_VARS_5926_M_1=b:a1::a2 +NV_VARS_5926_M_2=a1::a2:b +NV_VARS_5926_M_3=b:a1::a2 +NV_VARS_5926_M_4=a1::a2:b +NV_VARS_5926_S_1=a: +NV_VARS_5926_S_2=:a NV_VARS_5926_S_3=a: NV_VARS_5926_S_4=:a NV_VARS_5926_T_1=b:a: -NV_VARS_5926_T_2=b:a +NV_VARS_5926_T_2=b:a: NV_VARS_5926_T_3=a::b -NV_VARS_5926_T_4=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_6=b:a: NV_VARS_5926_T_7=:a:b -NV_VARS_5926_T_8=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: @@ -236,29 +236,29 @@ NV_VARS_5925_6='foo:': export NV_VARS_5925_6: NV_VARS_5925_7=':foo': export NV_VARS_5925_7: NV_VARS_5925_8=':foo': export NV_VARS_5925_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_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_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_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: -NV_VARS_5926_M_2='a1:a2:b': export NV_VARS_5926_M_2: -NV_VARS_5926_M_3='b:a1:a2': export NV_VARS_5926_M_3: -NV_VARS_5926_M_4='a1:a2:b': export NV_VARS_5926_M_4: -NV_VARS_5926_S_1='a': export NV_VARS_5926_S_1: -NV_VARS_5926_S_2='a': export NV_VARS_5926_S_2: +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: +NV_VARS_5926_M_2='a1::a2:b': export NV_VARS_5926_M_2: +NV_VARS_5926_M_3='b:a1::a2': export NV_VARS_5926_M_3: +NV_VARS_5926_M_4='a1::a2:b': export NV_VARS_5926_M_4: +NV_VARS_5926_S_1='a:': export NV_VARS_5926_S_1: +NV_VARS_5926_S_2=':a': export NV_VARS_5926_S_2: NV_VARS_5926_S_3='a:': export NV_VARS_5926_S_3: NV_VARS_5926_S_4=':a': export NV_VARS_5926_S_4: NV_VARS_5926_T_1='b:a:': export NV_VARS_5926_T_1: -NV_VARS_5926_T_2='b:a': export NV_VARS_5926_T_2: +NV_VARS_5926_T_2='b:a:': export NV_VARS_5926_T_2: 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_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_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_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: @@ -271,29 +271,29 @@ NV_VARS_5925_6='': export NV_VARS_5925_6: NV_VARS_5925_7='': export NV_VARS_5925_7: NV_VARS_5925_8='': export NV_VARS_5925_8: NV_VARS_5926_L_1='': export NV_VARS_5926_L_1: -NV_VARS_5926_L_2='a': export NV_VARS_5926_L_2: +NV_VARS_5926_L_2=':a': export NV_VARS_5926_L_2: NV_VARS_5926_L_3='': export NV_VARS_5926_L_3: -NV_VARS_5926_L_4='a': export NV_VARS_5926_L_4: +NV_VARS_5926_L_4='a:': export NV_VARS_5926_L_4: NV_VARS_5926_L_5='': export NV_VARS_5926_L_5: -NV_VARS_5926_L_6='a': export NV_VARS_5926_L_6: +NV_VARS_5926_L_6=':a': export NV_VARS_5926_L_6: NV_VARS_5926_L_7='': export NV_VARS_5926_L_7: -NV_VARS_5926_L_8='a': export NV_VARS_5926_L_8: -NV_VARS_5926_M_1='a1:a2': export NV_VARS_5926_M_1: -NV_VARS_5926_M_2='a2:a1': export NV_VARS_5926_M_2: -NV_VARS_5926_M_3='a1:a2': export NV_VARS_5926_M_3: -NV_VARS_5926_M_4='a2:a1': export NV_VARS_5926_M_4: +NV_VARS_5926_L_8='a:': export NV_VARS_5926_L_8: +NV_VARS_5926_M_1='a1::a2': export NV_VARS_5926_M_1: +NV_VARS_5926_M_2='a2::a1': export NV_VARS_5926_M_2: +NV_VARS_5926_M_3='a1::a2': export NV_VARS_5926_M_3: +NV_VARS_5926_M_4='a2::a1': export NV_VARS_5926_M_4: NV_VARS_5926_S_1='': export NV_VARS_5926_S_1: NV_VARS_5926_S_2='': export NV_VARS_5926_S_2: NV_VARS_5926_S_3='': export NV_VARS_5926_S_3: NV_VARS_5926_S_4='': export NV_VARS_5926_S_4: NV_VARS_5926_T_1='': export NV_VARS_5926_T_1: -NV_VARS_5926_T_2='a': export NV_VARS_5926_T_2: +NV_VARS_5926_T_2='a:': export NV_VARS_5926_T_2: NV_VARS_5926_T_3='': export NV_VARS_5926_T_3: -NV_VARS_5926_T_4='a': export NV_VARS_5926_T_4: +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_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 @@ -312,29 +312,29 @@ NV_VARS_5925_6=foo: NV_VARS_5925_7=:foo NV_VARS_5925_8=:foo NV_VARS_5926_L_1=b::a -NV_VARS_5926_L_2=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_4=:a:b NV_VARS_5926_L_5=:b:a -NV_VARS_5926_L_6=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 -NV_VARS_5926_M_2=a1:a2:b -NV_VARS_5926_M_3=b:a1:a2 -NV_VARS_5926_M_4=a1:a2:b -NV_VARS_5926_S_1=a -NV_VARS_5926_S_2=a +NV_VARS_5926_L_8=:a:b +NV_VARS_5926_M_1=b:a1::a2 +NV_VARS_5926_M_2=a1::a2:b +NV_VARS_5926_M_3=b:a1::a2 +NV_VARS_5926_M_4=a1::a2:b +NV_VARS_5926_S_1=a: +NV_VARS_5926_S_2=:a NV_VARS_5926_S_3=a: NV_VARS_5926_S_4=:a NV_VARS_5926_T_1=b:a: -NV_VARS_5926_T_2=b:a +NV_VARS_5926_T_2=b:a: NV_VARS_5926_T_3=a::b -NV_VARS_5926_T_4=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_6=b:a: NV_VARS_5926_T_7=:a:b -NV_VARS_5926_T_8=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: @@ -347,29 +347,29 @@ NV_VARS_5925_6='foo:': export NV_VARS_5925_6: NV_VARS_5925_7=':foo': export NV_VARS_5925_7: NV_VARS_5925_8=':foo': export NV_VARS_5925_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_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_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_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: -NV_VARS_5926_M_2='a1:a2:b': export NV_VARS_5926_M_2: -NV_VARS_5926_M_3='b:a1:a2': export NV_VARS_5926_M_3: -NV_VARS_5926_M_4='a1:a2:b': export NV_VARS_5926_M_4: -NV_VARS_5926_S_1='a': export NV_VARS_5926_S_1: -NV_VARS_5926_S_2='a': export NV_VARS_5926_S_2: +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: +NV_VARS_5926_M_2='a1::a2:b': export NV_VARS_5926_M_2: +NV_VARS_5926_M_3='b:a1::a2': export NV_VARS_5926_M_3: +NV_VARS_5926_M_4='a1::a2:b': export NV_VARS_5926_M_4: +NV_VARS_5926_S_1='a:': export NV_VARS_5926_S_1: +NV_VARS_5926_S_2=':a': export NV_VARS_5926_S_2: NV_VARS_5926_S_3='a:': export NV_VARS_5926_S_3: NV_VARS_5926_S_4=':a': export NV_VARS_5926_S_4: NV_VARS_5926_T_1='b:a:': export NV_VARS_5926_T_1: -NV_VARS_5926_T_2='b:a': export NV_VARS_5926_T_2: +NV_VARS_5926_T_2='b:a:': export NV_VARS_5926_T_2: 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_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_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_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: @@ -382,29 +382,29 @@ NV_VARS_5925_6='': export NV_VARS_5925_6: NV_VARS_5925_7='': export NV_VARS_5925_7: NV_VARS_5925_8='': export NV_VARS_5925_8: NV_VARS_5926_L_1='': export NV_VARS_5926_L_1: -NV_VARS_5926_L_2='a': export NV_VARS_5926_L_2: +NV_VARS_5926_L_2=':a': export NV_VARS_5926_L_2: NV_VARS_5926_L_3='': export NV_VARS_5926_L_3: -NV_VARS_5926_L_4='a': export NV_VARS_5926_L_4: +NV_VARS_5926_L_4='a:': export NV_VARS_5926_L_4: NV_VARS_5926_L_5='': export NV_VARS_5926_L_5: -NV_VARS_5926_L_6='a': export NV_VARS_5926_L_6: +NV_VARS_5926_L_6=':a': export NV_VARS_5926_L_6: NV_VARS_5926_L_7='': export NV_VARS_5926_L_7: -NV_VARS_5926_L_8='a': export NV_VARS_5926_L_8: -NV_VARS_5926_M_1='a1:a2': export NV_VARS_5926_M_1: -NV_VARS_5926_M_2='a2:a1': export NV_VARS_5926_M_2: -NV_VARS_5926_M_3='a1:a2': export NV_VARS_5926_M_3: -NV_VARS_5926_M_4='a2:a1': export NV_VARS_5926_M_4: +NV_VARS_5926_L_8='a:': export NV_VARS_5926_L_8: +NV_VARS_5926_M_1='a1::a2': export NV_VARS_5926_M_1: +NV_VARS_5926_M_2='a2::a1': export NV_VARS_5926_M_2: +NV_VARS_5926_M_3='a1::a2': export NV_VARS_5926_M_3: +NV_VARS_5926_M_4='a2::a1': export NV_VARS_5926_M_4: NV_VARS_5926_S_1='': export NV_VARS_5926_S_1: NV_VARS_5926_S_2='': export NV_VARS_5926_S_2: NV_VARS_5926_S_3='': export NV_VARS_5926_S_3: NV_VARS_5926_S_4='': export NV_VARS_5926_S_4: NV_VARS_5926_T_1='': export NV_VARS_5926_T_1: -NV_VARS_5926_T_2='a': export NV_VARS_5926_T_2: +NV_VARS_5926_T_2='a:': export NV_VARS_5926_T_2: NV_VARS_5926_T_3='': export NV_VARS_5926_T_3: -NV_VARS_5926_T_4='a': export NV_VARS_5926_T_4: +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_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" @@ -469,29 +469,29 @@ NV_VARS_5925_6='foo:': export NV_VARS_5925_6: NV_VARS_5925_7=':foo': export NV_VARS_5925_7: NV_VARS_5925_8=':foo': export NV_VARS_5925_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_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_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_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: -NV_VARS_5926_M_2='a1:a2:b': export NV_VARS_5926_M_2: -NV_VARS_5926_M_3='b:a1:a2': export NV_VARS_5926_M_3: -NV_VARS_5926_M_4='a1:a2:b': export NV_VARS_5926_M_4: -NV_VARS_5926_S_1='a': export NV_VARS_5926_S_1: -NV_VARS_5926_S_2='a': export NV_VARS_5926_S_2: +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: +NV_VARS_5926_M_2='a1::a2:b': export NV_VARS_5926_M_2: +NV_VARS_5926_M_3='b:a1::a2': export NV_VARS_5926_M_3: +NV_VARS_5926_M_4='a1::a2:b': export NV_VARS_5926_M_4: +NV_VARS_5926_S_1='a:': export NV_VARS_5926_S_1: +NV_VARS_5926_S_2=':a': export NV_VARS_5926_S_2: NV_VARS_5926_S_3='a:': export NV_VARS_5926_S_3: NV_VARS_5926_S_4=':a': export NV_VARS_5926_S_4: NV_VARS_5926_T_1='b:a:': export NV_VARS_5926_T_1: -NV_VARS_5926_T_2='b:a': export NV_VARS_5926_T_2: +NV_VARS_5926_T_2='b:a:': export NV_VARS_5926_T_2: 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_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_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_8=':a:b': export NV_VARS_5926_T_8: ### OPAMNOENVNOTICE=1 ### : Env hooks : ### diff --git a/tests/reftests/env.win32.test b/tests/reftests/env.win32.test index 36cd1c711a7..34bbd276345 100644 --- a/tests/reftests/env.win32.test +++ b/tests/reftests/env.win32.test @@ -23,12 +23,11 @@ Done. set "MANPATH=:"${BASEDIR}/OPAM/rewriting/man"" set "PATH=${BASEDIR}/OPAM/rewriting/bin;C:\Devel\bin1;C:\Devel\bin2;"C:\Devel\bin3;";C:\Devel\bin4;ZZZ:\; ### opam exec -- opam env --shell=cmd --revert | grep 'ZZZ:' | 'ZZZ:\\.*' -> 'ZZZ:\' -set "PATH=C:\Devel\bin1;C:\Devel\bin2;C:\Devel\bin3;;C:\Devel\bin4;ZZZ:\ +set "PATH=C:\Devel\bin1;C:\Devel\bin2;"C:\Devel\bin3;";C:\Devel\bin4;ZZZ:\ ### : Test for #5838 ### opam env | grep MANPATH MANPATH=':"${BASEDIR}/OPAM/rewriting/man"'; export MANPATH; ### opam exec -- opam env --revert | grep MANPATH -MANPATH=''; export MANPATH; ### : Tests forward and backslash rewriting on revert ### : This sequence of updates is what presently happens with the compiler ### @@ -169,7 +168,7 @@ Processing 2/3: [col-target-quoted: sh env | grep RCTQ_ENV | sort] + sh "-c" "env | grep RCTQ_ENV | sort" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/col-target-quoted.1) - RCTQ_ENVBUILD=\a\given\path - RCTQ_ENVBUILD_ADD=\a\given\path:a/path/to -- RCTQ_ENVBUILD_ADD_WITH_COL="a:\nother\gi;ven\path":/a/path/to:t:/his/is/quoted +- RCTQ_ENVBUILD_ADD_WITH_COL="a:\nother\gi;ven\path":/a/path/to:"t:/his/is/quoted" - RCTQ_ENVBUILD_STR=something - RCTQ_ENVBUILD_WITH_COL="s:mething" - RCTQ_ENVSET_ADD=a/path/to @@ -180,7 +179,7 @@ Done. ### opam env | sort | grep "RCTQ_ENV" RCTQ_ENVSET='\a\given\path'; export RCTQ_ENVSET; RCTQ_ENVSET_ADD='\a\given\path:a/path/to'; export RCTQ_ENVSET_ADD; -RCTQ_ENVSET_ADD_WITH_COL='"a:\nother\gi;ven\path":/a/path/to:t:/his/is/quoted'; export RCTQ_ENVSET_ADD_WITH_COL; +RCTQ_ENVSET_ADD_WITH_COL='"a:\nother\gi;ven\path":/a/path/to:"t:/his/is/quoted"'; export RCTQ_ENVSET_ADD_WITH_COL; RCTQ_ENVSET_STR='something'; export RCTQ_ENVSET_STR; RCTQ_ENVSET_WITH_COL='"s:mething"'; export RCTQ_ENVSET_WITH_COL; ### cat OPAM/rewriting/.opam-switch/environment | grep RCTQ_ENV @@ -305,7 +304,7 @@ Processing 2/3: [col-host-quoted: sh env | grep RCHQ_ENV | sort] + sh "-c" "env | grep RCHQ_ENV | sort" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/col-host-quoted.1) - RCHQ_ENVBUILD=/a/given/path - RCHQ_ENVBUILD_ADD=/a/given/path:a/path/to -- RCHQ_ENVBUILD_ADD_WITH_COL=/cygdrive/a/nother/gi;ven/path:/a/path/to:t:/his/is/quoted +- RCHQ_ENVBUILD_ADD_WITH_COL=/cygdrive/a/nother/gi;ven/path:/a/path/to:"t:/his/is/quoted" - RCHQ_ENVBUILD_STR=something - RCHQ_ENVBUILD_WITH_COL="s:mething" - RCHQ_ENVSET_ADD=a/path/to @@ -316,7 +315,7 @@ Done. ### opam env | sort | grep "RCHQ_ENV" RCHQ_ENVSET='/a/given/path'; export RCHQ_ENVSET; RCHQ_ENVSET_ADD='/a/given/path:a/path/to'; export RCHQ_ENVSET_ADD; -RCHQ_ENVSET_ADD_WITH_COL='/cygdrive/a/nother/gi;ven/path:/a/path/to:t:/his/is/quoted'; export RCHQ_ENVSET_ADD_WITH_COL; +RCHQ_ENVSET_ADD_WITH_COL='/cygdrive/a/nother/gi;ven/path:/a/path/to:"t:/his/is/quoted"'; export RCHQ_ENVSET_ADD_WITH_COL; RCHQ_ENVSET_STR='something'; export RCHQ_ENVSET_STR; RCHQ_ENVSET_WITH_COL='"s:mething"'; export RCHQ_ENVSET_WITH_COL; ### cat OPAM/rewriting/.opam-switch/environment | grep RCHQ_ENV @@ -441,7 +440,7 @@ Processing 2/3: [semicol-target-quoted: sh env | grep RSTQ_ENV | sort] + sh "-c" "env | grep RSTQ_ENV | sort" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/semicol-target-quoted.1) - RSTQ_ENVBUILD=\a\given\path - RSTQ_ENVBUILD_ADD=\a\given\path;a/path/to -- RSTQ_ENVBUILD_ADD_WITH_COL="a:\nother\gi;ven\path";/a/path/to;t:/his/is/quoted +- RSTQ_ENVBUILD_ADD_WITH_COL="a:\nother\gi;ven\path";/a/path/to;"t:/his/is/quoted" - RSTQ_ENVBUILD_STR=something - RSTQ_ENVBUILD_WITH_COL=s:mething - RSTQ_ENVSET_ADD=a/path/to @@ -452,7 +451,7 @@ Done. ### opam env | sort | grep "RSTQ_ENV" RSTQ_ENVSET='\a\given\path'; export RSTQ_ENVSET; RSTQ_ENVSET_ADD='\a\given\path;a/path/to'; export RSTQ_ENVSET_ADD; -RSTQ_ENVSET_ADD_WITH_COL='"a:\nother\gi;ven\path";/a/path/to;t:/his/is/quoted'; export RSTQ_ENVSET_ADD_WITH_COL; +RSTQ_ENVSET_ADD_WITH_COL='"a:\nother\gi;ven\path";/a/path/to;"t:/his/is/quoted"'; export RSTQ_ENVSET_ADD_WITH_COL; RSTQ_ENVSET_STR='something'; export RSTQ_ENVSET_STR; RSTQ_ENVSET_WITH_COL='s:mething'; export RSTQ_ENVSET_WITH_COL; ### cat OPAM/rewriting/.opam-switch/environment | grep RSTQ_ENV @@ -577,7 +576,7 @@ Processing 2/3: [semicol-host-quoted: sh env | grep RSHQ_ENV | sort] + sh "-c" "env | grep RSHQ_ENV | sort" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/semicol-host-quoted.1) - RSHQ_ENVBUILD=/a/given/path - RSHQ_ENVBUILD_ADD=/a/given/path;a/path/to -- RSHQ_ENVBUILD_ADD_WITH_COL="/cygdrive/a/nother/gi;ven/path";/a/path/to;t:/his/is/quoted +- RSHQ_ENVBUILD_ADD_WITH_COL="/cygdrive/a/nother/gi;ven/path";/a/path/to;"t:/his/is/quoted" - RSHQ_ENVBUILD_STR=something - RSHQ_ENVBUILD_WITH_COL=s:mething - RSHQ_ENVSET_ADD=a/path/to @@ -588,7 +587,7 @@ Done. ### opam env | sort | grep "RSHQ_ENV" RSHQ_ENVSET='/a/given/path'; export RSHQ_ENVSET; RSHQ_ENVSET_ADD='/a/given/path;a/path/to'; export RSHQ_ENVSET_ADD; -RSHQ_ENVSET_ADD_WITH_COL='"/cygdrive/a/nother/gi;ven/path";/a/path/to;t:/his/is/quoted'; export RSHQ_ENVSET_ADD_WITH_COL; +RSHQ_ENVSET_ADD_WITH_COL='"/cygdrive/a/nother/gi;ven/path";/a/path/to;"t:/his/is/quoted"'; export RSHQ_ENVSET_ADD_WITH_COL; RSHQ_ENVSET_STR='something'; export RSHQ_ENVSET_STR; RSHQ_ENVSET_WITH_COL='s:mething'; export RSHQ_ENVSET_WITH_COL; ### cat OPAM/rewriting/.opam-switch/environment | grep RSHQ_ENV @@ -719,7 +718,7 @@ Processing 2/3: [rewrite: sh env | grep RO_ENV | sort] - RO_ENVBUILD=\another\given\path - RO_ENVBUILD_COL=s:mething - RO_ENVBUILD_COL_TARGET=/cygdrive/a/nother/gi;ven/path;a/path/to -- RO_ENVBUILD_COL_TARGET_QUOTED=/cygdrive/a/nother/gi;ven/path:a/path/to:this/i:s/quoted +- RO_ENVBUILD_COL_TARGET_QUOTED=/cygdrive/a/nother/gi;ven/path:a/path/to:"this/i:s/quoted" - RO_ENVBUILD_STR=something - RO_ENVSET_COL_TARGET=a/path/to - RO_ENVSET_COL_TARGET_QUOTED=a/path/to:"this/i:s/quoted" @@ -730,7 +729,7 @@ Done. RO_ENVSET='\a\given\path'; export RO_ENVSET; RO_ENVSET_COL='"s:mething"'; export RO_ENVSET_COL; RO_ENVSET_COL_TARGET='/cygdrive/a/nother/gi;ven/path;a/path/to'; export RO_ENVSET_COL_TARGET; -RO_ENVSET_COL_TARGET_QUOTED='/cygdrive/a/nother/gi;ven/path:a/path/to:this/i:s/quoted'; export RO_ENVSET_COL_TARGET_QUOTED; +RO_ENVSET_COL_TARGET_QUOTED='/cygdrive/a/nother/gi;ven/path:a/path/to:"this/i:s/quoted"'; export RO_ENVSET_COL_TARGET_QUOTED; RO_ENVSET_STR='something'; export RO_ENVSET_STR; RO_ENVSET_STR_WS2='something/else'; export RO_ENVSET_STR_WS2; RO_ENVSET_STR_WS='something/else'; export RO_ENVSET_STR_WS;