[pacman-dev,02/10] makepkg: Simplify SPLITPKG check

Message ID a1a360d2fee56e6e4ae538fb09dc0e1e8c9142e5.1527783895.git.jan.steffens@gmail.com
State Accepted, archived
Headers show
Series [pacman-dev,01/10] libmakepkg/util/option: Refactor checking to reduce code duplication | expand

Commit Message

Jan Alexander Steffens May 31, 2018, 4:24 p.m. UTC
This causes package_$pkgname() to be preferred over package() in the
non-split case, but the behavior if both functions exist was
undocumented anyway.
---
 scripts/makepkg.sh.in | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Comments

Eli Schwartz May 31, 2018, 9:01 p.m. UTC | #1
On 05/31/2018 12:24 PM, Jan Alexander Steffens (heftig) wrote:
> This causes package_$pkgname() to be preferred over package() in the
> non-split case, but the behavior if both functions exist was
> undocumented anyway.

We don't document the behavior of arbitrary user-defined functions.
package_$pkgname() is only defined as having meaning in the context of
the PACKAGE SPLITTING section of the documentation.

IMHO this is us documenting that package() is the only correct function
unless ${#pkgname[@]} > 1.

I think it is far more intuitive to behave that way, and I'd actually be
willing to refuse to use package_$pkgname even if it is the only one...
Allan McRae June 4, 2018, 11:30 a.m. UTC | #2
On 01/06/18 07:01, Eli Schwartz wrote:
> On 05/31/2018 12:24 PM, Jan Alexander Steffens (heftig) wrote:
>> This causes package_$pkgname() to be preferred over package() in the
>> non-split case, but the behavior if both functions exist was
>> undocumented anyway.
> 
> We don't document the behavior of arbitrary user-defined functions.
> package_$pkgname() is only defined as having meaning in the context of
> the PACKAGE SPLITTING section of the documentation.
> 
> IMHO this is us documenting that package() is the only correct function
> unless ${#pkgname[@]} > 1.
> 
> I think it is far more intuitive to behave that way, and I'd actually be
> willing to refuse to use package_$pkgname even if it is the only one...
> 

We discussed on IRC to abort if both are present as undefined behavoiur.

Allan

Patch

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index e9080a70..748481e4 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1481,30 +1481,28 @@  fi
 # check we have the software required to process the PKGBUILD
 check_software || exit $E_MISSING_MAKEPKG_DEPS
 
-if (( ${#pkgname[@]} > 1 )); then
+if (( ${#pkgname[@]} > 1 )) || have_function package_${pkgname}; then
 	SPLITPKG=1
 fi
 
 # test for available PKGBUILD functions
 if have_function prepare; then
 	# "Hide" prepare() function if not going to be run
 	if [[ $RUN_PREPARE != "n" ]]; then
 		PREPAREFUNC=1
 	fi
 fi
 if have_function build; then
 	BUILDFUNC=1
 fi
 if have_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 have_function package; then
 	PKGFUNC=1
-elif [[ $SPLITPKG -eq 0 ]] && have_function package_${pkgname}; then
-	SPLITPKG=1
 fi
 
 # check if gpg signature is to be created and if signing key is valid