public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] out-of-source.eclass: A new eclass to help with out-of-source builds
@ 2017-08-12 22:23 Michał Górny
  0 siblings, 0 replies; 3+ messages in thread
From: Michał Górny @ 2017-08-12 22:23 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

The out-of-source.eclass is a simple multilib-minimal-style wrapper
to perform out of source builds of autotools (and other) packages. It is
mostly derived from the function served in the past by autotools-utils
since a number of developers found it useful. However, in order to avoid
the mistakes of autotools-utils, it is meant to be focused on a single
feature and have a better API.

This eclass has two use cases:

1. Ensuring that packages are tested with out-of-source builds.

2. Improving consistency between multilib and non-multilib packages.

// NB: I've even considered naming the phases multilib_*() to make
// switching to multilib even easier.

In the most basic form, it just redefines the phases from src_configure()
to src_install() with out-of-source wrappers. However, each phase can
be overriden using my_src_*() sub-phase that is run inside build dir
(alike multilib_src_*() in multilib-minimal). There is also
my_src_install_all() for the trailing source-dir actions.

// I'm wondering whether ECONF_SOURCE should be declared unconditionally
// as it is now in the patch, or if it should only be included
// in the default and required to be specified in my_src_configure()
// when redefined. FWICS, multilib-minimal currently requires it
// explicitly specified all the time.
---
 eclass/out-of-source.eclass | 123 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 123 insertions(+)
 create mode 100644 eclass/out-of-source.eclass

diff --git a/eclass/out-of-source.eclass b/eclass/out-of-source.eclass
new file mode 100644
index 000000000000..e19256426882
--- /dev/null
+++ b/eclass/out-of-source.eclass
@@ -0,0 +1,123 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: out-of-source.eclass
+# @MAINTAINER:
+# Michał Górny <mgorny@gentoo.org>
+# @BLURB: convenient wrapper to build autotools packages out-of-source
+# @DESCRIPTION:
+# This eclass provides a minimalistic wrapper interface to easily
+# build autotools (and alike) packages out-of-source. It is meant
+# to resemble the interface used by multilib-minimal without actually
+# requiring the package to be multilib.
+#
+# For the simplest ebuilds, it is enough to inherit the eclass
+# and the new phase functions will automatically build the package
+# out-of-source. If you need to redefine one of the default phases
+# between src_configure() and src_install(), you need to define
+# the sub-phases: my_src_configure(), my_src_compile(), my_src_test()
+# and my_src_install() instead that will be run inside the build
+# directory. Additionally, my_src_install_all() is provided to perform
+# doc-install and other common tasks done in source directory.
+#
+# Example use:
+# @CODE
+# inherit out-of-source
+#
+# my_src_configure() {
+#     econf \
+#         --disable-static
+# }
+# @CODE
+
+case ${EAPI} in
+	6);;
+	*) die "EAPI ${EAPI:-0} unsupported (too old)";;
+esac
+
+EXPORT_FUNCTIONS src_configure src_compile src_test src_install
+
+if [[ ! ${_OUT_OF_SOURCE_ECLASS} ]]; then
+
+# @FUNCTION: out-of-source_src_configure
+# @DESCRIPTION:
+# The default src_configure() implementation establishes a BUILD_DIR,
+# sets ECONF_SOURCE to the current directory (usually S), and runs
+# my_src_configure() (or the default) inside it.
+out-of-source_src_configure() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	# set some BUILD_DIR if we don't have one yet
+	: "${BUILD_DIR:=${WORKDIR}/${P}_build}"
+	local ECONF_SOURCE=${PWD}
+
+	mkdir -p "${BUILD_DIR}" || die
+	pushd "${BUILD_DIR}" >/dev/null || die
+	if declare -f my_src_configure >/dev/null ; then
+		my_src_configure
+	else
+		default_src_configure
+	fi
+	popd >/dev/null || die
+}
+
+# @FUNCTION: out-of-source_src_compile
+# @DESCRIPTION:
+# The default src_compile() implementation runs my_src_compile()
+# (or the default) inside the build directory.
+out-of-source_src_compile() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	pushd "${BUILD_DIR}" >/dev/null || die
+	if declare -f my_src_compile >/dev/null ; then
+		my_src_compile
+	else
+		default_src_compile
+	fi
+	popd >/dev/null || die
+}
+
+# @FUNCTION: out-of-source_src_test
+# @DESCRIPTION:
+# The default src_test() implementation runs my_src_test()
+# (or the default) inside the build directory.
+out-of-source_src_test() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	pushd "${BUILD_DIR}" >/dev/null || die
+	if declare -f my_src_test >/dev/null ; then
+		my_src_test
+	else
+		default_src_test
+	fi
+	popd >/dev/null || die
+}
+
+# @FUNCTION: out-of-source_src_install
+# @DESCRIPTION:
+# The default src_install() implementation runs my_src_install()
+# (or the 'make install' part of the default) inside the build directory,
+# followed by a call to my_src_install_all() (or 'einstalldocs' part
+# of the default) in the original working directory.
+out-of-source_src_install() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	pushd "${BUILD_DIR}" >/dev/null || die
+	if declare -f my_src_install >/dev/null ; then
+		my_src_install
+	else
+		if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
+			emake DESTDIR="${D}" install
+		fi
+	fi
+	popd >/dev/null || die
+
+	if declare -f my_src_install_all >/dev/null ; then
+		my_src_install_all
+	else
+		einstalldocs
+	fi
+}
+
+_OUT_OF_SOURCE_ECLASS=1
+fi
-- 
2.14.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [gentoo-dev] [PATCH] out-of-source.eclass: A new eclass to help with out-of-source builds
  2017-11-16 13:48 Michał Górny
@ 2017-11-16 13:54 ` David Seifert
  0 siblings, 0 replies; 3+ messages in thread
From: David Seifert @ 2017-11-16 13:54 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

On Thu, 2017-11-16 at 14:48 +0100, Michał Górny wrote:
> // NB: I'm not sure if I haven't submitted it already but that was
> // a long time ago, so let's try again. Requested by soap.
> 
> The out-of-source.eclass is a simple multilib-minimal-style wrapper
> to perform out of source builds of autotools (and other) packages. It
> is
> mostly derived from the function served in the past by autotools-
> utils
> since a number of developers found it useful. However, in order to
> avoid
> the mistakes of autotools-utils, it is meant to be focused on a
> single
> feature and have a better API.
> 
> This eclass has two use cases:
> 
> 1. Ensuring that packages are tested with out-of-source builds.
> 
> 2. Improving consistency between multilib and non-multilib packages.
> 
> In the most basic form, it just redefines the phases from
> src_configure()
> to src_install() with out-of-source wrappers. However, each phase can
> be overriden using my_src_*() sub-phase that is run inside build dir
> (alike multilib_src_*() in multilib-minimal). There is also
> my_src_install_all() for the trailing source-dir actions.

+1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [gentoo-dev] [PATCH] out-of-source.eclass: A new eclass to help with out-of-source builds
@ 2017-11-16 13:48 Michał Górny
  2017-11-16 13:54 ` David Seifert
  0 siblings, 1 reply; 3+ messages in thread
From: Michał Górny @ 2017-11-16 13:48 UTC (permalink / raw)
  To: gentoo-dev; +Cc: Michał Górny

// NB: I'm not sure if I haven't submitted it already but that was
// a long time ago, so let's try again. Requested by soap.

The out-of-source.eclass is a simple multilib-minimal-style wrapper
to perform out of source builds of autotools (and other) packages. It is
mostly derived from the function served in the past by autotools-utils
since a number of developers found it useful. However, in order to avoid
the mistakes of autotools-utils, it is meant to be focused on a single
feature and have a better API.

This eclass has two use cases:

1. Ensuring that packages are tested with out-of-source builds.

2. Improving consistency between multilib and non-multilib packages.

In the most basic form, it just redefines the phases from src_configure()
to src_install() with out-of-source wrappers. However, each phase can
be overriden using my_src_*() sub-phase that is run inside build dir
(alike multilib_src_*() in multilib-minimal). There is also
my_src_install_all() for the trailing source-dir actions.
---
 eclass/out-of-source.eclass | 124 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 124 insertions(+)
 create mode 100644 eclass/out-of-source.eclass

diff --git a/eclass/out-of-source.eclass b/eclass/out-of-source.eclass
new file mode 100644
index 000000000000..4d9c8d05fd64
--- /dev/null
+++ b/eclass/out-of-source.eclass
@@ -0,0 +1,124 @@
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: out-of-source.eclass
+# @MAINTAINER:
+# Michał Górny <mgorny@gentoo.org>
+# @BLURB: convenient wrapper to build autotools packages out-of-source
+# @DESCRIPTION:
+# This eclass provides a minimalistic wrapper interface to easily
+# build autotools (and alike) packages out-of-source. It is meant
+# to resemble the interface used by multilib-minimal without actually
+# requiring the package to be multilib.
+#
+# For the simplest ebuilds, it is enough to inherit the eclass
+# and the new phase functions will automatically build the package
+# out-of-source. If you need to redefine one of the default phases
+# src_configure() through src_install(), you need to define
+# the matching sub-phases: my_src_configure(), my_src_compile(),
+# my_src_test() and/or my_src_install(). Those sub-phase functions
+# will be run inside the build directory. Additionally,
+# my_src_install_all() is provided to perform doc-install and other
+# common tasks that are done in source directory.
+#
+# Example use:
+# @CODE
+# inherit out-of-source
+#
+# my_src_configure() {
+#     econf \
+#         --disable-static
+# }
+# @CODE
+
+case ${EAPI} in
+	6);;
+	*) die "EAPI ${EAPI:-0} unsupported (too old)";;
+esac
+
+EXPORT_FUNCTIONS src_configure src_compile src_test src_install
+
+if [[ ! ${_OUT_OF_SOURCE_ECLASS} ]]; then
+
+# @FUNCTION: out-of-source_src_configure
+# @DESCRIPTION:
+# The default src_configure() implementation establishes a BUILD_DIR,
+# sets ECONF_SOURCE to the current directory (usually S), and runs
+# my_src_configure() (or the default) inside it.
+out-of-source_src_configure() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	# set some BUILD_DIR if we don't have one yet
+	: "${BUILD_DIR:=${WORKDIR}/${P}_build}"
+	local ECONF_SOURCE=${PWD}
+
+	mkdir -p "${BUILD_DIR}" || die
+	pushd "${BUILD_DIR}" >/dev/null || die
+	if declare -f my_src_configure >/dev/null ; then
+		my_src_configure
+	else
+		default_src_configure
+	fi
+	popd >/dev/null || die
+}
+
+# @FUNCTION: out-of-source_src_compile
+# @DESCRIPTION:
+# The default src_compile() implementation runs my_src_compile()
+# (or the default) inside the build directory.
+out-of-source_src_compile() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	pushd "${BUILD_DIR}" >/dev/null || die
+	if declare -f my_src_compile >/dev/null ; then
+		my_src_compile
+	else
+		default_src_compile
+	fi
+	popd >/dev/null || die
+}
+
+# @FUNCTION: out-of-source_src_test
+# @DESCRIPTION:
+# The default src_test() implementation runs my_src_test()
+# (or the default) inside the build directory.
+out-of-source_src_test() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	pushd "${BUILD_DIR}" >/dev/null || die
+	if declare -f my_src_test >/dev/null ; then
+		my_src_test
+	else
+		default_src_test
+	fi
+	popd >/dev/null || die
+}
+
+# @FUNCTION: out-of-source_src_install
+# @DESCRIPTION:
+# The default src_install() implementation runs my_src_install()
+# (or the 'make install' part of the default) inside the build directory,
+# followed by a call to my_src_install_all() (or 'einstalldocs' part
+# of the default) in the original working directory.
+out-of-source_src_install() {
+	debug-print-function ${FUNCNAME} "$@"
+
+	pushd "${BUILD_DIR}" >/dev/null || die
+	if declare -f my_src_install >/dev/null ; then
+		my_src_install
+	else
+		if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
+			emake DESTDIR="${D}" install
+		fi
+	fi
+	popd >/dev/null || die
+
+	if declare -f my_src_install_all >/dev/null ; then
+		my_src_install_all
+	else
+		einstalldocs
+	fi
+}
+
+_OUT_OF_SOURCE_ECLASS=1
+fi
-- 
2.15.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-16 13:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-12 22:23 [gentoo-dev] [PATCH] out-of-source.eclass: A new eclass to help with out-of-source builds Michał Górny
2017-11-16 13:48 Michał Górny
2017-11-16 13:54 ` David Seifert

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