Skip to content

Commit

Permalink
added case to load libraries of executables
Browse files Browse the repository at this point in the history
Signed-off-by: Kiran Gopinathan <[email protected]>
  • Loading branch information
kiranandcode authored and rgrinberg committed Sep 1, 2021
1 parent 63aa373 commit fd4c4ae
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
----------

- Include dependencies of executables when creating toplevels (either `dune
top` or `dune utop`) (#4882, fixes #4872, @Gopiancode)

- Fixes `opam` META file requires entry for private libs (#4841, fixes #4839, @toots)

- Fixes `dune exec` not adding .exe on Windows (#4371, fixes #3322, @MisterDA)
Expand Down
46 changes: 46 additions & 0 deletions src/dune_rules/utop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,52 @@ let libs_and_ppx_under_dir sctx ~db ~dir =
, pps )
else
(acc, pps))
| Dune_file.Executables exes -> (
let* libs =
let open Memo.Build.O in
let* compile_info =
let project = Scope.project d.scope in
let dune_version = Dune_project.dune_version project in
let+ pps =
Resolve.Build.read_memo_build
(Preprocess.Per_module.with_instrumentation
exes.buildable.preprocess
~instrumentation_backend:
(Lib.DB.instrumentation_backend (Scope.libs d.scope)))
>>| Preprocess.Per_module.pps
in
Lib.DB.resolve_user_written_deps_for_exes db exes.names
exes.buildable.libraries ~pps ~dune_version
~allow_overlaps:
exes.buildable.allow_overlapping_dependencies
~forbidden_libraries:exes.forbidden_libraries
in
let+ available = Lib.Compile.direct_requires compile_info in
Resolve.peek available
in
match libs with
| Error () -> Memo.Build.return (acc, pps)
| Ok libs ->
Memo.Build.List.fold_left libs ~init:(acc, pps)
~f:(fun (acc, pps) lib ->
let info = Lib.info lib in
match Lib_info.kind info with
| Lib_kind.Ppx_rewriter _
| Ppx_deriver _ ->
Memo.Build.return
( Appendable_list.( @ )
(Appendable_list.singleton lib)
acc
, Appendable_list.( @ )
(Appendable_list.singleton
(Lib_info.loc info, Lib_info.name info))
pps )
| Normal ->
Memo.Build.return
( Appendable_list.( @ )
(Appendable_list.singleton lib)
acc
, pps )))
| _ -> Memo.Build.return (acc, pps)))
>>| fun (libs, pps) ->
(Appendable_list.to_list libs, Appendable_list.to_list pps)
Expand Down
6 changes: 1 addition & 5 deletions test/blackbox-tests/test-cases/utop/utop-executables.t/run.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
Running dune utop in a project with only executables loads external libraries
$ dune utop bin -- load_executable_libraries.ml
File "load_executable_libraries.ml", line 2, characters 2-9:
2 | Bar.run ();
^^^^^^^
Error: Unbound module Bar
[2]
loaded external library successfully

0 comments on commit fd4c4ae

Please sign in to comment.