Consider the following file structure in a dune project:
...
src/
|
+-- analysis/
|
+-- file.mli
|
+-- file.enabled.ml
|
+-- file.disabled.ml
That is, I have an src
folder with an analysis
subfolder containing two versions of the File module, plus its interface. The choice depends on whether package ocamlgraph
is available. Therefore, I tried the following stanza in src/dune
:
(library
(name test)
(libraries
(select analysis/file.ml from
(ocamlgraph -> analysis/file.enabled.ml)
( -> analysis/file.disabled.ml)
)
)
)
(include_subdirs unqualified)
However, this fails with:
Error: Some modules don't have an implementation.
You need to add the following field to this stanza:
(modules_without_implementation file)
The suggestion does not work in my case (the modules do have an implementation, it's just that Dune couldn't find it). If I add it, I get:
Error: test__Analysis/file corresponds to an invalid module name
-> required by _build/default/src/test.ml-gen
The real issue seems to be that apparently Dune ignores the analysis/
from the first part of the select
stanza? I then tried removing it:
(library
(name test)
(libraries
(select file.ml from
(ocamlgraph -> analysis/file.enabled.ml)
( -> analysis/file.disabled.ml)
)
)
)
(include_subdirs unqualified)
But now, dune build
fails with:
File "src/dune", line 5, characters 18-42:
5 | (ocamlgraph -> analysis/file.enabled.ml)
^^^^^^^^^^^^^^^^^^^^^^^^
Error: The format for files in this select branch must be file.{name}.ml
Of course, if I remove the analysis/
everywhere, it doesn't work. Either because file.mli
is still in analysis
, thus causing:
Error: Module "File" appears in several directories:
- _build/default/src
- _build/default/src/analysis
This is not allowed, please rename one of them.
Or, if I move it to src
, the error is, as expected:
Error: No rule found for src/file.enabled.ml
Since, of course, src/file.enabled.ml
does not exist.
The only way I can make Dune work is to remove the analysis
directory altogether, flattening out the structure (which I want to avoid). But it seems like it should be possible to use select
even in the presence of file names with subdirectories. Is it possible? If so, how?
Reproduction script
In case it helps, here's a script to quickly test changes to the dune
file.
dune init project proj
cd proj
mkdir -p src/analysis
echo "val f : int -> int" > src/analysis/file.mli
echo "let f i = i + 1" > src/analysis/file.enabled.ml
echo "let f _i = 0" > src/analysis/file.disabled.ml
cat >src/dune <<EOF
(library
(name test)
(libraries
(select analysis/file.ml from
(ocamlgraph -> analysis/file.enabled.ml)
( -> analysis/file.disabled.ml)
)
)
)
(include_subdirs unqualified)
EOF
dune build