Skip to content

Commit

Permalink
fix: enabled_if with dune describe (ocaml#10881)
Browse files Browse the repository at this point in the history
* fix: enabled_if with `dune describe`

Fixes ocaml#10779.

Signed-off-by: Alpha DIALLO <moyodiallo@gmail.com>
  • Loading branch information
moyodiallo authored and anmonteiro committed Nov 17, 2024
1 parent 01b5847 commit 2c0c872
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 55 deletions.
103 changes: 54 additions & 49 deletions bin/describe/describe_workspace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -387,58 +387,63 @@ module Crawl = struct
let executables sctx ~options ~project ~dir (exes : Executables.t)
: (Descr.Item.t * Lib.Set.t) option Memo.t
=
let first_exe = snd (Nonempty_list.hd exes.names) in
let* scope =
Scope.DB.find_by_project (Super_context.context sctx |> Context.name) project
in
let* modules_, obj_dir =
let+ modules_, obj_dir =
Dir_contents.get sctx ~dir
>>= Dir_contents.ocaml
>>= Ml_sources.modules_and_obj_dir
~libs:(Scope.libs scope)
~for_:(Exe { first_exe })
let* expander = Super_context.expander sctx ~dir in
Expander.eval_blang expander exes.enabled_if
>>= function
| false -> Memo.return None
| true ->
let first_exe = snd (Nonempty_list.hd exes.names) in
let* scope =
Scope.DB.find_by_project (Super_context.context sctx |> Context.name) project
in
Modules.With_vlib.modules modules_, obj_dir
in
let* pp_map =
let+ version =
let+ ocaml = Super_context.context sctx |> Context.ocaml in
ocaml.version
let* modules_, obj_dir =
let+ modules_, obj_dir =
Dir_contents.get sctx ~dir
>>= Dir_contents.ocaml
>>= Ml_sources.modules_and_obj_dir
~libs:(Scope.libs scope)
~for_:(Exe { first_exe })
in
Modules.With_vlib.modules modules_, obj_dir
in
Staged.unstage
@@ Pp_spec.pped_modules_map
(Preprocess.Per_module.without_instrumentation exes.buildable.preprocess)
version
in
let deps_of module_ =
let module_ = pp_map module_ in
immediate_deps_of_module ~options ~obj_dir ~modules:modules_ module_
in
let obj_dir = Obj_dir.of_local obj_dir in
let* modules_ = modules ~obj_dir ~deps_of modules_ in
let+ requires =
let* compile_info = Exe_rules.compile_info ~scope exes in
let open Resolve.Memo.O in
let* requires = Lib.Compile.direct_requires compile_info in
if options.with_pps
then
let+ pps = Lib.Compile.pps compile_info in
pps @ requires
else Resolve.Memo.return requires
in
match Resolve.peek requires with
| Error () -> None
| Ok libs ->
let include_dirs = Obj_dir.all_cmis obj_dir in
let exe_descr =
{ Descr.Exe.names = List.map ~f:snd (Nonempty_list.to_list exes.names)
; requires = List.map ~f:uid_of_library libs
; modules = modules_
; include_dirs
}
let* pp_map =
let+ version =
let+ ocaml = Super_context.context sctx |> Context.ocaml in
ocaml.version
in
Staged.unstage
@@ Pp_spec.pped_modules_map
(Preprocess.Per_module.without_instrumentation exes.buildable.preprocess)
version
in
Some (Descr.Item.Executables exe_descr, Lib.Set.of_list libs)
let deps_of module_ =
let module_ = pp_map module_ in
immediate_deps_of_module ~options ~obj_dir ~modules:modules_ module_
in
let obj_dir = Obj_dir.of_local obj_dir in
let* modules_ = modules ~obj_dir ~deps_of modules_ in
let+ requires =
let* compile_info = Exe_rules.compile_info ~scope exes in
let open Resolve.Memo.O in
let* requires = Lib.Compile.direct_requires compile_info in
if options.with_pps
then
let+ pps = Lib.Compile.pps compile_info in
pps @ requires
else Resolve.Memo.return requires
in
(match Resolve.peek requires with
| Error () -> None
| Ok libs ->
let include_dirs = Obj_dir.all_cmis obj_dir in
let exe_descr =
{ Descr.Exe.names = List.map ~f:snd (Nonempty_list.to_list exes.names)
; requires = List.map ~f:uid_of_library libs
; modules = modules_
; include_dirs
}
in
Some (Descr.Item.Executables exe_descr, Lib.Set.of_list libs))
;;

(* Builds a workspace item for the provided library object *)
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/10881.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Fix `dune describe` when an executable is disabled with `enabled_if`.
(#10881, fixes #10779, @moyodiallo)
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@

$ dune build
$ dune runtest
$ dune describe 2>&1 | head -n 5
Internal error, please report upstream including the contents of _build/log.
Description:
("modules_and_obj_dir: failed lookup",
{ keys = []; for_ = Exe { first_exe = "test" } })
Raised at Stdune__Code_error.raise in file
$ dune describe 2>&1
((root
$TESTCASE_ROOT)
(build_context _build/default))

0 comments on commit 2c0c872

Please sign in to comment.