Skip to content

Commit

Permalink
Fix bigarray config ocaml#5494
Browse files Browse the repository at this point in the history
"Select" rule prevent the case when we endup on require and forbiden
empty. Skipping bigarray could result having require and forbiden empty
that case is the same as no literals "(_ -> dummy)".

Some test-cases for "Direct", "Re-export" and "Select"

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
  • Loading branch information
moyodiallo authored and emillon committed May 24, 2022
1 parent 089579a commit 87fff6c
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 23 deletions.
40 changes: 25 additions & 15 deletions src/dune_rules/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,8 @@ end = struct
let forbidden = Lib_name.Set.to_list forbidden in
if
List.exists
~f:(fun lib -> is_bigarray lib && bigarray_in_std_libraries)
~f:(fun lib ->
is_bigarray lib && not bigarray_in_std_libraries)
forbidden
then Memo.return None
else
Expand All @@ -1228,21 +1229,30 @@ end = struct
in
if exists then Memo.return None
else
let required =
Lib_name.Set.filter
~f:(fun lib ->
(not (is_bigarray lib)) || bigarray_in_std_libraries)
required
let found, required =
( Lib_name.Set.mem required (Lib_name.of_string "bigarray")
, Lib_name.Set.filter
~f:(fun lib ->
(not (is_bigarray lib)) || bigarray_in_std_libraries)
required )
in
Resolve.Memo.peek
(let deps =
Lib_name.Set.fold required ~init:[] ~f:(fun x acc ->
(loc, x) :: acc)
in
resolve_simple_deps ~private_deps db deps)
>>| function
| Ok ts -> Some (ts, file)
| Error () -> None)
if
Lib_name.Set.is_empty required
&& found
&& not bigarray_in_std_libraries
then Memo.return None
(*avoid the case where forbidden and required are empty, so
it switch in case "(_ -> dummy)"*)
else
Resolve.Memo.peek
(let deps =
Lib_name.Set.fold required ~init:[] ~f:(fun x acc ->
(loc, x) :: acc)
in
resolve_simple_deps ~private_deps db deps)
>>| function
| Ok ts -> Some (ts, file)
| Error () -> None)
in
let get which =
let res = select |> Option.map ~f:which in
Expand Down
8 changes: 0 additions & 8 deletions test/blackbox-tests/test-cases/bigarray-select.t

This file was deleted.

3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/a/a.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let _c = Bigarray.C_layout_typ

let () = Printf.eprintf "Welcome to a\n%!"
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/a/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name a)
(libraries bigarray))
4 changes: 4 additions & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/b/b.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let _c1 = B_lib.v
let _c2 = Bigarray.C_layout_typ

let () = Printf.eprintf "Welcome to b\n%!"
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/b/b_lib.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let v = Bigarray.C_layout_typ
9 changes: 9 additions & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/b/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(library
(name b_lib)
(libraries (re_export bigarray))
(modules b_lib))

(executable
(name b)
(libraries b_lib)
(modules b))
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/c/c.bigarray.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let _c = Bigarray.C_layout_typ

let () = Printf.eprintf "Welcome to c WITH bigarray support\n%!"
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/c/c.dummy.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = Printf.eprintf "Welcome to c with nothing inferred\n%!"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = Printf.eprintf "Welcome to c WITHOUT bigarray support\n%!"
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/c/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name c)
(libraries (select c.ml from (!bigarray -> c.nobigarray.ml) (bigarray -> c.bigarray.ml) ( -> c.dummy.ml))))
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 3.0)

(implicit_transitive_deps false)
19 changes: 19 additions & 0 deletions test/blackbox-tests/test-cases/bigarray-skip/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Bigarray library is included in the Standard libraries since OCaml 5.00.0.
And now dune skip it by #5526 PR when included in libraries doing like "(libraries bigarray)".

$ dummy="_build/default/c/c.dummy.ml"
$ found="$(ocamlfind query bigarray -p-format)_found"
$ cat > done.sh <<EOF
> #!/usr/bin/env bash
> if [[ "$found" != "bigarray_found" && -e $dummy ]]; then
> echo "Success skipping bigarray"
> elif [[ "$found" != "bigarray_found" && ! -e $dummy ]]; then
> echo "Fail skipping bigarray"
> else
> echo "Success skipping bigarray"
> fi
> EOF
$ dune build @install
$ chmod +x done.sh
$ ./done.sh
Success skipping bigarray

0 comments on commit 87fff6c

Please sign in to comment.