diff options
author | Profpatsch <mail@profpatsch.de> | 2019-02-24 14:40:10 +0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2019-02-25 10:34:16 +0100 |
commit | 61c22bcc0efd8267642ea06acbb30ab10a2ecd83 (patch) | |
tree | 7b5b003219f476dd601cb6b3b5557223d28fc319 | |
parent | 4266523c141518ecf560a1ff616c6e865607f090 (diff) |
build-support/skaware: factor out clean packaging utils
They are useful for other packages as well.
-rw-r--r-- | pkgs/build-support/skaware/build-skaware-package.nix | 36 | ||||
-rw-r--r-- | pkgs/build-support/skaware/clean-packaging.nix | 53 | ||||
-rw-r--r-- | pkgs/top-level/all-packages.nix | 7 |
3 files changed, 64 insertions, 32 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; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 4ca0101f3096..0763e09ed9f1 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -12538,8 +12538,11 @@ in skalibs = skawarePackages.skalibs; - skawarePackages = recurseIntoAttrs { - buildPackage = callPackage ../build-support/skaware/build-skaware-package.nix { }; + skawarePackages = recurseIntoAttrs rec { + cleanPackaging = callPackage ../build-support/skaware/clean-packaging.nix { }; + buildPackage = callPackage ../build-support/skaware/build-skaware-package.nix { + inherit cleanPackaging; + }; skalibs = callPackage ../development/libraries/skalibs { }; execline = callPackage ../tools/misc/execline { }; |