Skip to content

Commit

Permalink
Merge pull request #3951 from tmattio/context-in-missing-deps-hint
Browse files Browse the repository at this point in the history
Signed-off-by: Thibaut Mattio <thibaut.mattio@gmail.com>
  • Loading branch information
nojb authored Nov 16, 2020
2 parents 497a4d6 + 41e47f0 commit 6b74732
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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

0 comments on commit 6b74732

Please sign in to comment.