crane/checks/compilesFresh.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.3 KiB
Nix
Raw Normal View History

{ buildDepsOnly
, jq
}:
expectedArg: mkDrv: args:
let
runCargoAndCheckFreshness = cmd: extra:
let
expected =
if builtins.isAttrs expectedArg then
expectedArg.${cmd} or ""
else
expectedArg;
in
''
cargo ${cmd} \
--release \
--message-format json-diagnostic-short \
${extra} \
${args.cargoExtraArgs or ""} >${cmd}out
2022-11-21 03:28:49 +03:00
filter='select(.reason == "compiler-artifact" and .fresh != true) | .target.name'
2021-12-31 07:12:52 +03:00
builtTargets="$(jq -r "$filter" <${cmd}out | sort -u)"
2022-11-21 03:28:49 +03:00
# Make sure only the crate needed building
2021-12-31 07:12:52 +03:00
if [[ "${expected}" != "$builtTargets" ]]; then
echo for command ${cmd}
2021-12-31 07:12:52 +03:00
echo expected \""${expected}"\"
echo but got \""$builtTargets"\"
false
fi
'';
in
mkDrv (args // {
doInstallCargoArtifacts = false;
2021-12-31 07:12:52 +03:00
# NB: explicit call here so that the buildDepsOnly call
# doesn't inherit our build commands
cargoArtifacts = buildDepsOnly args;
nativeBuildInputs = [ jq ];
buildPhase = ''
runHook preBuild
${runCargoAndCheckFreshness "check" ""}
${runCargoAndCheckFreshness "build" ""}
runHook postBuild
'';
checkPhase = ''
runHook preCheck
${runCargoAndCheckFreshness "test" "--no-run"}
runHook postCheck
'';
installPhase = ''
touch $out
'';
})