From ce77a5ceec8d4f241bec049a3af9d9626b74b6dc Mon Sep 17 00:00:00 2001 From: Petr Rockai Date: Fri, 13 Jul 2012 20:58:39 +0200 Subject: [PATCH] Factor out repeated scriptlets from build-support/release/*.nix. --- pkgs/build-support/release/ant-build.nix | 9 ++------- pkgs/build-support/release/binary-tarball.nix | 7 +------ pkgs/build-support/release/debian-build.nix | 15 ++++----------- pkgs/build-support/release/functions.sh | 14 ++++++++++++++ pkgs/build-support/release/nix-build.nix | 8 ++------ pkgs/build-support/release/rpm-build.nix | 14 ++++---------- 6 files changed, 27 insertions(+), 40 deletions(-) create mode 100644 pkgs/build-support/release/functions.sh diff --git a/pkgs/build-support/release/ant-build.nix b/pkgs/build-support/release/ant-build.nix index fe15f93a8fe2..696f179a2ed0 100644 --- a/pkgs/build-support/release/ant-build.nix +++ b/pkgs/build-support/release/ant-build.nix @@ -100,15 +100,10 @@ stdenv.mkDerivation ( postHook = '' mkdir -p $out/nix-support echo "$system" > $out/nix-support/system + . ${./functions.sh} - # If `src' is the result of a call to `makeSourceTarball', then it - # has a subdirectory containing the actual tarball(s). If there are - # multiple tarballs, just pick the first one. origSrc=$src - if test -d $src/tarballs; then - src=$(ls $src/tarballs/*.tar.bz2 $src/tarballs/*.tar.gz | sort | head -1) - fi - + src=$(findTarballs $src | head -1) ''; } ) diff --git a/pkgs/build-support/release/binary-tarball.nix b/pkgs/build-support/release/binary-tarball.nix index 6901c9f5555f..93331707ceef 100644 --- a/pkgs/build-support/release/binary-tarball.nix +++ b/pkgs/build-support/release/binary-tarball.nix @@ -36,13 +36,8 @@ stdenv.mkDerivation ( mkdir -p $out/nix-support echo "$system" > $out/nix-support/system - # If `src' is the result of a call to `makeSourceTarball', then it - # has a subdirectory containing the actual tarball(s). If there are - # multiple tarballs, just pick the first one. origSrc=$src - if test -d $src/tarballs; then - src=$(ls $src/tarballs/*.tar.bz2 $src/tarballs/*.tar.gz | sort | head -1) - fi + src=$(findTarballs $src | head -1) if test -e $origSrc/nix-support/hydra-release-name; then releaseName=$(cat $origSrc/nix-support/hydra-release-name) diff --git a/pkgs/build-support/release/debian-build.nix b/pkgs/build-support/release/debian-build.nix index 0095a2ff8818..feb15267f592 100644 --- a/pkgs/build-support/release/debian-build.nix +++ b/pkgs/build-support/release/debian-build.nix @@ -30,17 +30,10 @@ vmTools.runInLinuxImage (stdenv.mkDerivation ( # !!! cut&paste from rpm-build.nix postHook = '' - mkdir -p $out/nix-support - cat "$diskImage"/nix-support/full-name > $out/nix-support/full-name - - # If `src' is the result of a call to `makeSourceTarball', then it - # has a subdirectory containing the actual tarball(s). If there are - # multiple tarballs, just pick the first one. - echo $src - if test -d $src/tarballs; then - src=$(ls $src/tarballs/*.tar.bz2 $src/tarballs/*.tar.gz | sort | head -1) - fi - ''; # */ + . ${./functions.sh} + propagateImageName + src=$(findTarballs $src | head -1) # Find a tarball. + ''; installExtraDebsPhase = '' for i in $extraDebs; do diff --git a/pkgs/build-support/release/functions.sh b/pkgs/build-support/release/functions.sh new file mode 100644 index 000000000000..9f2d03519c8c --- /dev/null +++ b/pkgs/build-support/release/functions.sh @@ -0,0 +1,14 @@ +findTarballs() { + local suffix + test -d "$1/tarballs/" && { + for suffix in tar.gz tgz tar.bz2 tbz2 tar.xz tar.lzma; do + ls $1/tarballs/*.$suffix 2> /dev/null + done | sort + } + echo "$1" +} + +propagateImageName() { + ensureDir $out/nix-support + cat "$diskImage"/nix-support/full-name > $out/nix-support/full-name +} diff --git a/pkgs/build-support/release/nix-build.nix b/pkgs/build-support/release/nix-build.nix index 8abbca978750..336563ae285f 100644 --- a/pkgs/build-support/release/nix-build.nix +++ b/pkgs/build-support/release/nix-build.nix @@ -58,13 +58,9 @@ stdenv.mkDerivation ( name = name + (if src ? version then "-" + src.version else ""); postHook = '' - # If `src' is the result of a call to `makeSourceTarball', then it - # has a subdirectory containing the actual tarball(s). If there are - # multiple tarballs, just pick the first one. + . ${./functions.sh} origSrc=$src - if test -d $src/tarballs; then - src=$(ls $src/tarballs/*.tar.bz2 $src/tarballs/*.tar.gz $src/tarballs/*.tar.xz | sort | head -1) - fi + src=$(findTarballs $src | head -1) # Set GCC flags for coverage analysis, if desired. if test -n "${toString doCoverageAnalysis}"; then diff --git a/pkgs/build-support/release/rpm-build.nix b/pkgs/build-support/release/rpm-build.nix index 5eace575366f..708b62302d57 100644 --- a/pkgs/build-support/release/rpm-build.nix +++ b/pkgs/build-support/release/rpm-build.nix @@ -14,16 +14,10 @@ vmTools.buildRPM ( name = name + "-" + diskImage.name + (if src ? version then "-" + src.version else ""); preBuild = '' - mkdir -p $out/nix-support - cat "$diskImage"/nix-support/full-name > $out/nix-support/full-name - - # If `src' is the result of a call to `makeSourceTarball', then it - # has a subdirectory containing the actual tarball(s). If there are - # multiple tarballs, just pick the first one. - if test -d $src/tarballs; then - src=$(ls $src/tarballs/*.tar.bz2 $src/tarballs/*.tar.gz | sort | head -1) - fi - ''; # */ + . ${./functions.sh} + propagateImageName + src=$(findTarballs $src | head -1) # Pick the first tarball. + ''; postInstall = '' declare -a rpms rpmNames