Skip to content

Commit

Permalink
Fix resolving optional public library
Browse files Browse the repository at this point in the history
This is a fix for the issue ocurrent#53. The public optional libraries were
resolved.
  • Loading branch information
moyodiallo committed Oct 24, 2023
1 parent 998c59b commit 13fbac0
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
4 changes: 2 additions & 2 deletions deps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ let resolve_internal_deps d_items items_pkg =
else begin
Hashtbl.add acc (get_name item) item;
(get_item item).internal_deps
|> List.filter_map (fun (name, k) ->
|> List.filter_map (fun (name, _) ->
match Hashtbl.find_opt d_items_lib (String.cat name ".lib") with
| None -> None
| Some d_item_lib ->
if Kind.is_required k && Option.is_some (get_item d_item_lib).package then None
if Option.is_some (get_item d_item_lib).package then None
else Some d_item_lib)
|> fun internals -> add_internal acc (tl @ internals)
end
Expand Down
66 changes: 66 additions & 0 deletions tests/test_optional_public_lib.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Inspired from test_vendoring.t test. Create a project with an public optional libraries
It fixes the bug #53. The fix is about to not resolve an public optional library when used as dependency.

$ mkdir bin lib optional

$ cat > dune-project << EOF
> (lang dune 2.7)
> (generate_opam_files true)
> (package
> (name main)
> (synopsis "Main package")
> (depends libfoo))
> (package
> (name optional)
> (synopsis "Optional package")
> (depends bos))
> EOF

$ cat > bin/dune << EOF
> (executable
> (name main)
> (package main)
> (public_name main)
> (libraries lib))
> EOF

$ cat > lib/dune << EOF
> (library
> (name lib)
> (public_name main)
> (libraries findlib
> (select file.ml from
> (optional -> file.enabled.ml)
> ( -> file.disabled.ml))))
> EOF

$ cat > optional/dune << EOF
> (library
> (name optinal)
> (public_name optional)
> (libraries bos))
> EOF

$ touch bin/main.ml lib/lib.ml lib/file.disabled.ml lib/file.enabled.ml optional/optional.ml
$ dune build

Replace all version numbers with "1.0" to get predictable outut.

$ export OPAM_DUNE_LINT_TESTS=y

Check configuration:

$ dune external-lib-deps -p main @install
dune: This subcommand has been moved to dune describe external-lib-deps.
[1]

Check that the missing findlib for "lib" is detected, but not "optional"'s dependency
on "bos":
$ opam-dune-lint </dev/null
main.opam: changes needed:
"ocamlfind" {>= "1.0"} [from lib]
optional.opam: OK
Note: version numbers are just suggestions based on the currently installed version.
Run with -f to apply changes in non-interactive mode.
[1]

0 comments on commit 13fbac0

Please sign in to comment.