summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2013-03-04 19:21:27 +0000
committerMichał Górny <mgorny@gentoo.org>2013-03-04 19:21:27 +0000
commitfc01d475a49880e6de76f2e7e1907dd4f8337d3b (patch)
treea5ed2b0af2c514c8d30c1191b65e95880fe7c722 /eclass
parentSwitch to EAPI 5. (diff)
downloadgentoo-2-fc01d475a49880e6de76f2e7e1907dd4f8337d3b.tar.gz
gentoo-2-fc01d475a49880e6de76f2e7e1907dd4f8337d3b.tar.bz2
gentoo-2-fc01d475a49880e6de76f2e7e1907dd4f8337d3b.zip
Introduce multibuild.eclass to handle building multiple variants of the same package in a common manner.
Diffstat (limited to 'eclass')
-rw-r--r--eclass/ChangeLog6
-rw-r--r--eclass/multibuild.eclass178
2 files changed, 183 insertions, 1 deletions
diff --git a/eclass/ChangeLog b/eclass/ChangeLog
index bb0c514fa1f1..ae1494834ca3 100644
--- a/eclass/ChangeLog
+++ b/eclass/ChangeLog
@@ -1,6 +1,10 @@
# ChangeLog for eclass directory
# Copyright 1999-2013 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.704 2013/03/04 19:10:31 robbat2 Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.705 2013/03/04 19:21:27 mgorny Exp $
+
+ 04 Mar 2013; Michał Górny <mgorny@gentoo.org> +multibuild.eclass:
+ Introduce multibuild.eclass to handle building multiple variants of the same
+ package in a common manner.
04 Mar 2013; Robin H. Johnson <robbat2@gentoo.org> mysql-cmake.eclass:
MySQL 5.6 needs to NOT have -fno-implicit-templates, also support
diff --git a/eclass/multibuild.eclass b/eclass/multibuild.eclass
new file mode 100644
index 000000000000..39e1772320f8
--- /dev/null
+++ b/eclass/multibuild.eclass
@@ -0,0 +1,178 @@
+# Copyright 1999-2013 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/eclass/multibuild.eclass,v 1.1 2013/03/04 19:21:27 mgorny Exp $
+
+# @ECLASS: multibuild
+# @MAINTAINER:
+# Michał Górny <mgorny@gentoo.org>
+# @AUTHOR:
+# Author: Michał Górny <mgorny@gentoo.org>
+# @BLURB: A generic eclass for building multiple variants of packages.
+# @DESCRIPTION:
+# The multibuild eclass aims to provide a generic framework for building
+# multiple 'variants' of a package (e.g. multilib, Python
+# implementations).
+
+case "${EAPI:-0}" in
+ 0|1|2|3|4)
+ die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
+ ;;
+ 5)
+ ;;
+ *)
+ die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
+ ;;
+esac
+
+if [[ ! ${_MULTIBUILD} ]]; then
+
+inherit multiprocessing
+
+# @ECLASS-VARIABLE: MULTIBUILD_VARIANTS
+# @DESCRIPTION:
+# An array specifying all enabled variants which multibuild_foreach*
+# can execute the process for.
+#
+# In ebuild, it can be set in global scope. Eclasses should set it
+# locally in function scope to support nesting properly.
+#
+# Example:
+# @CODE
+# python_foreach_impl() {
+# local MULTIBUILD_VARIANTS=( python{2_5,2_6,2_7} ... )
+# multibuild_foreach_variant python_compile
+# }
+# @CODE
+
+# @ECLASS-VARIABLE: MULTIBUILD_VARIANT
+# @DESCRIPTION:
+# The current variant which the function was executed for.
+#
+# Example value:
+# @CODE
+# python2_6
+# @CODE
+
+# @ECLASS-VARIABLE: MULTIBUILD_ID
+# @DESCRIPTION:
+# The unique identifier for a multibuild run. In a simple run, it is
+# equal to MULTIBUILD_VARIANT. In a nested multibuild environment, it
+# contains the complete selection tree.
+#
+# It can be used to create variant-unique directories and files.
+#
+# Example value:
+# @CODE
+# amd64-double
+# @CODE
+
+# @ECLASS-VARIABLE: BUILD_DIR
+# @DESCRIPTION:
+# The current build directory. In global scope, it is supposed
+# to contain an 'initial' build directory. If unset, ${S} is used.
+#
+# multibuild_foreach_variant() sets BUILD_DIR locally
+# to variant-specific build directories based on the initial value
+# of BUILD_DIR.
+#
+# Example value:
+# @CODE
+# ${WORKDIR}/foo-1.3-python2_6
+# @CODE
+
+# @FUNCTION: multibuild_foreach_variant
+# @USAGE: [<argv>...]
+# @DESCRIPTION:
+# Run the passed command repeatedly for each of the enabled package
+# variants.
+#
+# Each of the runs will have variant-specific BUILD_DIR set, and output
+# teed to a separate log in ${T}.
+#
+# The function returns 0 if all commands return 0, or the first non-zero
+# exit status otherwise. However, it performs all the invocations
+# nevertheless. It is preferred to call 'die' inside of the passed
+# function.
+multibuild_foreach_variant() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ${MULTIBUILD_VARIANTS} ]] \
+ || die "MULTIBUILD_VARIANTS need to be set"
+
+ local bdir=${BUILD_DIR:-${S}}
+
+ # Avoid writing outside WORKDIR if S=${WORKDIR}.
+ [[ ${bdir%%/} == ${WORKDIR%%/} ]] && bdir=${WORKDIR}/build
+
+ local prev_id=${MULTIBUILD_ID:+${MULTIBUILD_ID}-}
+ local ret=0 lret=0 v
+
+ debug-print "${FUNCNAME}: initial build_dir = ${bdir}"
+
+ for v in "${MULTIBUILD_VARIANTS[@]}"; do
+ local MULTIBUILD_VARIANT=${v}
+ local MULTIBUILD_ID=${prev_id}${v}
+ local BUILD_DIR=${bdir%%/}-${v}
+ local log_fd
+
+ # redirect_alloc_fd accepts files only. so we need to open
+ # a random file and then reuse the fd for logger process.
+ redirect_alloc_fd log_fd /dev/null
+ # bash can't handle ${log_fd} in redirections,
+ # we need to use eval to pass fd numbers directly.
+ eval "
+ exec ${log_fd}> >(exec tee -a \"\${T}/build-\${MULTIBUILD_ID}.log\")
+ einfo \"\${v}: running \${@}\" >&${log_fd} 2>&1
+ \"\${@}\" >&${log_fd} 2>&1
+ lret=\${?}
+ exec ${log_fd}>&-
+ "
+ done
+ [[ ${ret} -eq 0 && ${lret} -ne 0 ]] && ret=${lret}
+
+ return ${ret}
+}
+
+# @FUNCTION: multibuild_parallel_foreach_variant
+# @USAGE: [<argv>...]
+# @DESCRIPTION:
+# Run the passed command repeatedly for each of the enabled package
+# variants alike multibuild_foreach_variant. Multiple invocations of the command
+# will be performed in parallel, up to MULTIBUILD_JOBS tasks.
+#
+# The function returns 0 if all commands return 0, or the first non-zero
+# exit status otherwise. However, it performs all the invocations
+# nevertheless. It is preferred to call 'die' inside of the passed
+# function.
+multibuild_parallel_foreach_variant() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local ret lret
+
+ _multibuild_parallel() {
+ (
+ multijob_child_init
+ "${@}"
+ ) &
+ multijob_post_fork
+ }
+
+ local opts
+ if [[ ${MULTIBUILD_JOBS} ]]; then
+ opts=-j${MULTIBUILD_JOBS}
+ else
+ opts=${MAKEOPTS}
+ fi
+
+ multijob_init "${opts}"
+ multibuild_foreach_variant _multibuild_parallel "${@}"
+ ret=${?}
+ multijob_finish
+ lret=${?}
+
+ [[ ${ret} -eq 0 ]] && ret=${lret}
+ return ${ret}
+}
+
+_MULTIBUILD=1
+fi