From 8ead750fb9178593ce38fd4e28a93133a6717f30 Mon Sep 17 00:00:00 2001 From: Thibaut Mattio Date: Mon, 16 Nov 2020 16:25:21 +0100 Subject: [PATCH 1/6] Add a switch argument to opam when context is not default Signed-off-by: Thibaut Mattio --- bin/external_lib_deps.ml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/external_lib_deps.ml b/bin/external_lib_deps.ml index e0425f1bff8..08d8cf602f2 100644 --- a/bin/external_lib_deps.ml +++ b/bin/external_lib_deps.ml @@ -46,6 +46,14 @@ let all_lib_deps ~request = |> Context_name.Map.map ~f:(Path.Source.Map.of_list_reduce ~f:Lib_deps_info.merge) +let populate_opam_command ~context_name packages = + let cmd = + match Dune_engine.Context_name.to_string context_name with + | "default" -> "opam install" + | ctx -> Printf.sprintf "opam install --switch=%s" ctx + in + cmd :: packages |> String.concat ~sep:" " + let run ~lib_deps ~by_dir ~setup ~only_missing ~sexp = Dune_engine.Context_name.Map.foldi lib_deps ~init:false ~f:(fun context_name lib_deps_by_dir acc -> @@ -107,8 +115,8 @@ let run ~lib_deps ~by_dir ~setup ~only_missing ~sexp = ] ~hints: [ Dune_engine.Utils.pp_command_hint - ( "opam install" :: required_package_names - |> String.concat ~sep:" " ) + (populate_opam_command ~context_name + required_package_names) ]); true ) else if sexp then ( From fd15c323ff658b995336c6815173defc58a28563 Mon Sep 17 00:00:00 2001 From: Thibaut Mattio Date: Mon, 16 Nov 2020 17:15:39 +0100 Subject: [PATCH 2/6] Use switch name instead of context name Signed-off-by: Thibaut Mattio --- bin/external_lib_deps.ml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bin/external_lib_deps.ml b/bin/external_lib_deps.ml index 08d8cf602f2..1ffac0cce74 100644 --- a/bin/external_lib_deps.ml +++ b/bin/external_lib_deps.ml @@ -46,11 +46,11 @@ let all_lib_deps ~request = |> Context_name.Map.map ~f:(Path.Source.Map.of_list_reduce ~f:Lib_deps_info.merge) -let populate_opam_command ~context_name packages = +let populate_opam_command ?switch_name packages = let cmd = - match Dune_engine.Context_name.to_string context_name with - | "default" -> "opam install" - | ctx -> Printf.sprintf "opam install --switch=%s" ctx + match switch_name with + | Some name -> Printf.sprintf "opam install --switch=%s" name + | None -> "opam install" in cmd :: packages |> String.concat ~sep:" " @@ -61,11 +61,16 @@ let run ~lib_deps ~by_dir ~setup ~only_missing ~sexp = Path.Source.Map.values lib_deps_by_dir |> List.fold_left ~init:Lib_name.Map.empty ~f:Lib_deps_info.merge in - let internals = + let scontext = Dune_engine.Context_name.Map.find_exn setup.Import.Main.scontexts context_name - |> Super_context.internal_lib_names in + let opam_switch_name = + match Super_context.context scontext |> fun ctx -> ctx.Context.kind with + | Default -> None + | Opam { switch; _ } -> Some switch + in + let internals = Super_context.internal_lib_names scontext in let is_external name _kind = not (Lib_name.Set.mem internals name) in let externals = Lib_name.Map.filteri lib_deps ~f:is_external in if only_missing then ( @@ -115,7 +120,7 @@ let run ~lib_deps ~by_dir ~setup ~only_missing ~sexp = ] ~hints: [ Dune_engine.Utils.pp_command_hint - (populate_opam_command ~context_name + (populate_opam_command ?switch_name:opam_switch_name required_package_names) ]); true From 914d7fa8ab76b600cdf85981c2edab72cd714b40 Mon Sep 17 00:00:00 2001 From: Thibaut Mattio Date: Mon, 16 Nov 2020 17:23:23 +0100 Subject: [PATCH 3/6] Add a changelog entry Signed-off-by: Thibaut Mattio --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index b7501be7890..b05e6a57672 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -74,6 +74,8 @@ Unreleased - Tweak auto-formatting of `dune` files to improve readability. (#3928, @nojb) +- Add a switch argument to opam when context is not default. (#3951m @tmattio) + 2.7.1 (2/09/2020) ----------------- From 3b100b5c1d5e90e0430c62a0f23c3a167c830519 Mon Sep 17 00:00:00 2001 From: Thibaut Mattio Date: Mon, 16 Nov 2020 17:27:23 +0100 Subject: [PATCH 4/6] Address PR reviews Signed-off-by: Thibaut Mattio --- bin/external_lib_deps.ml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bin/external_lib_deps.ml b/bin/external_lib_deps.ml index 1ffac0cce74..ee81353106d 100644 --- a/bin/external_lib_deps.ml +++ b/bin/external_lib_deps.ml @@ -61,16 +61,16 @@ let run ~lib_deps ~by_dir ~setup ~only_missing ~sexp = Path.Source.Map.values lib_deps_by_dir |> List.fold_left ~init:Lib_name.Map.empty ~f:Lib_deps_info.merge in - let scontext = + let sctx = Dune_engine.Context_name.Map.find_exn setup.Import.Main.scontexts context_name in - let opam_switch_name = - match Super_context.context scontext |> fun ctx -> ctx.Context.kind with + let switch_name = + match (Super_context.context sctx).Context.kind with | Default -> None | Opam { switch; _ } -> Some switch in - let internals = Super_context.internal_lib_names scontext in + let internals = Super_context.internal_lib_names sctx in let is_external name _kind = not (Lib_name.Set.mem internals name) in let externals = Lib_name.Map.filteri lib_deps ~f:is_external in if only_missing then ( @@ -120,8 +120,7 @@ let run ~lib_deps ~by_dir ~setup ~only_missing ~sexp = ] ~hints: [ Dune_engine.Utils.pp_command_hint - (populate_opam_command ?switch_name:opam_switch_name - required_package_names) + (populate_opam_command ?switch_name required_package_names) ]); true ) else if sexp then ( From 86598857708b4d5a4d10a84ab0875a0be4c063d7 Mon Sep 17 00:00:00 2001 From: Thibaut Mattio Date: Mon, 16 Nov 2020 17:36:42 +0100 Subject: [PATCH 5/6] Update CHANGES.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolás Ojeda Bär Signed-off-by: Thibaut Mattio --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index b05e6a57672..5b54bea0111 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -74,7 +74,7 @@ Unreleased - Tweak auto-formatting of `dune` files to improve readability. (#3928, @nojb) -- Add a switch argument to opam when context is not default. (#3951m @tmattio) +- Add a switch argument to opam when context is not default. (#3951, @tmattio) 2.7.1 (2/09/2020) ----------------- From a04006399a8c571f83e3f3703a4fed7297405d9c Mon Sep 17 00:00:00 2001 From: Thibaut Mattio Date: Mon, 16 Nov 2020 20:05:05 +0100 Subject: [PATCH 6/6] Rename opam command function Signed-off-by: Thibaut Mattio --- bin/external_lib_deps.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/external_lib_deps.ml b/bin/external_lib_deps.ml index ee81353106d..ca1c768c91e 100644 --- a/bin/external_lib_deps.ml +++ b/bin/external_lib_deps.ml @@ -46,7 +46,7 @@ let all_lib_deps ~request = |> Context_name.Map.map ~f:(Path.Source.Map.of_list_reduce ~f:Lib_deps_info.merge) -let populate_opam_command ?switch_name packages = +let opam_install_command ?switch_name packages = let cmd = match switch_name with | Some name -> Printf.sprintf "opam install --switch=%s" name @@ -120,7 +120,7 @@ let run ~lib_deps ~by_dir ~setup ~only_missing ~sexp = ] ~hints: [ Dune_engine.Utils.pp_command_hint - (populate_opam_command ?switch_name required_package_names) + (opam_install_command ?switch_name required_package_names) ]); true ) else if sexp then (