From 4c3036b3cc215e19f23103cac62b56e23cf1c67d Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Fri, 31 Mar 2017 17:44:03 +0100 Subject: [PATCH] Don't fail when opam return the same envirnonemt variable several times Instead, print a warning and take the last bindings. Fixes #46 --- src/context.ml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/context.ml b/src/context.ml index f65f366f..3d0f4b68 100644 --- a/src/context.ml +++ b/src/context.ml @@ -392,7 +392,22 @@ let create_for_opam ?root ~switch ~name ?(merlin=false) () = >>= fun s -> let vars = Sexp_lexer.single (Lexing.from_string s) - |> Sexp.Of_sexp.(string_map string) + |> Sexp.Of_sexp.(list (pair string string)) + |> String_map.of_alist_multi + |> String_map.mapi ~f:(fun var values -> + match List.rev values with + | [] -> assert false + | [x] -> x + | x :: _ -> + Format.eprintf + "@{Warning@}: variable %S present multiple times in the output of:\n\ + @{
%s@}@." + var + (String.concat ~sep:" " + (List.map ~f:quote_for_shell + [Path.to_string fn; "config"; "env"; "--root"; root; + "--switch"; switch; "--sexp"])); + x) in let path = match String_map.find "PATH" vars with