public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: reavertm@gentoo.org, multilib@gentoo.org,
	"Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH] Introduce autotools_* sub-phase functions to make overriding easier.
Date: Thu,  2 May 2013 14:26:35 +0200	[thread overview]
Message-ID: <1367497595-8335-1-git-send-email-mgorny@gentoo.org> (raw)
In-Reply-To: <20130502142611.18a76960@gentoo.org>

More details in the mail preceding the patch.
---
 gx86/eclass/autotools-multilib.eclass |  47 ++++++++--
 gx86/eclass/autotools-utils.eclass    | 157 +++++++++++++++++++++++++---------
 2 files changed, 158 insertions(+), 46 deletions(-)

diff --git a/gx86/eclass/autotools-multilib.eclass b/gx86/eclass/autotools-multilib.eclass
index 5ca8112..6156610 100644
--- a/gx86/eclass/autotools-multilib.eclass
+++ b/gx86/eclass/autotools-multilib.eclass
@@ -38,27 +38,62 @@ autotools-multilib_src_prepare() {
 }
 
 autotools-multilib_src_configure() {
-	multilib_parallel_foreach_abi autotools-utils_src_configure "${@}"
+	if declare -f autotools_configure >/dev/null; then
+		multilib_parallel_foreach_abi \
+			_autotools-utils_run_phase autotools_configure "${@}"
+	else
+		multilib_parallel_foreach_abi \
+			_autotools-utils_run_phase \
+			autotools-utils_autotools_configure "${@}"
+	fi
 }
 
 autotools-multilib_src_compile() {
-	multilib_foreach_abi autotools-utils_src_compile "${@}"
+	if declare -f autotools_compile >/dev/null; then
+		multilib_foreach_abi \
+			_autotools-utils_run_phase autotools_compile "${@}"
+	else
+		multilib_foreach_abi \
+			_autotools-utils_run_phase \
+			autotools-utils_autotools_compile "${@}"
+	fi
 }
 
 autotools-multilib_src_test() {
-	multilib_foreach_abi autotools-utils_src_test "${@}"
+	if declare -f autotools_test >/dev/null; then
+		multilib_foreach_abi \
+			_autotools-utils_run_phase autotools_test "${@}"
+	else
+		multilib_foreach_abi \
+			_autotools-utils_run_phase \
+			autotools-utils_autotools_test "${@}"
+	fi
 }
 
 autotools-multilib_src_install() {
-	autotools-multilib_secure_install() {
-		autotools-utils_src_install "${@}"
+	_autotools-multilib_wrap_install() {
+		"${@}"
 
 		multilib_prepare_wrappers
 		# Make sure all headers are the same for each ABI.
 		multilib_check_headers
 	}
 
-	multilib_foreach_abi autotools-multilib_secure_install "${@}"
+	if declare -f autotools_install >/dev/null; then
+		multilib_foreach_abi _autotools-multilib_wrap_install \
+			_autotools-utils_run_phase autotools_install "${@}"
+	else
+		multilib_foreach_abi _autotools-multilib_wrap_install \
+			_autotools-utils_run_phase \
+			autotools-utils_autotools_install "${@}"
+	fi
+
+	if declare -f autotools_install_all >/dev/null; then
+		_autotools-utils_run_phase autotools_install_all "${@}"
+	else
+		_autotools-utils_run_phase \
+			autotools-utils_autotools_install_all "${@}"
+	fi
 
 	# merge the wrappers
 	multilib_install_wrappers
diff --git a/gx86/eclass/autotools-utils.eclass b/gx86/eclass/autotools-utils.eclass
index e6bf526..b0a299c 100644
--- a/gx86/eclass/autotools-utils.eclass
+++ b/gx86/eclass/autotools-utils.eclass
@@ -14,8 +14,15 @@
 # handling, libtool files removal.
 #
 # Please note that autotools-utils does not support mixing of its phase
-# functions with regular econf/emake calls. If necessary, please call
-# autotools-utils_src_compile instead of the latter.
+# functions with regular econf/emake calls in src_*. If necessary, please
+# declare autotools_* sub-phases instead which will be run in ${BUILD_DIR}.
+#
+# autotools-utils uses the following sub-phases:
+#
+# - autotools_prepare_all, autotools_install_all -- run in ${S}, once.
+#
+# - autotools_configure, autotools_compile, autotools_test,
+#   autotools_install -- run in ${BUILD_DIR}, may be run multiple times.
 #
 # @EXAMPLE:
 # Typical ebuild using autotools-utils.eclass:
@@ -60,26 +67,26 @@
 # 	"${FILESDIR}/${P}-unbundle_libpng.patch"
 # )
 #
-# src_configure() {
+# autotools_configure() {
 # 	local myeconfargs=(
 # 		$(use_enable debug)
 # 		$(use_with qt4)
 # 		$(use_enable threads multithreading)
 # 		$(use_with tiff)
 # 	)
-# 	autotools-utils_src_configure
+# 	edefault
 # }
 #
-# src_compile() {
-# 	autotools-utils_src_compile
-# 	use doc && autotools-utils_src_compile docs
+# autotools_compile() {
+# 	edefault
+# 	use doc && emake docs
 # }
 #
-# src_install() {
-# 	use doc && HTML_DOCS=("${BUILD_DIR}/apidocs/html/")
-# 	autotools-utils_src_install
+# autotools_install_all() {
+# 	use doc && HTML_DOCS=( apidocs/html/. )
+# 	edefault
 # 	if use examples; then
-# 		dobin "${BUILD_DIR}"/foo_example{1,2,3} \\
+# 		dobin foo_example{1,2,3} \\
 # 			|| die 'dobin examples failed'
 # 	fi
 # }
@@ -228,6 +235,8 @@ _check_build_dir() {
 	# Backwards compatibility for getting the value.
 	AUTOTOOLS_BUILD_DIR=${BUILD_DIR}
 	echo ">>> Working in BUILD_DIR: \"${BUILD_DIR}\""
+
+	mkdir -p "${BUILD_DIR}" || die
 }
 
 # @FUNCTION: remove_libtool_files
@@ -383,12 +392,12 @@ autotools-utils_autoreconf() {
 	done
 }
 
-# @FUNCTION: autotools-utils_src_prepare
+# @FUNCTION: autotools-utils_autotools_prepare_all
 # @DESCRIPTION:
 # The src_prepare function.
 #
 # Supporting PATCHES array and user patches. See base.eclass(5) for reference.
-autotools-utils_src_prepare() {
+autotools-utils_autotools_prepare_all() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	local want_autoreconf=${AUTOTOOLS_AUTORECONF}
@@ -415,7 +424,7 @@ autotools-utils_src_prepare() {
 	elibtoolize --patch-only
 }
 
-# @FUNCTION: autotools-utils_src_configure
+# @FUNCTION: autotools-utils_autotools_configure
 # @DESCRIPTION:
 # The src_configure function. For out of source build it creates build
 # directory and runs econf there. Configuration parameters defined
@@ -424,7 +433,7 @@ autotools-utils_src_prepare() {
 #
 # IUSE="static-libs" passes --enable-shared and either --disable-static/--enable-static
 # to econf respectively.
-autotools-utils_src_configure() {
+autotools-utils_autotools_configure() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	[[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] \
@@ -435,7 +444,6 @@ autotools-utils_src_configure() {
 	# Common args
 	local econfargs=()
 
-	_check_build_dir
 	if "${ECONF_SOURCE}"/configure --help 2>&1 | grep -q '^ *--docdir='; then
 		econfargs+=(
 			--docdir="${EPREFIX}"/usr/share/doc/${PF}
@@ -453,40 +461,38 @@ autotools-utils_src_configure() {
 	# Append user args
 	econfargs+=("${myeconfargs[@]}")
 
-	mkdir -p "${BUILD_DIR}" || die
-	pushd "${BUILD_DIR}" > /dev/null || die
 	econf "${econfargs[@]}" "$@"
-	popd > /dev/null || die
 }
 
-# @FUNCTION: autotools-utils_src_compile
+# @FUNCTION: autotools-utils_autotools_compile
 # @DESCRIPTION:
 # The autotools src_compile function, invokes emake in specified BUILD_DIR.
-autotools-utils_src_compile() {
+autotools-utils_autotools_compile() {
 	debug-print-function ${FUNCNAME} "$@"
 
-	_check_build_dir
-	pushd "${BUILD_DIR}" > /dev/null || die
 	emake "$@" || die 'emake failed'
-	popd > /dev/null || die
 }
 
-# @FUNCTION: autotools-utils_src_install
+# @FUNCTION: autotools-utils_autotools_install
+# @DESCRIPTION:
+# The build-dir part of src_install function. Runs emake install.
+autotools-utils_autotools_install() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	emake DESTDIR="${D}" "$@" install || die "emake install failed"
+}
+
+# @FUNCTION: autotools-utils_autotools_install_all
 # @DESCRIPTION:
-# The autotools src_install function. Runs emake install, unconditionally
-# removes unnecessary static libs (based on shouldnotlink libtool property)
-# and removes unnecessary libtool files when static-libs USE flag is defined
+# The common part of autotools src_install function. Removes unnecessary
+# static libs (based on shouldnotlink libtool property) and removes
+# unnecessary libtool files when static-libs USE flag is defined
 # and unset.
 #
 # DOCS and HTML_DOCS arrays are supported. See base.eclass(5) for reference.
-autotools-utils_src_install() {
+autotools-utils_autotools_install_all() {
 	debug-print-function ${FUNCNAME} "$@"
 
-	_check_build_dir
-	pushd "${BUILD_DIR}" > /dev/null || die
-	emake DESTDIR="${D}" "$@" install || die "emake install failed"
-	popd > /dev/null || die
-
 	# Move docs installed by autotools (in EAPI < 4).
 	if [[ ${EAPI} == [23] ]] \
 			&& path_exists "${D}${EPREFIX}"/usr/share/doc/${PF}/*; then
@@ -532,17 +538,88 @@ autotools-utils_src_install() {
 	prune_libtool_files ${prune_ltfiles:+--${prune_ltfiles}}
 }
 
-# @FUNCTION: autotools-utils_src_test
+# @FUNCTION: autotools-utils_autotools_test
 # @DESCRIPTION:
 # The autotools src_test function. Runs emake check in build directory.
-autotools-utils_src_test() {
+autotools-utils_autotools_test() {
 	debug-print-function ${FUNCNAME} "$@"
 
-	_check_build_dir
-	pushd "${BUILD_DIR}" > /dev/null || die
-
 	# XXX: do we need to support other targets in autotools?
 	emake check "${@}" || die 'emake check failed.'
+}
+
+# @FUNCTION: _autotools-utils_run_phase
+# @USAGE: <sub-phase> [<args>...]
+# @INTERNAL
+# @DESCRIPTION:
+# Run the given ebuild sub-phase or the default implementation.
+_autotools-utils_run_phase() {
+	local phase=${1}
+
+	# it's ok to have wrong value in default impls
+	# since they can't use it anyway.
+	eval "edefault() { autotools-utils_${phase} \"\${@}\"; }"
+	if [[ ${phase} != *_all ]]; then
+		_check_build_dir
+		pushd "${BUILD_DIR}" > /dev/null || die
+	fi
+
+	"${@}"
+
+	if [[ ${phase} != *_all ]]; then
+		popd > /dev/null || die
+	fi
+	unset -f edefault
+}
+
+autotools-utils_src_prepare() {
+	if declare -f autotools_prepare_all >/dev/null; then
+		_autotools-utils_run_phase autotools_prepare_all "${@}"
+	else
+		_autotools-utils_run_phase \
+			autotools-utils_autotools_prepare_all "${@}"
+	fi
+}
+
+autotools-utils_src_configure() {
+	if declare -f autotools_configure >/dev/null; then
+		_autotools-utils_run_phase autotools_configure "${@}"
+	else
+		_autotools-utils_run_phase \
+			autotools-utils_autotools_configure "${@}"
+	fi
+}
+
+autotools-utils_src_compile() {
+	if declare -f autotools_compile >/dev/null; then
+		_autotools-utils_run_phase autotools_compile "${@}"
+	else
+		_autotools-utils_run_phase \
+			autotools-utils_autotools_compile "${@}"
+	fi
+}
+
+autotools-utils_src_test() {
+	if declare -f autotools_test >/dev/null; then
+		_autotools-utils_run_phase autotools_test "${@}"
+	else
+		_autotools-utils_run_phase \
+			autotools-utils_autotools_test "${@}"
+	fi
+}
 
-	popd > /dev/null || die
+autotools-utils_src_install() {
+	if declare -f autotools_install >/dev/null; then
+		_autotools-utils_run_phase autotools_install "${@}"
+	else
+		_autotools-utils_run_phase \
+			autotools-utils_autotools_install "${@}"
+	fi
+
+	if declare -f autotools_install_all >/dev/null; then
+		_autotools-utils_run_phase autotools_install_all "${@}"
+	else
+		_autotools-utils_run_phase \
+			autotools-utils_autotools_install_all "${@}"
+	fi
 }
-- 
1.8.2.1



  reply	other threads:[~2013-05-02 12:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-02 12:26 [gentoo-dev] [PATCHES] Sub-phase functions in autotools-utils & autotools-multilib Michał Górny
2013-05-02 12:26 ` Michał Górny [this message]
2013-05-04  7:28 ` Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1367497595-8335-1-git-send-email-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=multilib@gentoo.org \
    --cc=reavertm@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox