Skip to content

Commit 93ff2a9

Browse files
authored
Fix handling of missing optional directories in findlib (#11569)
* Reword test case to make the problem clearer Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com> * Fix handling of findlib 'exists_if' clause Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com> --------- Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com>
1 parent 5251af8 commit 93ff2a9

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

src/fs/fs.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ let dir_contents (dir : Path.t) =
1616
>>| Result.map ~f:(fun contents ->
1717
Fs_cache.Dir_contents.to_list contents |> List.map ~f:fst)
1818
| `Inside _ ->
19-
let* () = Build_system.build_dir dir in
20-
Memo.return (Path.readdir_unsorted dir)
19+
let* already_exists = Build_system.file_exists dir in
20+
let+ () = if already_exists then Build_system.build_dir dir else Memo.return () in
21+
Path.readdir_unsorted dir
2122
;;
2223

2324
let exists path kind =

test/blackbox-tests/test-cases/pkg/findlib-meta-optional-directory.t

+34-7
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@ Reproduces #11405
77
$ mkdir external_sources
88

99
$ cat >external_sources/META <<EOF
10-
> package "sub" (
11-
> directory = "sub"
10+
> package "yes" (
11+
> directory = "yes"
1212
> version = "0.0.1"
13-
> exists_if = "sub.cma"
13+
> exists_if = "yes.cma"
14+
> )
15+
> package "no" (
16+
> directory = "no"
17+
> version = "0.0.1"
18+
> exists_if = "no.cma"
1419
> )
1520
> EOF
1621

1722
$ cat >external_sources/mypkg.install <<EOF
1823
> lib: [
1924
> "META"
25+
> "yes/yes.cma" {"yes/yes.cma"}
2026
> ]
2127
> EOF
2228

29+
$ mkdir external_sources/yes
30+
$ touch external_sources/yes/yes.cma
31+
2332
$ cat >dune-project <<EOF
2433
> (lang dune 3.17)
2534
> EOF
@@ -35,14 +44,32 @@ Reproduces #11405
3544
> (source (copy $PWD/external_sources))
3645
> EOF
3746

47+
$ touch foo.ml
48+
49+
$ cat >dune <<EOF
50+
> (executable
51+
> (libraries mypkg.yes)
52+
> (name foo))
53+
> EOF
54+
55+
No errors here as 'yes' actually exists
56+
$ dune build foo.exe
57+
3858
$ cat >dune <<EOF
3959
> (executable
40-
> (libraries mypkg.sub)
60+
> (libraries mypkg.no)
4161
> (name foo))
4262
> EOF
4363

64+
Clearer error here as we really depend on non-existing 'no'
4465
$ dune build foo.exe
45-
Error: This rule defines a directory target "default/.pkg/mypkg/target" that
46-
matches the requested path "default/.pkg/mypkg/target/lib/mypkg/sub" but the
47-
rule's action didn't produce it
66+
File "dune", line 2, characters 12-20:
67+
2 | (libraries mypkg.no)
68+
^^^^^^^^
69+
Error: Library "mypkg.no" in
70+
_build/_private/default/.pkg/mypkg/target/lib/mypkg/no is hidden (unsatisfied
71+
'exists_if').
72+
-> required by _build/default/.foo.eobjs/byte/dune__exe__Foo.cmi
73+
-> required by _build/default/.foo.eobjs/native/dune__exe__Foo.cmx
74+
-> required by _build/default/foo.exe
4875
[1]

0 commit comments

Comments
 (0)