Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a switch argument to opam when context is not default #3951

Merged
merged 7 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. (#3951, @tmattio)

2.7.1 (2/09/2020)
-----------------

Expand Down
20 changes: 16 additions & 4 deletions bin/external_lib_deps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,31 @@ let all_lib_deps ~request =
|> Context_name.Map.map
~f:(Path.Source.Map.of_list_reduce ~f:Lib_deps_info.merge)

let opam_install_command ?switch_name packages =
let cmd =
match switch_name with
| Some name -> Printf.sprintf "opam install --switch=%s" name
| None -> "opam install"
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 ->
let lib_deps =
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 sctx =
Dune_engine.Context_name.Map.find_exn setup.Import.Main.scontexts
context_name
|> Super_context.internal_lib_names
in
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 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 (
Expand Down Expand Up @@ -107,8 +120,7 @@ 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:" " )
(opam_install_command ?switch_name required_package_names)
]);
true
) else if sexp then (
Expand Down