nix: add withTmpDir to checked-shell-script

This commit is contained in:
Wolfgang Walther
2021-04-12 19:03:16 +02:00
committed by Wolfgang Walther
parent 579a626de2
commit fc791a6320
3 changed files with 17 additions and 16 deletions
+2 -4
View File
@@ -105,17 +105,16 @@ let
name = "postgrest-dump-minimal-imports";
docs = "Dump minimal imports into given directory.";
inRootDir = true;
withTmpDir = true;
}
''
dumpdir="''${1:?dumpdir not set}"
tmpdir="$(mktemp -d)"
mkdir -p "$dumpdir"
${cabal-install}/bin/cabal v2-build ${devCabalOptions} \
--builddir="$tmpdir" \
--ghc-option=-ddump-minimal-imports \
--ghc-option=-dumpdir="$dumpdir" \
1>&2
rm -rf "$tmpdir"
# Fix OverloadedRecordFields imports
# shellcheck disable=SC2016
@@ -127,12 +126,11 @@ let
{
name = "postgrest-hsie-minimal-imports";
docs = "Run hsie with a provided dump of minimal imports.";
withTmpDir = true;
}
''
tmpdir="$(mktemp -d)"
${dumpMinimalImports} "$tmpdir"
${hsie} "$tmpdir" "$@"
rm -rf "$tmpdir"
'';
hsieGraphModules =
@@ -9,7 +9,7 @@
, stdenv
, writeTextFile
}:
{ name, docs, inRootDir ? false }: text:
{ name, docs, inRootDir ? false, withTmpDir ? false }: text:
# TODO: do something sensible with docs, e.g. provide automated --help
let
bin =
@@ -40,7 +40,19 @@ let
exit 1
fi
''
+ "(${text})";
+ lib.optionalString withTmpDir ''
tmpdir="$(mktemp -d)"
# we keep the tmpdir when an error occurs for debugging
trap 'echo Temporary directory kept at: $tmpdir' ERR
# remove the tmpdir when cancelled (postgrest-watch)
trap 'rm -rf "$tmpdir"' SIGINT SIGTERM
''
+ "(${text})"
+ lib.optionalString withTmpDir ''
rm -rf "$tmpdir"
'';
checkPhase =
''
+1 -10
View File
@@ -174,6 +174,7 @@ let
inherit name;
docs = "Run spec and io tests while collecting hpc coverage data.";
inRootDir = true;
withTmpDir = true;
}
''
env="$(cat ${postgrest.env})"
@@ -184,14 +185,6 @@ let
mkdir -p coverage
rm -rf coverage/*
# temporary directory to collect data in
tmpdir="$(mktemp -d)"
# we keep the tmpdir when an error occurs for debugging
trap 'echo Temporary directory kept at: $tmpdir' ERR
# remove the tmpdir when cancelled (postgrest-watch)
trap 'rm -rf "$tmpdir"' SIGINT SIGTERM
# build once before running all the tests
${cabal-install}/bin/cabal v2-build ${devCabalOptions} --enable-tests all
@@ -234,8 +227,6 @@ let
echo "file://$(pwd)/coverage/hpc_index.html"
${ghc}/bin/hpc report coverage/postgrest.tix "$@"
fi
rm -rf "$tmpdir"
'';
coverageDraftOverlay =