Skip to content

Commit

Permalink
Merge pull request #1999 from TheLortex/fix-variants
Browse files Browse the repository at this point in the history
Fix variants
  • Loading branch information
rgrinberg authored Apr 3, 2019
2 parents 126177d + 8b70d74 commit 9f6daf1
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/stdune/caml/dune_caml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Lexing = Lexing
module Digest = Digest
module StringLabels = StringLabels
module ListLabels = ListLabels
module List = List

type ('a, 'error) result = ('a, 'error) Result.t =
| Ok of 'a
Expand Down
3 changes: 3 additions & 0 deletions src/stdune/list.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Dune_caml.List.sort_uniq (fun a b -> Ordering.to_int (compare a b)) t

let rec compare a b ~compare:f : Ordering.t =
match a, b with
| [], [] -> Eq
Expand Down
1 change: 1 addition & 0 deletions src/stdune/list.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions test/blackbox-tests/test-cases/variants/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ Solving variant ambiguity by specifying a concrete implementation.
Entering directory 'variant-with-concrete-impl'
bar alias default
hello from lib2.default

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'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(executable
(name exe)
(variants unix)
(libraries test))

(alias
(name default)
(action
(run ./exe.exe)))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.9)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.9)
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(name test_unix)
(public_name test-unix)
(implements test)
(variant unix))
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(name test)
(public_name test)
(virtual_modules foo))
Empty file.

0 comments on commit 9f6daf1

Please sign in to comment.