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.
14 globWith = lib.concatMapStringsSep "\n";
15 rmNoise = noiseGlobs: globWith (f: "rm -rf ${f}") noiseGlobs;
16 mvDoc = docGlobs: globWith (f: ''mv ${f} "$DOCDIR" 2>/dev/null || true'') docGlobs;
18 # Shell script that implements common move & remove actions
19 # $1 is the doc directory (will be created).
20 # Best used in conjunction with checkForRemainingFiles
23 # list of fileglobs that are removed from the source dir
25 # files that are moved to the doc directory ($1)
26 # TODO(Profpatsch): allow to set target dir with
27 # { glob = …; to = "html" } (relative to docdir)
30 writeScript "common-file-actions.sh" ''
33 DOCDIR="''${1?commonFileActions: DOCDIR as argv[1] required}"
34 shopt -s globstar extglob nullglob
40 # Shell script to check whether the build directory is empty.
41 # If there are still files remaining, exit 1 with a helpful
42 # listing of all remaining files and their types.
43 checkForRemainingFiles = writeScript "check-for-remaining-files.sh" ''
45 echo "Checking for remaining source files"
46 rem=$(find -mindepth 1 -xtype f -print0 \
47 | tee $TMP/remaining-files)
48 if [[ "$rem" != "" ]]; then
49 echo "ERROR: These files should be either moved or deleted:"
50 cat $TMP/remaining-files | xargs -0 ${file}/bin/file
57 inherit commonFileActions checkForRemainingFiles;