ocamlPackages.findlib: detect conflicts of version early

just like pythonCatchConflictHook
This commit is contained in:
Guillaume Girol 2022-12-11 12:00:00 +00:00
parent 3302bc3ddd
commit 6043e3af4e
2 changed files with 18 additions and 0 deletions

View File

@ -129,3 +129,8 @@ packaged libraries may still use the old spelling: maintainers are invited to
fix this when updating packages. Massive renaming is strongly discouraged as it
would be challenging to review, difficult to test, and will cause unnecessary
rebuild.
The build will automatically fail if two distinct versions of the same library
are added to `buildInputs` (which usually happens transitively because of
`propagatedBuildInputs`). Set `dontDetectOcamlConflicts` to true to disable this
behavior.

View File

@ -44,6 +44,15 @@ stdenv.mkDerivation rec {
mkdir -p $OCAMLFIND_DESTDIR
fi
}
detectOcamlConflicts () {
local conflict
conflict="$(ocamlfind list |& grep "has multiple definitions" || true)"
if [[ -n "$conflict" ]]; then
echo "Conflicting ocaml packages detected";
echo "$conflict"
exit 1
fi
}
# run for every buildInput
addEnvHooks "$targetOffset" addOCamlPath
@ -51,6 +60,10 @@ stdenv.mkDerivation rec {
preInstallHooks+=(createOcamlDestDir)
# run even in nix-shell, and even without buildInputs
addEnvHooks "$hostOffset" exportOcamlDestDir
# runs after all calls to addOCamlPath
if [[ -z "''${dontDetectOcamlConflicts-}" ]]; then
postHooks+=("detectOcamlConflicts")
fi
'';
meta = {