1 # set of utilities that assure the cwd of a build
2 # is completely clean after the build, meaning all
3 # files were either discarded or moved to outputs.
4 # This ensures nothing is forgotten and new files
5 # are correctly handled on update.
6 { lib, stdenv, file, writeScript }:
9 globWith = lib.concatMapStringsSep "\n";
10 rmNoise = noiseGlobs: globWith (f:
11 "rm -rf ${f}") noiseGlobs;
12 mvDoc = docGlobs: globWith
13 (f: ''mv ${f} "$DOCDIR" 2>/dev/null || true'')
16 # Shell script that implements common move & remove actions
17 # $1 is the doc directory (will be created).
18 # Best used in conjunction with checkForRemainingFiles
20 { # list of fileglobs that are removed from the source dir
22 # files that are moved to the doc directory ($1)
23 # TODO(Profpatsch): allow to set target dir with
24 # { glob = …; to = "html" } (relative to docdir)
26 writeScript "common-file-actions.sh" ''
29 DOCDIR="''${1?commonFileActions: DOCDIR as argv[1] required}"
30 shopt -s globstar extglob nullglob
36 # Shell script to check whether the build directory is empty.
37 # If there are still files remaining, exit 1 with a helpful
38 # listing of all remaining files and their types.
39 checkForRemainingFiles = writeScript "check-for-remaining-files.sh" ''
41 echo "Checking for remaining source files"
42 rem=$(find -mindepth 1 -xtype f -print0 \
43 | tee $TMP/remaining-files)
44 if [[ "$rem" != "" ]]; then
45 echo "ERROR: These files should be either moved or deleted:"
46 cat $TMP/remaining-files | xargs -0 ${file}/bin/file
52 inherit commonFileActions checkForRemainingFiles;