mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 21:33:03 +03:00
build-support/skaware: factor out clean packaging utils
They are useful for other packages as well.
This commit is contained in:
parent
4266523c14
commit
61c22bcc0e
@ -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 = {
|
||||
|
53
pkgs/build-support/skaware/clean-packaging.nix
Normal file
53
pkgs/build-support/skaware/clean-packaging.nix
Normal file
@ -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;
|
||||
}
|
@ -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 { };
|
||||
|
Loading…
Reference in New Issue
Block a user