From 08034ceb1767f4bcbb7b440bcbfed1bc76881d16 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 16 Jan 2009 22:20:05 +1000 Subject: makepkg: add optional package function This patch allows us to split the building and packaging stages of a PKGBUILD and minimize fakeroot usage. This can be done with less code duplication (run_build and run_package look quite similiar) but the run_package function will be where the package splitting logic is implemented in the future. Signed-off-by: Allan McRae --- scripts/makepkg.sh.in | 57 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index e9e38b3a..b21c2af8 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -682,7 +682,7 @@ run_build() { local ret=0 if [ "$LOGGING" = "1" ]; then - BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}.log" + BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-build.log" if [ -f "$BUILDLOG" ]; then local i=1 while true; do @@ -710,6 +710,46 @@ run_build() { fi } +run_package() { + # clear user-specified makeflags if requested + if [ "$(check_option makeflags)" = "n" ]; then + MAKEFLAGS="" + fi + + msg "$(gettext "Starting package()...")" + cd "$srcdir" + + # ensure all necessary build variables are exported + export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST + + local ret=0 + if [ "$LOGGING" = "1" ]; then + BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-package.log" + if [ -f "$BUILDLOG" ]; then + local i=1 + while true; do + if [ -f "$BUILDLOG.$i" ]; then + i=$(($i +1)) + else + break + fi + done + mv "$BUILDLOG" "$BUILDLOG.$i" + fi + + package 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} + else + package 2>&1 || ret=$? + fi + + if [ $ret -gt 0 ]; then + error "$(gettext "Packaging Failed.")" + plain "$(gettext "Aborting...")" + remove_deps + exit 2 # $E_BUILD_FAILED + fi +} + tidy_install() { cd "$pkgdir" msg "$(gettext "Tidying install...")" @@ -1570,7 +1610,11 @@ fi # Run the bare minimum in fakeroot if [ "$INFAKEROOT" = "1" ]; then if [ "$REPKG" = "0" ]; then - run_build + if [ "$(type -t package)" != "function" ]; then + run_build + else + run_package + fi tidy_install fi @@ -1662,11 +1706,20 @@ else if [ "$REPKG" = "0" ]; then devel_update run_build + if [ "$(type -t package)" == "function" ]; then + run_package + fi tidy_install fi create_package else + if [ "$(type -t package)" == "function" ]; then + devel_update + run_build + cd "$startdir" + fi + msg "$(gettext "Entering fakeroot environment...")" if [ "$newpkgver" != "" ]; then -- cgit v1.2.3 From 9804911c5fbe7363d22f2384953bbcc3e57c1959 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 16 Jan 2009 22:22:04 +1000 Subject: makepkg: add functions for backup and restore of package fields Adds functions for the backup and restoration of package variables that can be over-ridden during package splitting. Variables which can be overridden are given in the splitpkg_overrides variable. Signed-off-by: Allan McRae --- scripts/makepkg.sh.in | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index b21c2af8..4d33a9c0 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -42,9 +42,12 @@ BUILDSCRIPT='@BUILDSCRIPT@' startdir="$PWD" srcdir="$startdir/src" pkgdir="$startdir/pkg" + packaging_options=('strip' 'docs' 'libtool' 'emptydirs' 'zipman' 'purge') other_options=('ccache' 'distcc' 'makeflags' 'force') -readonly -a packaging_options other_options +splitpkg_overrides=('pkgdesc' 'license' 'groups' 'depends' 'optdepends' 'provides' \ + 'conflicts' 'replaces' 'backup' 'options' 'install') +readonly -a packaging_options other_options splitpkg_overrides # Options ASROOT=0 @@ -1179,6 +1182,24 @@ devel_update() { fi } +backup_package_variables() { + for var in ${splitpkg_overrides[@]}; do + indirect="${var}_backup" + eval "${indirect}=\"${!var}\"" + done +} + +restore_package_variables() { + for var in ${splitpkg_overrides[@]}; do + indirect="${var}_backup" + if [ -n "${!indirect}" ]; then + eval "${var}=\"${!indirect}\"" + else + unset ${var} + fi + done +} + # getopt like parser parse_options() { local short_options=$1; shift; -- cgit v1.2.3 From 708ce1480f83e01af7a6aba2db04e7982c313673 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Mon, 8 Dec 2008 12:21:03 +1000 Subject: makepkg: hack around tee in run_package function Piping the package function through tee to log the outut also clears any variables set in the package function. This is a problem in split packages as package variable overrides are done in the package function. This is fixed by creating a node which the output is piped through and duplicated using the tee function. Signed-off-by: Allan McRae --- scripts/makepkg.sh.in | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 4d33a9c0..f2c9b363 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -740,7 +740,16 @@ run_package() { mv "$BUILDLOG" "$BUILDLOG.$i" fi - package 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]} + # ensure overridden package variables suvrive tee with split packages + logpipe=$(mktemp -u "$startdir/logpipe.XXXXXXXX") + mknod "$logpipe" p + exec 3>&1 + tee "$BUILDLOG" < "$logpipe" & + exec 1>"$logpipe" 2>"$logpipe" + package 2>&1 || ret=$? + sync + exec 1>&3 2>&3 3>&- + rm "$logpipe" else package 2>&1 || ret=$? fi -- cgit v1.2.3 From 21b8a5418dc4e4f0b0ebc95b20126c07b3714ca6 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 16 Jan 2009 22:26:52 +1000 Subject: makepkg: Optional argument for run_package and create_package Generalize run_package to allow the passing of a package name directing the use of an alternative package function. A similar adjustment to create_package to prepare split packages. Signed-off-by: Allan McRae --- scripts/makepkg.sh.in | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index f2c9b363..13cd98fc 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -714,12 +714,20 @@ run_build() { } run_package() { + if [ -z "$1" ]; then + pkgfunc="package" + nameofpkg="$pkgname" + else + pkgfunc="package_$1" + nameofpkg="$1" + fi + # clear user-specified makeflags if requested if [ "$(check_option makeflags)" = "n" ]; then MAKEFLAGS="" fi - msg "$(gettext "Starting package()...")" + msg "$(gettext "Starting %s()...")" "$pkgfunc" cd "$srcdir" # ensure all necessary build variables are exported @@ -727,7 +735,7 @@ run_package() { local ret=0 if [ "$LOGGING" = "1" ]; then - BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-package.log" + BUILDLOG="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log" if [ -f "$BUILDLOG" ]; then local i=1 while true; do @@ -746,12 +754,12 @@ run_package() { exec 3>&1 tee "$BUILDLOG" < "$logpipe" & exec 1>"$logpipe" 2>"$logpipe" - package 2>&1 || ret=$? + $pkgfunc 2>&1 || ret=$? sync exec 1>&3 2>&3 3>&- rm "$logpipe" else - package 2>&1 || ret=$? + $pkgfunc 2>&1 || ret=$? fi if [ $ret -gt 0 ]; then @@ -845,6 +853,12 @@ tidy_install() { } create_package() { + if [ -z "$1" ]; then + nameofpkg="$pkgname" + else + nameofpkg="$1" + fi + if [ ! -d "$pkgdir" ]; then error "$(gettext "Missing pkg/ directory.")" plain "$(gettext "Aborting...")" @@ -869,7 +883,7 @@ create_package() { echo "# using $(fakeroot -v)" >>.PKGINFO fi echo "# $(LC_ALL=C date -u)" >>.PKGINFO - echo "pkgname = $pkgname" >>.PKGINFO + echo "pkgname = $nameofpkg" >>.PKGINFO echo "pkgver = $pkgver-$pkgrel" >>.PKGINFO echo "pkgdesc = $pkgdesc" >>.PKGINFO echo "url = $url" >>.PKGINFO @@ -953,7 +967,7 @@ create_package() { "$PKGEXT" ;; esac - local pkg_file="$PKGDEST/${pkgname}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" + local pkg_file="$PKGDEST/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}${PKGEXT}" # when fileglobbing, we want * in an empty directory to expand to # the null string rather than itself -- cgit v1.2.3 From e946ee7745a839c0cd9244a3d9b50a3ea15143f9 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 16 Jan 2009 22:32:05 +1000 Subject: makepkg: implement creation of split packages Adds the ability to create multiple packages from one PKGBUILD Signed-off-by: Allan McRae --- scripts/makepkg.sh.in | 63 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 16 deletions(-) (limited to 'scripts') diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 13cd98fc..1e990de3 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -67,6 +67,7 @@ LOGGING=0 SOURCEONLY=0 IGNOREARCH=0 HOLDVER=0 +SPLITPKG=0 # Forces the pkgver of the current PKGBUILD. Used by the fakeroot call # when dealing with svn/cvs/etc PKGBUILDs. @@ -1565,6 +1566,10 @@ if [ "$GENINTEG" = "1" ]; then exit 0 # $E_OK fi +if [ "${#pkgname[@]}" -gt "1" ]; then + SPLITPKG=1 +fi + # check for no-no's in the build script if [ -z "$pkgname" ]; then error "$(gettext "%s is not allowed to be empty.")" "pkgname" @@ -1653,17 +1658,29 @@ fi # Run the bare minimum in fakeroot if [ "$INFAKEROOT" = "1" ]; then - if [ "$REPKG" = "0" ]; then - if [ "$(type -t package)" != "function" ]; then - run_build - else - run_package + if [ "$SPLITPKG" = "0" ]; then + if [ "$REPKG" = "0" ]; then + if [ "$(type -t package)" != "function" ]; then + run_build + else + run_package + fi + tidy_install fi - tidy_install + create_package + else + for pkg in ${pkgname[@]}; do + pkgdir="$pkgdir/$pkg" + mkdir -p "$pkgdir" + backup_package_variables + run_package $pkg + tidy_install + create_package $pkg + restore_package_variables + pkgdir="${pkgdir%/*}" + done fi - create_package - msg "$(gettext "Leaving fakeroot environment.")" exit 0 # $E_OK fi @@ -1747,18 +1764,32 @@ else # if we are root or if fakeroot is not enabled, then we don't use it if [ "$(check_buildenv fakeroot)" != "y" -o $EUID -eq 0 ]; then - if [ "$REPKG" = "0" ]; then + if [ "$SPLITPKG" = "0" ]; then + if [ "$REPKG" = "0" ]; then + devel_update + run_build + if [ "$(type -t package)" == "function" ]; then + run_package + fi + tidy_install + fi + create_package + else devel_update run_build - if [ "$(type -t package)" == "function" ]; then - run_package - fi - tidy_install + for pkg in ${pkgname[@]}; do + pkgdir="$pkgdir/$pkg" + mkdir -p "$pkgdir" + backup_package_variables + run_package $pkg + tidy_install + create_package $pkg + restore_package_variables + pkgdir="${pkgdir%/*}" + done fi - - create_package else - if [ "$(type -t package)" == "function" ]; then + if [ "$(type -t package)" == "function" -o "$SPLITPKG" = "1" ]; then devel_update run_build cd "$startdir" -- cgit v1.2.3