bscpkgs/garlic/stages/control.nix

53 lines
915 B
Nix
Raw Normal View History

2020-08-11 18:05:43 +08:00
{
stdenv
2020-10-09 21:55:37 +08:00
, garlicTools
2020-08-11 18:05:43 +08:00
}:
2020-09-02 23:07:09 +08:00
{
2020-10-09 21:55:37 +08:00
nextStage
2020-09-03 22:18:50 +08:00
, loops ? 30
2020-09-02 23:07:09 +08:00
}:
2020-08-11 18:05:43 +08:00
2020-10-09 21:55:37 +08:00
with garlicTools;
2020-08-11 18:05:43 +08:00
stdenv.mkDerivation {
2020-09-02 23:07:09 +08:00
name = "control";
2020-08-11 18:05:43 +08:00
preferLocalBuild = true;
phases = [ "installPhase" ];
dontPatchShebangs = true;
installPhase = ''
2021-02-08 21:14:08 +08:00
cat > $out <<"EOF"
#!/bin/sh -e
2021-04-16 15:16:03 +08:00
function badexit() {
errcode=$?
if [ $errcode != 0 ]; then
printf "exit %d\n" $errcode > "$basedir/status"
echo "exiting with $errcode"
fi
echo 1 > "$basedir/done"
exit $errcode
}
trap badexit EXIT
basedir=$(pwd)
loops=${toString loops}
for n in $(seq 1 $loops); do
2021-02-08 21:14:08 +08:00
export GARLIC_RUN="$n"
2021-04-16 15:16:03 +08:00
echo "run $n/$loops" > status
2021-02-08 21:14:08 +08:00
mkdir "$n"
cd "$n"
mkdir .garlic
date +%s > .garlic/total_time_start
2020-10-09 21:55:37 +08:00
${stageProgram nextStage}
2021-02-08 21:14:08 +08:00
date +%s > .garlic/total_time_end
cd ..
2020-08-11 18:05:43 +08:00
done
2021-04-16 15:16:03 +08:00
echo "ok" > status
2020-08-11 18:05:43 +08:00
EOF
2020-09-02 23:07:09 +08:00
chmod +x $out
2020-08-11 18:05:43 +08:00
'';
}