From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 63E9F198005 for ; Sun, 10 Mar 2013 15:50:15 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8058FE07DD; Sun, 10 Mar 2013 15:50:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B7721E07D4 for ; Sun, 10 Mar 2013 15:50:00 +0000 (UTC) Received: from pomiocik.lan (77-255-9-250.adsl.inetia.pl [77.255.9.250]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 6899333CB84; Sun, 10 Mar 2013 15:49:58 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: python@gentoo.org, hasufell@gentoo.org, ulm@gentoo.org, =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH] multibuild: introduce a generic framework for custom phase functions. Date: Sun, 10 Mar 2013 16:50:17 +0100 Message-Id: <1362930617-20031-1-git-send-email-mgorny@gentoo.org> X-Mailer: git-send-email 1.8.1.5 In-Reply-To: <20796.31150.637490.654018@a1i15.kph.uni-mainz.de> References: <20796.31150.637490.654018@a1i15.kph.uni-mainz.de> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Archives-Salt: 68e45003-1fa9-4506-abed-7cff9c97faf4 X-Archives-Hash: 3d20ecece819388574143a1fe67d074d The framework provides functions to declare, export and obtain custom phase functions. Each of the custom phases can be defined by eclasses and ebuilds in a manner similar to regular phases. The eclasses define ${ECLASS}_${phase} function and run 'multibuild_export_phases' to register them. The ebuilds define ${phase} function and it automatically takes precedence over eclass-defined ones. --- gx86/eclass/multibuild.eclass | 66 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass index bc510e9..3187c9e 100644 --- a/gx86/eclass/multibuild.eclass +++ b/gx86/eclass/multibuild.eclass @@ -245,5 +245,71 @@ run_in_build_dir() { return ${ret} } +# @ECLASS-VARIABLE: _MULTIBUILD_EXPORTED_PHASES +# @INTERNAL +# @DESCRIPTION: +# The list of currently exported phase functions. +# +# Each function is stored in the form of 'eclass:phase-name'. +# New exports are prepended to the list, so the first matching value +# is the most recent one. +_MULTIBUILD_EXPORTED_PHASES=() + +# @FUNCTION: multibuild_export_phases +# @USAGE: ... +# @DESCRIPTION: +# Export the eclass phase functions for named phases. The functions need +# be named ${ECLASS}_. The exported functions will override +# any previously exported phases. +multibuild_export_phases() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${#} -eq 0 ]] && die "Usage: multibuild_export_phases ..." + + # just prepend to the list + _MULTIBUILD_EXPORTED_PHASES=( + "${@/#/${ECLASS}:}" + "${_MULTIBUILD_EXPORTED_PHASES[@]}" + ) +} + +# @FUNCTION: multibuild_get_phase_function +# @USAGE: +# @DESCRIPTION: +# Find the topmost handler for the named phase. It can be either +# user-defined phase handler (with the same name as the phase) +# or a handler exported most recently by an eclass. +# +# Prints the function name to stdout or null string if there is +# no handler for the phase. +multibuild_get_phase_function() { + debug-print-function ${FUNCNAME} "${@}" + + [[ ${#} -ne 1 ]] && die "Usage: multibuild_get_phase_function " + + local phase=${1} + + # user-defined phase + if ! declare -f "${phase}" >/dev/null; then + local found p + for p in "${_MULTIBUILD_EXPORTED_PHASES[@]}"; do + if [[ ${p} == *:${phase} ]]; then + # we're breaking out, so we can overwrite it. + phase=${p/:/_} + found=1 + break + fi + done + + if [[ ! ${found} ]]; then + return + elif ! declare -f "${phase}" >/dev/null; then + die "Phase function ${phase} exported but never defined!" + fi + fi + + echo "${phase}" +} + _MULTIBUILD=1 fi -- 1.8.1.5