public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download: 
* [gentoo-portage-dev] [PATCH 6/6] Rewrite default ebuild phase setting code
  @ 2014-08-18 17:51 99% ` Michał Górny
  0 siblings, 0 replies; 1+ results
From: Michał Górny @ 2014-08-18 17:51 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Michał Górny

Replace the ebuild phase setting code for EAPI 2 and newer with a
simpler approach; first set proper default_* functions, and call them
within the phase. Disallow calling default_* for other phase functions
than the one being run.
---
 bin/phase-functions.sh | 117 ++++++++++++++++++++++---------------------------
 bin/save-ebuild-env.sh |   2 +-
 2 files changed, 53 insertions(+), 66 deletions(-)

diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index f39a024..b7fb5d7 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -734,91 +734,78 @@ __ebuild_phase_funcs() {
 	[ $# -ne 2 ] && die "expected exactly 2 args, got $#: $*"
 	local eapi=$1
 	local phase_func=$2
-	local default_phases="pkg_nofetch src_unpack src_prepare src_configure
-		src_compile src_install src_test"
-	local x y default_func=""
-
-	for x in pkg_nofetch src_unpack src_test ; do
-		declare -F $x >/dev/null || \
-			eval "$x() { __eapi0_$x \"\$@\" ; }"
+	local all_phases="src_compile pkg_config src_configure pkg_info
+		src_install pkg_nofetch pkg_postinst pkg_postrm pkg_preinst
+		src_prepare pkg_prerm pkg_pretend pkg_setup src_test src_unpack"
+	local x
+
+	# First, set up the error handlers for default*
+	for x in ${all_phases} ; do
+		eval "default_${x}() {
+			die \"default_${x}() is not supported in EAPI='${eapi}' in phase ${phase_func}\"
+		}"
 	done
 
+	# We can just call the specific handler -- it will either error out
+	# on invalid phase or run it.
+	eval "default() {
+		default_${phase_func}
+	}"
+
 	case "$eapi" in
+		0|1) # EAPIs not supporting 'default'
 
-		0|1)
+			for x in pkg_nofetch src_unpack src_test ; do
+				declare -F $x >/dev/null || \
+					eval "$x() { __eapi0_$x; }"
+			done
 
 			if ! declare -F src_compile >/dev/null ; then
 				case "$eapi" in
 					0)
-						src_compile() { __eapi0_src_compile "$@" ; }
+						src_compile() { __eapi0_src_compile; }
 						;;
 					*)
-						src_compile() { __eapi1_src_compile "$@" ; }
+						src_compile() { __eapi1_src_compile; }
 						;;
 				esac
 			fi
-
-			for x in $default_phases ; do
-				eval "default_$x() {
-					die \"default_$x() is not supported with EAPI='$eapi' during phase $phase_func\"
-				}"
-			done
-
-			eval "default() {
-				die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
-			}"
-
 			;;
 
-		*)
-
+		*) # EAPIs supporting 'default'
+
+			# defaults starting with EAPI 0
+			[[ ${phase_func} == pkg_nofetch ]] && \
+				default_pkg_nofetch() { __eapi0_pkg_nofetch; }
+			[[ ${phase_func} == src_unpack ]] && \
+				default_src_unpack() { __eapi0_src_unpack; }
+			[[ ${phase_func} == src_test ]] && \
+				default_src_test() { __eapi0_src_test; }
+
+			# defaults starting with EAPI 2
+			[[ ${phase_func} == src_configure ]] && \
+				default_src_configure() { __eapi2_src_configure; }
+			[[ ${phase_func} == src_compile ]] && \
+				default_src_compile() { __eapi2_src_compile; }
+
+			# bind supported phases to the defaults
+			declare -F src_unpack >/dev/null || \
+				src_unpack() { default; }
 			declare -F src_configure >/dev/null || \
-				src_configure() { __eapi2_src_configure "$@" ; }
-
+				src_configure() { default; }
 			declare -F src_compile >/dev/null || \
-				src_compile() { __eapi2_src_compile "$@" ; }
-
-			has $eapi 2 3 || declare -F src_install >/dev/null || \
-				src_install() { __eapi4_src_install "$@" ; }
+				src_compile() { default; }
+			declare -F src_test >/dev/null || \
+				src_test() { default; }
 
-			if has $phase_func $default_phases ; then
-
-				__eapi2_pkg_nofetch   () { __eapi0_pkg_nofetch          "$@" ; }
-				__eapi2_src_unpack    () { __eapi0_src_unpack           "$@" ; }
-				__eapi2_src_prepare   () { true                             ; }
-				__eapi2_src_test      () { __eapi0_src_test             "$@" ; }
-				__eapi2_src_install   () { die "$FUNCNAME is not supported" ; }
-
-				for x in $default_phases ; do
-					eval "default_$x() { __eapi2_$x \"\$@\" ; }"
-				done
-
-				eval "default() { __eapi2_$phase_func \"\$@\" ; }"
-
-				case "$eapi" in
-					2|3)
-						;;
-					*)
-						eval "default_src_install() { __eapi4_src_install \"\$@\" ; }"
-						[[ $phase_func = src_install ]] && \
-							eval "default() { __eapi4_$phase_func \"\$@\" ; }"
-						;;
-				esac
-
-			else
-
-				for x in $default_phases ; do
-					eval "default_$x() {
-						die \"default_$x() is not supported in phase $default_func\"
-					}"
-				done
-
-				eval "default() {
-					die \"default() is not supported with EAPI='$eapi' during phase $phase_func\"
-				}"
+			# defaults starting with EAPI 4
+			if ! has ${eapi} 2 3; then
+				[[ ${phase_func} == src_install ]] && \
+					default_src_install() { __eapi4_src_install; }
 
+				declare -F src_install >/dev/null || \
+					src_install() { default; }
 			fi
-
 			;;
 	esac
 }
diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh
index 98cff83..de0c499 100644
--- a/bin/save-ebuild-env.sh
+++ b/bin/save-ebuild-env.sh
@@ -42,7 +42,7 @@ __save_ebuild_env() {
 
 	for x in pkg_setup pkg_nofetch src_unpack src_prepare src_configure \
 		src_compile src_test src_install pkg_preinst pkg_postinst \
-		pkg_prerm pkg_postrm ; do
+		pkg_prerm pkg_postrm pkg_config pkg_info pkg_pretend ; do
 		unset -f default_$x __eapi{0,1,2,3,4}_$x
 	done
 	unset x
-- 
2.0.4



^ permalink raw reply related	[relevance 99%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2014-08-18 17:51     [gentoo-portage-dev] [PATCHES] Random issues and refactoring before EAPI6 series Michał Górny
2014-08-18 17:51 99% ` [gentoo-portage-dev] [PATCH 6/6] Rewrite default ebuild phase setting code Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox