summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2019-02-24 14:40:10 +0100
committerProfpatsch <mail@profpatsch.de>2019-02-25 10:34:16 +0100
commit61c22bcc0efd8267642ea06acbb30ab10a2ecd83 (patch)
tree7b5b003219f476dd601cb6b3b5557223d28fc319 /pkgs/build-support
parent4266523c141518ecf560a1ff616c6e865607f090 (diff)
build-support/skaware: factor out clean packaging utils
They are useful for other packages as well.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/skaware/build-skaware-package.nix36
-rw-r--r--pkgs/build-support/skaware/clean-packaging.nix53
2 files changed, 59 insertions, 30 deletions
diff --git a/pkgs/build-support/skaware/build-skaware-package.nix b/pkgs/build-support/skaware/build-skaware-package.nix
index 5ae8985e3abe..e4712a5ef22c 100644
--- a/pkgs/build-support/skaware/build-skaware-package.nix
+++ b/pkgs/build-support/skaware/build-skaware-package.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, writeScript, file }:
+{ stdenv, callPackage, cleanPackaging, fetchurl, writeScript, file }:
let lib = stdenv.lib;
in {
# : string
@@ -54,25 +54,6 @@ let
"README.*"
];
- globWith = stdenv.lib.concatMapStringsSep "\n";
- rmNoise = globWith (f:
- ''rm -rf ${f}'') commonNoiseFiles;
- mvMeta = globWith
- (f: ''mv ${f} "$DOCDIR" 2>/dev/null || true'')
- commonMetaFiles;
-
- # Move & remove actions, taking the package doc directory
- commonFileActions = writeScript "common-file-actions.sh" ''
- #!${stdenv.shell}
- set -e
- DOCDIR="$1"
- shopt -s globstar extglob nullglob
- ${rmNoise}
- mkdir -p "$DOCDIR"
- ${mvMeta}
- '';
-
-
in stdenv.mkDerivation {
name = "${pname}-${version}";
@@ -105,21 +86,16 @@ in stdenv.mkDerivation {
# TODO(Profpatsch): ensure that there is always a $doc output!
postInstall = ''
echo "Cleaning & moving common files"
- mkdir -p $doc/share/doc/${pname}
- ${commonFileActions} $doc/share/doc/${pname}
+ ${cleanPackaging.commonFileActions {
+ noiseFiles = commonNoiseFiles;
+ docFiles = commonMetaFiles;
+ }} $doc/share/doc/${pname}
${postInstall}
'';
postFixup = ''
- echo "Checking for remaining source files"
- rem=$(find -mindepth 1 -xtype f -print0 \
- | tee $TMP/remaining-files)
- if [[ "$rem" != "" ]]; then
- echo "ERROR: These files should be either moved or deleted:"
- cat $TMP/remaining-files | xargs -0 ${file}/bin/file
- exit 1
- fi
+ ${cleanPackaging.checkForRemainingFiles}
'';
meta = {
diff --git a/pkgs/build-support/skaware/clean-packaging.nix b/pkgs/build-support/skaware/clean-packaging.nix
new file mode 100644
index 000000000000..16bae04b21e2
--- /dev/null
+++ b/pkgs/build-support/skaware/clean-packaging.nix
@@ -0,0 +1,53 @@
+# set of utilities that assure the cwd of a build
+# is completely clean after the build, meaning all
+# files were either discarded or moved to outputs.
+# This ensures nothing is forgotten and new files
+# are correctly handled on update.
+{ stdenv, file, writeScript }:
+
+let
+ globWith = stdenv.lib.concatMapStringsSep "\n";
+ rmNoise = noiseGlobs: globWith (f:
+ ''rm -rf ${f}'') noiseGlobs;
+ mvDoc = docGlobs: globWith
+ (f: ''mv ${f} "$DOCDIR" 2>/dev/null || true'')
+ docGlobs;
+
+ # Shell script that implements common move & remove actions
+ # $1 is the doc directory (will be created).
+ # Best used in conjunction with checkForRemainingFiles
+ commonFileActions =
+ { # list of fileglobs that are removed from the source dir
+ noiseFiles
+ # files that are moved to the doc directory ($1)
+ # TODO(Profpatsch): allow to set target dir with
+ # { glob = …; to = "html" } (relative to docdir)
+ , docFiles }:
+ writeScript "common-file-actions.sh" ''
+ #!${stdenv.shell}
+ set -e
+ DOCDIR="$1"
+ shopt -s globstar extglob nullglob
+ ${rmNoise noiseFiles}
+ mkdir -p "$DOCDIR"
+ ${mvDoc docFiles}
+ '';
+
+ # Shell script to check whether the build directory is empty.
+ # If there are still files remaining, exit 1 with a helpful
+ # listing of all remaining files and their types.
+ checkForRemainingFiles = writeScript "check-for-remaining-files.sh" ''
+ #!${stdenv.shell}
+ echo "Checking for remaining source files"
+ rem=$(find -mindepth 1 -xtype f -print0 \
+ | tee $TMP/remaining-files)
+ if [[ "$rem" != "" ]]; then
+ echo "ERROR: These files should be either moved or deleted:"
+ cat $TMP/remaining-files | xargs -0 ${file}/bin/file
+ exit 1
+ fi
+ '';
+
+in {
+ inherit commonFileActions checkForRemainingFiles;
+}