From ac1e29bab46cf86b6923ac5676daedd67753b159 Mon Sep 17 00:00:00 2001 From: Lucas Pluvinage Date: Mon, 1 Apr 2019 12:20:18 +0200 Subject: [PATCH] Quick fix multiple definitions of the same library when several scopes define the same library. Signed-off-by: Lucas Pluvinage Signed-off-by: Rudi Grinberg --- src/lib.ml | 4 ++++ src/stdune/list.ml | 3 +++ src/stdune/list.mli | 1 + test/blackbox-tests/test-cases/variants/run.t | 9 --------- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lib.ml b/src/lib.ml index 663ac43906c..1c951eeef82 100644 --- a/src/lib.ml +++ b/src/lib.ml @@ -762,6 +762,10 @@ let rec find_implementation_for db lib ~variants = ~f:(fun variant acc -> List.rev_append acc (Variant.Map.Multi.find available_implementations variant)) + |> List.sort_uniq ~compare:(fun (a:Lib_info.t) (b:Lib_info.t) -> + match Lib_name.compare a.name b.name with + | Eq -> Path.compare a.src_dir b.src_dir + | x -> x) |> fun x -> match x, db.parent with | [], None -> Ok None | [], Some db -> find_implementation_for db lib ~variants diff --git a/src/stdune/list.ml b/src/stdune/list.ml index 02b688112aa..8e1aea6436d 100644 --- a/src/stdune/list.ml +++ b/src/stdune/list.ml @@ -111,6 +111,9 @@ let sort t ~compare = let stable_sort t ~compare = stable_sort t ~cmp:(fun a b -> Ordering.to_int (compare a b)) +let sort_uniq t ~compare = + sort_uniq t ~cmp:(fun a b -> Ordering.to_int (compare a b)) + let rec compare a b ~compare:f : Ordering.t = match a, b with | [], [] -> Eq diff --git a/src/stdune/list.mli b/src/stdune/list.mli index 088f19c3f8a..5ae2cf09dee 100644 --- a/src/stdune/list.mli +++ b/src/stdune/list.mli @@ -41,6 +41,7 @@ val destruct_last : 'a t -> ('a list * 'a) option val sort : 'a t -> compare:('a -> 'a -> Ordering.t) -> 'a t val stable_sort : 'a t -> compare:('a -> 'a -> Ordering.t) -> 'a t +val sort_uniq : 'a t -> compare:('a -> 'a -> Ordering.t) -> 'a t val compare : 'a t -> 'a t -> compare:('a -> 'a -> Ordering.t) -> Ordering.t diff --git a/test/blackbox-tests/test-cases/variants/run.t b/test/blackbox-tests/test-cases/variants/run.t index 3b0ddc07326..34063c17084 100644 --- a/test/blackbox-tests/test-cases/variants/run.t +++ b/test/blackbox-tests/test-cases/variants/run.t @@ -82,12 +82,3 @@ Solving variant ambiguity by specifying a concrete implementation. Don't fail when the same library is defined in multiple scopes. $ dune build --root same-lib-in-multiple-scopes Entering directory 'same-lib-in-multiple-scopes' - File "dune", line 3, characters 12-16: - 3 | (variants unix) - ^^^^ - Error: Multiple solutions for the implementation - of test with variants [ "unix" ] - -> test-unix ("unix") - -> test-unix ("unix") - -> required by executable exe in dune:2 - [1]