dune-build-info: spurious `git describe` output instead of version string
Context
Build of a package for an ocaml product, where the source tarball gets unpacked in a build tree inside a git-managed tree. In our case it is a RPM build, but the default setup for a Yocto tree would be similar.
Expected Behavior
When dune-project has a (version whatever) statement, this doc makes me expect to get that that version in build_info
Actual Behavior
The binaries get a git describe string instead of the version specified in dune-project.
On a CentOS 7 base, this happens only when the git tree is actually dirty, which makes me wonder whether the doc matches the actual behavior; on AlmaLinux 10 with the same ocaml and dune versions starting with the same clean git tree, after the dune install run the tree is seen as dirty with no actual diff (by git diff-index HEAD and gitk), and git update-index --refresh (or git status) syncs back the index and confirms no actual diff is present.
Since the git tree under which the build occurs is not the one for the package, it would make sense to use the GIT_CEILING_DIRECTORIES envvar to prevent git from looking in the directory above the one containing dune-project. This could possibly be a job for dune itself, but as of today I would have to set it myself... but AFAICT this envvar does not get propagated by dune to child processes, so this workaround is also unavailable.
- even with a
versionstatement indune-projecta call togit describeis issued - as an added woe, setting
GIT_CEILING_DIRECTORIESin environment to protect fromgit describelooking at an unrelated history has no effect (could it be that https://github.com/ocaml/dune/blob/3fc17eec135ab67a514c1cbb02182f7bccf6d042/boot/duneboot.ml#L218 purges the environment?)
Reproduction
Starting from a dune init project and adding the code from the doc, my reproduction attempts are blocked by the lack of DUNE_PLACEHOLDER in the resulting binary - however, the program indeed accesses the version, as if the version string was hardcoded from the start. Help on this gladly accepted :)
Specifications
- Version of
dune(output ofdune --version): 3.15.3 - Version of
ocaml(output ofocamlc --version): 4.14.2 - Operating system (distribution and version): AlmaLinux 10 beta (and CentOS 7)
Additional information
For now the only workaround seem to be patching the dune-installed binaries to replace the spurious git describe output with the actual version string.
Wrapping up
There are indeed several items coming out of the initial symptom, maybe it would be worth opening separate issues for those?
- undocumented precedence of
git describeon explicit version when the tree is dirty - lack of ability to use
DUNE_PLACEHOLDERenvvar - possible use of
DUNE_PLACEHOLDERdirectly bydune dune installdirtying the git tree- reproduction of
DUNE_PLACEHOLDERuse (and possibly extend the documentation to help with its understanding)
Up?