[pacman-dev] [PATCH 1/2] makepkg: Add helper to test for functions in build script
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/makepkg.sh.in | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index c311c30..8b222da 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -2095,6 +2095,10 @@ install_package() { fi } +has_function() { + return $(declare -f $1 >/dev/null) +} + check_sanity() { # check for no-no's in the build script local i @@ -2238,7 +2242,7 @@ check_sanity() { if (( ${#pkgname[@]} > 1 )); then for i in ${pkgname[@]}; do - if ! declare -f package_${i} >/dev/null; then + if ! has_function package_${i}; then error "$(gettext "Missing %s function for split package '%s'")" "package_$i()" "$i" ret=1 fi @@ -2799,7 +2803,7 @@ if (( GENINTEG )); then exit 0 # $E_OK fi -if declare -f pkgver >/dev/null; then +if has_function pkgver; then PKGVERFUNC=1 fi @@ -2814,24 +2818,24 @@ if (( ${#pkgname[@]} > 1 )); then fi # test for available PKGBUILD functions -if declare -f prepare >/dev/null; then +if has_function prepare; then # "Hide" prepare() function if not going to be run if [[ $RUN_PREPARE != "n" ]]; then PREPAREFUNC=1 fi fi -if declare -f build >/dev/null; then +if has_function build; then BUILDFUNC=1 fi -if declare -f check >/dev/null; then +if has_function check; then # "Hide" check() function if not going to be run if [[ $RUN_CHECK = 'y' ]] || { ! check_buildenv "check" "n" && [[ $RUN_CHECK != "n" ]]; }; then CHECKFUNC=1 fi fi -if declare -f package >/dev/null; then +if has_function package; then PKGFUNC=1 -elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null; then +elif [[ $SPLITPKG -eq 0 ]] && has_function package_${pkgname}; then SPLITPKG=1 fi -- 1.8.2.3
Not having a package() function means all building occurs as root and repackaging can lose permissions. Given the use of package() functions has been around for years and we deprecated not having one in pacman-4.1, we can remove support for PKGBUILDs without package() functions altogether. However, keep PKGBUILDs that have neither a build() or package() function working. Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/makepkg.sh.in | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 8b222da..1bbd561 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -2240,7 +2240,12 @@ check_sanity() { ret=1 fi - if (( ${#pkgname[@]} > 1 )); then + if (( ${#pkgname[@]} == 1 )); then + if has_function build && ! ( has_function package || has_function package_${pkgname}); then + error "$(gettext "Missing %s function in %s")" "package()" "$BUILDFILE" + ret=1 + fi + else for i in ${pkgname[@]}; do if ! has_function package_${i}; then error "$(gettext "Missing %s function for split package '%s'")" "package_$i()" "$i" @@ -2873,17 +2878,7 @@ if (( INFAKEROOT )); then if (( ! SPLITPKG )); then pkgdir="$pkgdirbase/$pkgname" mkdir "$pkgdir" - if (( ! PKGFUNC )); then - if (( ! REPKG )); then - if (( BUILDFUNC )); then - run_build - (( CHECKFUNC )) && run_check - fi - else - warning "$(gettext "Repackaging without the use of a %s function is deprecated.")" "package()" - plain "$(gettext "File permissions may not be preserved.")" - fi - else + if (( PKGFUNC )); then run_package fi tidy_install @@ -2900,10 +2895,6 @@ fi fullver=$(get_full_version) msg "$(gettext "Making package: %s")" "$pkgbase $fullver ($(date))" -if (( !PKGFUNC && !SPLITPKG )); then - warning "$(gettext "Using a %s without a %s function is deprecated.")" "$BUILDSCRIPT" "package()" -fi - # if we are creating a source-only package, go no further if (( SOURCEONLY )); then if [[ -f $SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT} ]] \ @@ -2981,14 +2972,7 @@ cd_safe "$srcdir" if (( NOEXTRACT && ! VERIFYSOURCE )); then warning "$(gettext "Using existing %s tree")" "src/" -elif (( REPKG )); then - if (( ! PKGFUNC && ! SPLITPKG )) \ - && { [[ ! -d $pkgdirbase ]] || dir_is_empty "$pkgdirbase"; }; then - error "$(gettext "The package directory is empty, there is nothing to repackage!")" - plain "$(gettext "Aborting...")" - exit 1 - fi -else +elif (( !REPKG )); then download_sources check_source_integrity (( VERIFYSOURCE )) && exit 0 # $E_OK @@ -3002,8 +2986,8 @@ if (( NOBUILD )); then msg "$(gettext "Sources are ready.")" exit 0 #E_OK else - # check for existing pkg directory; don't remove if we are repackaging - if [[ -d $pkgdirbase ]] && (( ! REPKG || PKGFUNC || SPLITPKG )); then + # clean existing pkg directory + if [[ -d $pkgdirbase ]]; then msg "$(gettext "Removing existing %s directory...")" "pkg/" rm -rf "$pkgdirbase" fi @@ -3027,9 +3011,6 @@ else mkdir -p "$pkgdir" if (( PKGFUNC )); then run_package - elif (( REPKG )); then - warning "$(gettext "Repackaging without the use of a %s function is deprecated.")" "package()" - plain "$(gettext "File permissions may not be preserved.")" fi tidy_install create_package @@ -3038,7 +3019,7 @@ else run_split_packaging fi else - if (( ! REPKG && ( PKGFUNC || SPLITPKG ) )); then + if (( ! REPKG )); then (( BUILDFUNC )) && run_build (( CHECKFUNC )) && run_check cd_safe "$startdir" -- 1.8.2.3
On May 18, 2013 10:10 AM, "Allan McRae" <allan@archlinux.org> wrote:
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/makepkg.sh.in | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index c311c30..8b222da 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -2095,6 +2095,10 @@ install_package() { fi }
+has_function() { + return $(declare -f $1 >/dev/null)
Quotes on $1 please.
+}
+ check_sanity() { # check for no-no's in the build script local i @@ -2238,7 +2242,7 @@ check_sanity() {
if (( ${#pkgname[@]} > 1 )); then for i in ${pkgname[@]}; do - if ! declare -f package_${i} >/dev/null; then + if ! has_function package_${i}; then error "$(gettext "Missing %s function for split package '%s'")" "package_$i()" "$i" ret=1 fi @@ -2799,7 +2803,7 @@ if (( GENINTEG )); then exit 0 # $E_OK fi
-if declare -f pkgver >/dev/null; then +if has_function pkgver; then PKGVERFUNC=1 fi
@@ -2814,24 +2818,24 @@ if (( ${#pkgname[@]} > 1 )); then fi
# test for available PKGBUILD functions -if declare -f prepare >/dev/null; then +if has_function prepare; then # "Hide" prepare() function if not going to be run if [[ $RUN_PREPARE != "n" ]]; then PREPAREFUNC=1 fi fi -if declare -f build >/dev/null; then +if has_function build; then BUILDFUNC=1 fi -if declare -f check >/dev/null; then +if has_function check; then # "Hide" check() function if not going to be run if [[ $RUN_CHECK = 'y' ]] || { ! check_buildenv "check" "n" && [[ $RUN_CHECK != "n" ]]; }; then CHECKFUNC=1 fi fi -if declare -f package >/dev/null; then +if has_function package; then PKGFUNC=1 -elif [[ $SPLITPKG -eq 0 ]] && declare -f package_${pkgname} >/dev/null;
If this works, its only by chance. Just call declare and the return value will work itself out. Would also prefer have_ instead of has_ but that's a minor point. then
+elif [[ $SPLITPKG -eq 0 ]] && has_function package_${pkgname}; then SPLITPKG=1 fi
-- 1.8.2.3
On 19/05/13 01:37, Dave Reisner wrote:
On May 18, 2013 10:10 AM, "Allan McRae" <allan@archlinux.org> wrote:
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/makepkg.sh.in | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index c311c30..8b222da 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -2095,6 +2095,10 @@ install_package() { fi }
+has_function() { + return $(declare -f $1 >/dev/null)
Quotes on $1 please.
+}
If this works, its only by chance. Just call declare and the return value will work itself out.
Would also prefer have_ instead of has_ but that's a minor point.
All fixed on my working branch. Allan
participants (2)
-
Allan McRae
-
Dave Reisner