aboutsummaryrefslogtreecommitdiff
path: root/infra/libkookie/nixpkgs/pkgs/build-support/skaware
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
committerMx Kookie <kookie@spacekookie.de>2020-10-31 19:35:09 +0100
commitc4625b175f8200f643fd6e11010932ea44c78433 (patch)
treebce3f89888c8ac3991fa5569a878a9eab6801ccc /infra/libkookie/nixpkgs/pkgs/build-support/skaware
parent49f735974dd103039ddc4cb576bb76555164a9e7 (diff)
parentd661aa56a8843e991261510c1bb28fdc2f6975ae (diff)
Add 'infra/libkookie/' from commit 'd661aa56a8843e991261510c1bb28fdc2f6975ae'
git-subtree-dir: infra/libkookie git-subtree-mainline: 49f735974dd103039ddc4cb576bb76555164a9e7 git-subtree-split: d661aa56a8843e991261510c1bb28fdc2f6975ae
Diffstat (limited to 'infra/libkookie/nixpkgs/pkgs/build-support/skaware')
-rw-r--r--infra/libkookie/nixpkgs/pkgs/build-support/skaware/build-skaware-package.nix106
-rw-r--r--infra/libkookie/nixpkgs/pkgs/build-support/skaware/clean-packaging.nix53
2 files changed, 159 insertions, 0 deletions
diff --git a/infra/libkookie/nixpkgs/pkgs/build-support/skaware/build-skaware-package.nix b/infra/libkookie/nixpkgs/pkgs/build-support/skaware/build-skaware-package.nix
new file mode 100644
index 000000000000..e6e2e35789bc
--- /dev/null
+++ b/infra/libkookie/nixpkgs/pkgs/build-support/skaware/build-skaware-package.nix
@@ -0,0 +1,106 @@
+{ stdenv, cleanPackaging, fetchurl }:
+let lib = stdenv.lib;
+in {
+ # : string
+ pname
+ # : string
+, version
+ # : string
+, sha256
+ # : string
+, description
+ # : list Platform
+, platforms ? lib.platforms.all
+ # : list string
+, outputs ? [ "bin" "lib" "dev" "doc" "out" ]
+ # TODO(Profpatsch): automatically infer most of these
+ # : list string
+, configureFlags
+ # mostly for moving and deleting files from the build directory
+ # : lines
+, postInstall
+ # : list Maintainer
+, maintainers ? []
+
+
+}:
+
+let
+
+ # File globs that can always be deleted
+ commonNoiseFiles = [
+ ".gitignore"
+ "Makefile"
+ "INSTALL"
+ "configure"
+ "patch-for-solaris"
+ "src/**/*"
+ "tools/**/*"
+ "package/**/*"
+ "config.mak"
+ ];
+
+ # File globs that should be moved to $doc
+ commonMetaFiles = [
+ "COPYING"
+ "AUTHORS"
+ "NEWS"
+ "CHANGELOG"
+ "README"
+ "README.*"
+ ];
+
+in stdenv.mkDerivation {
+ inherit pname version;
+
+ src = fetchurl {
+ url = "https://skarnet.org/software/${pname}/${pname}-${version}.tar.gz";
+ inherit sha256;
+ };
+
+ inherit outputs;
+
+ dontDisableStatic = true;
+ enableParallelBuilding = true;
+
+ configureFlags = configureFlags ++ [
+ "--enable-absolute-paths"
+ # We assume every nix-based cross target has urandom.
+ # This might not hold for e.g. BSD.
+ "--with-sysdep-devurandom=yes"
+ (if stdenv.isDarwin
+ then "--disable-shared"
+ else "--enable-shared")
+ ]
+ # On darwin, the target triplet from -dumpmachine includes version number,
+ # but skarnet.org software uses the triplet to test binary compatibility.
+ # Explicitly setting target ensures code can be compiled against a skalibs
+ # binary built on a different version of darwin.
+ # http://www.skarnet.org/cgi-bin/archive.cgi?1:mss:623:heiodchokfjdkonfhdph
+ ++ (lib.optional stdenv.isDarwin
+ "--build=${stdenv.hostPlatform.system}");
+
+ # TODO(Profpatsch): ensure that there is always a $doc output!
+ postInstall = ''
+ echo "Cleaning & moving common files"
+ ${cleanPackaging.commonFileActions {
+ noiseFiles = commonNoiseFiles;
+ docFiles = commonMetaFiles;
+ }} $doc/share/doc/${pname}
+
+ ${postInstall}
+ '';
+
+ postFixup = ''
+ ${cleanPackaging.checkForRemainingFiles}
+ '';
+
+ meta = {
+ homepage = "https://skarnet.org/software/${pname}/";
+ inherit description platforms;
+ license = stdenv.lib.licenses.isc;
+ maintainers = with lib.maintainers;
+ [ pmahoney Profpatsch ] ++ maintainers;
+ };
+
+}
diff --git a/infra/libkookie/nixpkgs/pkgs/build-support/skaware/clean-packaging.nix b/infra/libkookie/nixpkgs/pkgs/build-support/skaware/clean-packaging.nix
new file mode 100644
index 000000000000..762fe25c0acf
--- /dev/null
+++ b/infra/libkookie/nixpkgs/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?commonFileActions: DOCDIR as argv[1] required}"
+ shopt -s globstar extglob nullglob
+ mkdir -p "$DOCDIR"
+ ${mvDoc docFiles}
+ ${rmNoise noiseFiles}
+ '';
+
+ # 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;
+}