This also fixes various other code smells. I wrote this back in the start of October, and never got around to sending it to the list for review. A note: given how extensively this patch changes the eclass, it is suggested that it actually become depend.apache-r1 and only support EAPI=6, and the EAPI=6 ebuilds that presently inherit depend.apache can inherit this instead. --- eclass/depend.apache.eclass | 156 ++++++++++++++++++++++++++------------------ 1 file changed, 93 insertions(+), 63 deletions(-)
diff --git a/eclass/depend.apache.eclass b/eclass/depend.apache.eclass index b69c2ec..2ef18cf 100644 --- a/eclass/depend.apache.eclass +++ b/eclass/depend.apache.eclass @@ -36,23 +36,21 @@ # want_apache2 server # # pkg_setup() { -# depend.apache_pkg_setup server +# depend.apache_pkg_setup # } # @CODE - -inherit multilib +# +# NOTE: Unless you have an indirect dependency on Apache, if you have your +# own pkg_setup, you must call depend.apache_pkg_setup to get the variables +# provided by this eclass. case ${EAPI:-0} in - 0|1|2|3|4|5) + 2|3|4|5) + inherit multilib ;; 6) - ewarn - ewarn "EAPI=${EAPI} is not supported by depend.apache.eclass." - ewarn "This means that ${CATEGORY}/${PF} is most likely buggy." - ewarn "Please file a report on https://bugs.gentoo.org/" - ewarn ;; - *) + 0|1|*) die "EAPI=${EAPI} is not supported by depend.apache.eclass" ;; esac @@ -64,47 +62,47 @@ esac # @ECLASS-VARIABLE: APACHE_VERSION # @DESCRIPTION: # Stores the version of apache we are going to be ebuilding. -# This variable is set by the want/need_apache functions. +# This variable is set by depend.apache-pkg_setup. # @ECLASS-VARIABLE: APXS # @DESCRIPTION: # Path to the apxs tool. -# This variable is set by the want/need_apache functions. +# This variable is set by depend.apache-pkg_setup. # @ECLASS-VARIABLE: APACHE_BIN # @DESCRIPTION: # Path to the apache binary. -# This variable is set by the want/need_apache functions. +# This variable is set by depend.apache-pkg_setup. # @ECLASS-VARIABLE: APACHE_CTL # @DESCRIPTION: # Path to the apachectl tool. -# This variable is set by the want/need_apache functions. +# This variable is set by depend.apache-pkg_setup. # @ECLASS-VARIABLE: APACHE_BASEDIR # @DESCRIPTION: # Path to the server root directory. -# This variable is set by the want/need_apache functions. +# This variable is set by depend.apache-pkg_setup. # @ECLASS-VARIABLE: APACHE_CONFDIR # @DESCRIPTION: # Path to the configuration file directory. -# This variable is set by the want/need_apache functions. +# This variable is set by depend.apache-pkg_setup. # @ECLASS-VARIABLE: APACHE_MODULES_CONFDIR # @DESCRIPTION: # Path where module configuration files are kept. -# This variable is set by the want/need_apache functions. +# This variable is set by depend.apache-pkg_setup. # @ECLASS-VARIABLE: APACHE_VHOSTS_CONFDIR # @DESCRIPTION: # Path where virtual host configuration files are kept. -# This variable is set by the want/need_apache functions. +# This variable is set by depend.apache-pkg_setup. # @ECLASS-VARIABLE: APACHE_MODULESDIR # @DESCRIPTION: # Path where we install modules. -# This variable is set by the want/need_apache functions. +# This variable is set by depend.apache-pkg_setup. # @ECLASS-VARIABLE: APACHE_DEPEND # @DESCRIPTION: @@ -126,6 +124,17 @@ APACHE2_2_DEPEND="=www-servers/apache-2.2*" # Dependencies for Apache 2.4.x APACHE2_4_DEPEND="=www-servers/apache-2.4*" +# @ECLASS-VARIABLE: APACHE_DEPENDENCY +# @INTERNAL +# @DESCRIPTION: +# Whether we want or need Apache (used in pkg_setup) +APACHE_DEPENDENCY="none" + +# @ECLASS-VARIABLE: APACHE_USEFLAG +# @INTERNAL +# @DESCRIPTION: +# What useflag indicates we want apache2, defaults to apache2 +APACHE_USEFLAG="apache2" # ============================================================================== # INTERNAL FUNCTIONS @@ -134,8 +143,6 @@ APACHE2_4_DEPEND="=www-servers/apache-2.4*" _init_apache2() { debug-print-function $FUNCNAME $* - # WARNING: Do not use these variables with anything that is put - # into the dependency cache (DEPEND/RDEPEND/etc) APACHE_VERSION="2" APXS="/usr/sbin/apxs2" APACHE_BIN="/usr/sbin/apache2" @@ -153,16 +160,42 @@ _init_no_apache() { APACHE_VERSION="0" } +# @FUNCTION: _apache_dependency +# @USAGE: { want | need } dependency [myiuse] +# @DESCRIPTION: +# Sets up apache dependencies. First parameter is the literal string "want" or +# "need" to indicate the type of dependency. Second parameter is the dependency +# string for {R,}DEPEND. Third parameter overrides the default useflag +# indicating apache2 is wanted. +_apache_dependency() { + debug-print-function $FUNCNAME $* + + case $1 in + want) + APACHE_USEFLAG="${3:-${APACHE_USEFLAG}}" + IUSE="${IUSE} ${APACHE_USEFLAG}" + DEPEND="${DEPEND} ${APACHE_USEFLAG}? ( $2 )" + RDEPEND="${RDEPEND} ${APACHE_USEFLAG}? ( $2 )" + ;; + need) + DEPEND="${DEPEND} $2" + RDEPEND="${RDEPEND} $2" + ;; + *) + die "Invalid first parameter to $FUNCNAME" + ;; + esac + APACHE_DEPENDENCY="$1" +} + # ============================================================================== # PUBLIC FUNCTIONS # ============================================================================== # @FUNCTION: depend.apache_pkg_setup -# @USAGE: [myiuse] # @DESCRIPTION: -# An ebuild calls this in pkg_setup() to initialize variables for optional -# apache-2.x support. If the myiuse parameter is not given it defaults to -# apache2. +# An ebuild calls this in pkg_setup() to initialize variables for apache-2.x +# support. depend.apache_pkg_setup() { debug-print-function $FUNCNAME $* @@ -170,14 +203,23 @@ depend.apache_pkg_setup() { die "$FUNCNAME() should be called in pkg_setup()" fi - local myiuse=${1:-apache2} - if has ${myiuse} ${IUSE}; then - if use ${myiuse}; then + case ${APACHE_DEPENDENCY} in + want) + if use ${APACHE_USEFLAG}; then + _init_apache2 + else + _init_no_apache + fi + ;; + need) _init_apache2 - else - _init_no_apache - fi - fi + ;; + none) + ;; + *) + die "Invalid APACHE_DEPENDENCY setting" + ;; + esac } # @FUNCTION: want_apache @@ -185,8 +227,6 @@ depend.apache_pkg_setup() { # @DESCRIPTION: # An ebuild calls this to get the dependency information for optional apache # support. If the myiuse parameter is not given it defaults to apache2. -# An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup() -# with the same myiuse parameter. want_apache() { debug-print-function $FUNCNAME $* want_apache2 "$@" @@ -197,15 +237,9 @@ want_apache() { # @DESCRIPTION: # An ebuild calls this to get the dependency information for optional apache-2.x # support. If the myiuse parameter is not given it defaults to apache2. -# An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup() -# with the same myiuse parameter. want_apache2() { debug-print-function $FUNCNAME $* - - local myiuse=${1:-apache2} - IUSE="${IUSE} ${myiuse}" - DEPEND="${DEPEND} ${myiuse}? ( ${APACHE2_DEPEND} )" - RDEPEND="${RDEPEND} ${myiuse}? ( ${APACHE2_DEPEND} )" + _apache_dependency want "${APACHE2_DEPEND}" "$@" } # @FUNCTION: want_apache2_2 @@ -214,15 +248,20 @@ want_apache2() { # An ebuild calls this to get the dependency information for optional # apache-2.2.x support. If the myiuse parameter is not given it defaults to # apache2. -# An ebuild should additionally call depend.apache_pkg_setup() in pkg_setup() -# with the same myiuse parameter. want_apache2_2() { debug-print-function $FUNCNAME $* + _apache_dependency want "${APACHE2_2_DEPEND}" "$@" +} - local myiuse=${1:-apache2} - IUSE="${IUSE} ${myiuse}" - DEPEND="${DEPEND} ${myiuse}? ( ${APACHE2_2_DEPEND} )" - RDEPEND="${RDEPEND} ${myiuse}? ( ${APACHE2_2_DEPEND} )" +# @FUNCTION: want_apache2_4 +# @USAGE: [myiuse] +# @DESCRIPTION: +# An ebuild calls this to get the dependency information for optional +# apache-2.4.x support. If the myiuse parameter is not given it defaults to +# apache2. +want_apache2_4() { + debug-print-function $FUNCNAME $* + _apache_dependency want "${APACHE2_4_DEPEND}" "$@" } # @FUNCTION: need_apache @@ -238,10 +277,7 @@ need_apache() { # An ebuild calls this to get the dependency information for apache-2.x. need_apache2() { debug-print-function $FUNCNAME $* - - DEPEND="${DEPEND} ${APACHE2_DEPEND}" - RDEPEND="${RDEPEND} ${APACHE2_DEPEND}" - _init_apache2 + _apache_dependency need "${APACHE2_DEPEND}" "$@" } # @FUNCTION: need_apache2_2 @@ -249,21 +285,15 @@ need_apache2() { # An ebuild calls this to get the dependency information for apache-2.2.x. need_apache2_2() { debug-print-function $FUNCNAME $* - - DEPEND="${DEPEND} ${APACHE2_2_DEPEND}" - RDEPEND="${RDEPEND} ${APACHE2_2_DEPEND}" - _init_apache2 + _apache_dependency need "${APACHE2_2_DEPEND}" "$@" } # @FUNCTION: need_apache2_4 # @DESCRIPTION: # An ebuild calls this to get the dependency information for apache-2.4.x. need_apache2_4() { - debug-print-function $FUNCNAME $* - - DEPEND="${DEPEND} ${APACHE2_4_DEPEND}" - RDEPEND="${RDEPEND} ${APACHE2_4_DEPEND}" - _init_apache2 + debug-print-function $FUNCNAME $* + _apache_dependency need "${APACHE2_4_DEPEND}" "$@" } # @FUNCTION: has_apache @@ -290,7 +320,7 @@ has_apache() { has_apache_threads() { debug-print-function $FUNCNAME $* - if ! built_with_use www-servers/apache threads; then + if ! has_version 'www-servers/apache[threads]'; then return fi @@ -313,14 +343,14 @@ has_apache_threads() { has_apache_threads_in() { debug-print-function $FUNCNAME $* - if ! built_with_use www-servers/apache threads; then + if ! has_version 'www-servers/apache[threads]'; then return fi local myforeign="$1" local myflag="${2:-threads}" - if ! built_with_use ${myforeign} ${myflag}; then + if ! has_version "${myforeign}[${myflag}]"; then echo eerror "You need to enable USE flag '${myflag}' in ${myforeign} to" eerror "build a thread-safe version of ${CATEGORY}/${PN} for use" -- 1.9.1