Dune build only specified directories




For the setting:


(where the b-0.* depend on a)
I would like to know if there’s a way to tell Dune to ignore folder b-0.1/ for example, when building b-0.2/. At the moment I could only do building if removing the opam files and using “wrapped” field (tho I think this is not advisable since not intended for that purpose…) for the b-*'s. Since I would like to install package a and b (only one version of b of course…), then Dune complains righteously in various ways:

(with prev. setting)
$ dune build b-0.2
Info: creating file b-0.2/dune-project with this contents: (lang dune 1.5)
Too many opam files for package “b”:

  • b-0.2/b.opam
  • b-0.1/b.opam

(when having one b.opam file at the root and giving the libraries public_name b.b)
$ dune build b-0.1/
Public library “b.b” is defined twice:

  • b-0.2/dune:1
  • b-0.1/dune:1

I thought on using:

  • build profiles, but seems they are just for adding flags for example when wanting a customised building
  • aliases, but so far only found examples for running actions such as, running a tool to make tests on files
  • the option --only package but, in my case both packages b’s are named the same :confused:

From this conversation:

seems like running test in a particular directory is supported, but maybe it would be the same issue since, I would like Dune to consider folder a-0.1 for the dependency, but to ignore b-0.1 when building b-0.2 (or consider a-0.1 and ignore b-0.2 to build b-0.1).

Hope is not that much confusing…


Have you tried the --only-packages command line option? If you pass --only-packages a,b-0.2, then dune will ignore any stanza that is part of a package other than a or b-0.2. So it will effectively ignore most of the dune files in b-0.1.


thank you for the prompt reply!

(rough guess: maybe what I’m after is out of the scope of building tools in general, since normally is done manually and so no need to support it…)

Issue is that, in the building there should be just one library b at the same time. And so, in the directories b-0.1 and b-0.2 the library b is declared. I’m trying to say that the library is not called b-0.1 nor b-0.2 but only b.

The use-case that I’m trying to satisfy is when having the libraries a and b working, but another developer modifies the library b (so creates b-0.2 directory and renames the b/ to b-0.1/) and would like to build the system not with b-0.1 but with b-0.2 and without renaming everywhere the version of its new implemented library. I guess manually one would just delete b/ and create b-0.2/ and all would work (including new things that may depend as well on b).


I see. The simplest solution is to tell Dune to ignore one of the sub-directory via an (ignored_subdirs (b-0.X)) stanza. Then you just need to edit this stanza to choose which library to use.