Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

build-support/skaware: factor out clean packaging utils

They are useful for other packages as well.

+64 -32
+6 -30
pkgs/build-support/skaware/build-skaware-package.nix
··· 1 - { stdenv, fetchurl, writeScript, file }: 1 + { stdenv, callPackage, cleanPackaging, fetchurl, writeScript, file }: 2 2 let lib = stdenv.lib; 3 3 in { 4 4 # : string ··· 54 54 "README.*" 55 55 ]; 56 56 57 - globWith = stdenv.lib.concatMapStringsSep "\n"; 58 - rmNoise = globWith (f: 59 - ''rm -rf ${f}'') commonNoiseFiles; 60 - mvMeta = globWith 61 - (f: ''mv ${f} "$DOCDIR" 2>/dev/null || true'') 62 - commonMetaFiles; 63 - 64 - # Move & remove actions, taking the package doc directory 65 - commonFileActions = writeScript "common-file-actions.sh" '' 66 - #!${stdenv.shell} 67 - set -e 68 - DOCDIR="$1" 69 - shopt -s globstar extglob nullglob 70 - ${rmNoise} 71 - mkdir -p "$DOCDIR" 72 - ${mvMeta} 73 - ''; 74 - 75 - 76 57 in stdenv.mkDerivation { 77 58 name = "${pname}-${version}"; 78 59 ··· 105 86 # TODO(Profpatsch): ensure that there is always a $doc output! 106 87 postInstall = '' 107 88 echo "Cleaning & moving common files" 108 - mkdir -p $doc/share/doc/${pname} 109 - ${commonFileActions} $doc/share/doc/${pname} 89 + ${cleanPackaging.commonFileActions { 90 + noiseFiles = commonNoiseFiles; 91 + docFiles = commonMetaFiles; 92 + }} $doc/share/doc/${pname} 110 93 111 94 ${postInstall} 112 95 ''; 113 96 114 97 postFixup = '' 115 - echo "Checking for remaining source files" 116 - rem=$(find -mindepth 1 -xtype f -print0 \ 117 - | tee $TMP/remaining-files) 118 - if [[ "$rem" != "" ]]; then 119 - echo "ERROR: These files should be either moved or deleted:" 120 - cat $TMP/remaining-files | xargs -0 ${file}/bin/file 121 - exit 1 122 - fi 98 + ${cleanPackaging.checkForRemainingFiles} 123 99 ''; 124 100 125 101 meta = {
+53
pkgs/build-support/skaware/clean-packaging.nix
··· 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 + { stdenv, file, writeScript }: 7 + 8 + let 9 + globWith = stdenv.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'') 14 + docGlobs; 15 + 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 19 + commonFileActions = 20 + { # list of fileglobs that are removed from the source dir 21 + noiseFiles 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) 25 + , docFiles }: 26 + writeScript "common-file-actions.sh" '' 27 + #!${stdenv.shell} 28 + set -e 29 + DOCDIR="$1" 30 + shopt -s globstar extglob nullglob 31 + ${rmNoise noiseFiles} 32 + mkdir -p "$DOCDIR" 33 + ${mvDoc docFiles} 34 + ''; 35 + 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" '' 40 + #!${stdenv.shell} 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 47 + exit 1 48 + fi 49 + ''; 50 + 51 + in { 52 + inherit commonFileActions checkForRemainingFiles; 53 + }
+5 -2
pkgs/top-level/all-packages.nix
··· 12538 12538 12539 12539 skalibs = skawarePackages.skalibs; 12540 12540 12541 - skawarePackages = recurseIntoAttrs { 12542 - buildPackage = callPackage ../build-support/skaware/build-skaware-package.nix { }; 12541 + skawarePackages = recurseIntoAttrs rec { 12542 + cleanPackaging = callPackage ../build-support/skaware/clean-packaging.nix { }; 12543 + buildPackage = callPackage ../build-support/skaware/build-skaware-package.nix { 12544 + inherit cleanPackaging; 12545 + }; 12543 12546 12544 12547 skalibs = callPackage ../development/libraries/skalibs { }; 12545 12548 execline = callPackage ../tools/misc/execline { };