diff --git a/nix/devtools.nix b/nix/devtools.nix index cf5ea8094..2dc43e22b 100644 --- a/nix/devtools.nix +++ b/nix/devtools.nix @@ -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 = diff --git a/nix/overlays/checked-shell-script/checked-shell-script.nix b/nix/overlays/checked-shell-script/checked-shell-script.nix index 4e21d26db..a7fa8c95d 100644 --- a/nix/overlays/checked-shell-script/checked-shell-script.nix +++ b/nix/overlays/checked-shell-script/checked-shell-script.nix @@ -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 = '' diff --git a/nix/tests.nix b/nix/tests.nix index 050712290..2334bc069 100644 --- a/nix/tests.nix +++ b/nix/tests.nix @@ -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 =