From 13fbac0d309ad39cde8c8a6492c63db80348f81f Mon Sep 17 00:00:00 2001 From: Alpha DIALLO Date: Tue, 24 Oct 2023 14:56:53 +0200 Subject: [PATCH] Fix resolving optional public library This is a fix for the issue #53. The public optional libraries were resolved. --- deps.ml | 4 +- tests/test_optional_public_lib.t | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/test_optional_public_lib.t diff --git a/deps.ml b/deps.ml index ca0233f..03d7295 100644 --- a/deps.ml +++ b/deps.ml @@ -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 diff --git a/tests/test_optional_public_lib.t b/tests/test_optional_public_lib.t new file mode 100644 index 0000000..5628132 --- /dev/null +++ b/tests/test_optional_public_lib.t @@ -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 = "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]