diff --git a/scons.eclass b/scons.eclass index 8321ee0..d29299c 100644 --- a/scons.eclass +++ b/scons.eclass @@ -5,10 +5,6 @@ # @ECLASS: scons.eclass # @MAINTAINER: # gentoo@... -# -# @CODE -# Michał Górny -# @CODE # @BLURB: helper functions to deal with SCons buildsystem # @DESCRIPTION: # This eclass provides a set of function to help developers sanely call @@ -19,22 +15,29 @@ # @ECLASS-VARIABLE: SCONS_MIN_VERSION # @DESCRIPTION: # The minimal version of SCons required for the build to work. -: ${SCONS_MIN_VERSION} +# @DEFAULT-UNSET + +# @ECLASS-VARIABLE: SCONSOPTS +# @DESCRIPTION: +# The default set of options to pass to scons. Similar to MAKEOPTS, +# supposed to be set in make.conf. If unset, will be generated from +# MAKEOPTS. +# @DEFAULT-UNSET # @ECLASS-VARIABLE: EXTRA_ESCONS # @DESCRIPTION: # The additional parameters to pass to SCons whenever escons() is used. -: ${EXTRA_ESCONS:=} +# @DEFAULT-UNSET -# @ECLASS-VARIABLE: SCONS_USE_TRUE +# @ECLASS-VARIABLE: USE_SCONS_TRUE # @DESCRIPTION: # The default value for truth in scons-use() (1 by default). -: ${SCONS_USE_TRUE:=1} +: ${USE_SCONS_TRUE:=1} -# @ECLASS-VARIABLE: SCONS_USE_FALSE +# @ECLASS-VARIABLE: USE_SCONS_FALSE # @DESCRIPTION: # The default value for false in scons-use() (0 by default). -: ${SCONS_USE_FALSE:=0} +: ${USE_SCONS_FALSE:=0} # -- ebuild variables setup -- @@ -46,16 +49,17 @@ fi # -- exported phase functions -- -EXPORT_FUNCTIONS pkg_setup src_compile +case "${EAPI:-0}" in + 1|0) EXPORT_FUNCTIONS src_compile;; + *) EXPORT_FUNCTIONS src_configure src_compile;; +esac -# @FUNCTION: scons_pkg_setup +# @FUNCTION: scons_src_configure # @DESCRIPTION: -# The exported pkg_setup() implementation. Calls scons_clean_makeopts() -# to get a sane MAKEOPTS. -scons_pkg_setup() { +# A blank src_configure() for SCons packages not using explicit +# configure phase. +scons_src_configure() { debug-print-function ${FUNCNAME} "${@}" - - scons_clean_makeopts } # @FUNCTION: scons_src_compile @@ -76,21 +80,37 @@ scons_src_compile() { # ${EXTRA_ESCONS}. Similar to emake. escons() { debug-print-function ${FUNCNAME} "${@}" - debug-print scons ${MAKEOPTS} ${EXTRA_ESCONS} "${@}" - scons ${MAKEOPTS} ${EXTRA_ESCONS} "${@}" + # if SCONSOPTS are _unset_, create them from MAKEOPTS + if [[ -n ${SCONSOPTS+1} ]]; then + export SCONSOPTS=$(scons_clean_makeopts) + fi + + set -- scons ${SCONSOPTS} ${EXTRA_ESCONS} "${@}" + echo "${@}" >&2 + "${@}" } # @FUNCTION: scons_clean_makeopts +# @USAGE: [makeflags] [...] # @DESCRIPTION: -# Strip MAKEOPTS of options not supported by SCons and make sure --jobs -# gets an argument. +# Strip the supplied makeflags (or ${MAKEOPTS} if called without +# an argument) of options not supported by SCons and make sure --jobs +# gets an argument. Output the resulting flag list (suitable +# for an assignment to SCONSOPTS). scons_clean_makeopts() { local new_makeopts debug-print-function ${FUNCNAME} "${@}" - set -- ${MAKEOPTS} + if [[ ${#} -eq 0 ]]; then + debug-print "Using MAKEOPTS: ${MAKEOPTS}" + set -- ${MAKEOPTS} + else + # unquote if necessary + set -- ${*} + fi + while [[ ${#} -gt 0 ]]; do case ${1} in # clean, simple to check -- we like that @@ -147,11 +167,11 @@ scons_clean_makeopts() { shift done - MAKEOPTS=${new_makeopts} - export MAKEOPTS + debug-print "New SCONSOPTS: ${new_makeopts}" + echo ${new_makeopts} } -# @FUNCTION: scons_use +# @FUNCTION: use_scons # @USAGE: [var-name] [var-opt-true] [var-opt-false] # @DESCRIPTION: # Output an SCons parameter with value depending on the USE flag state. @@ -159,13 +179,13 @@ scons_clean_makeopts() { # =. # # If is not set, will be used instead. -# If or is unset, SCONS_USE_TRUE -# or SCONS_USE_FALSE will be used instead. -scons_use() { +# If or is unset, USE_SCONS_TRUE +# or USE_SCONS_FALSE will be used instead. +use_scons() { local flag=${1} - local varname=${2:-${flag}} - local vartrue=${3:-${SCONS_USE_TRUE}} - local varfalse=${4:-${SCONS_USE_FALSE}} + local varname=${2:-${flag#!}} + local vartrue=${3:-${USE_SCONS_TRUE}} + local varfalse=${4:-${USE_SCONS_FALSE}} debug-print-function ${FUNCNAME} "${@}" @@ -183,45 +203,45 @@ scons_use() { # -- self-tests -- -_scons-clean-makeopts-perform-test() { - MAKEOPTS=${1} - scons-clean-makeopts - if [[ ${MAKEOPTS} != ${2-${1}} ]]; then +_scons_clean_makeopts_perform_test() { + local sconsopts=$(scons_clean_makeopts ${1}) + + if [[ ${sconsopts} != ${2-${1}} ]]; then cat >&2 <<_EOF_ Self-test failed: Input string: ${1} - Output string: ${MAKEOPTS} + Output string: ${sconsopts} Expected: ${2-${1}} _EOF_ fi } # Perform a self-test on scons-clean-makeopts. -_scons-clean-makeopts-tests() { +_scons_clean_makeopts_tests() { # jobcount expected for non-specified state local jc=255 # sane MAKEOPTS - _scons-clean-makeopts-perform-test '--jobs=14 -k' - _scons-clean-makeopts-perform-test '--jobs=14 -k' - _scons-clean-makeopts-perform-test '--jobs 15 -k' - _scons-clean-makeopts-perform-test '--jobs=16 --keep-going' - _scons-clean-makeopts-perform-test '-j17 --keep-going' - _scons-clean-makeopts-perform-test '-j 18 --keep-going' + _scons_clean_makeopts_perform_test '--jobs=14 -k' + _scons_clean_makeopts_perform_test '--jobs=14 -k' + _scons_clean_makeopts_perform_test '--jobs 15 -k' + _scons_clean_makeopts_perform_test '--jobs=16 --keep-going' + _scons_clean_makeopts_perform_test '-j17 --keep-going' + _scons_clean_makeopts_perform_test '-j 18 --keep-going' # needing cleaning - _scons-clean-makeopts-perform-test '--jobs -k' "--jobs=${jc} -k" - _scons-clean-makeopts-perform-test '--jobs --keep-going' "--jobs=${jc} --keep-going" - _scons-clean-makeopts-perform-test '-kj' "-kj ${jc}" + _scons_clean_makeopts_perform_test '--jobs -k' "--jobs=${jc} -k" + _scons_clean_makeopts_perform_test '--jobs --keep-going' "--jobs=${jc} --keep-going" + _scons_clean_makeopts_perform_test '-kj' "-kj ${jc}" # broken by definition (but passed as it breaks make as well) - _scons-clean-makeopts-perform-test '-jk' - _scons-clean-makeopts-perform-test '--jobs=randum' - _scons-clean-makeopts-perform-test '-kjrandum' + _scons_clean_makeopts_perform_test '-jk' + _scons_clean_makeopts_perform_test '--jobs=randum' + _scons_clean_makeopts_perform_test '-kjrandum' # needing stripping - _scons-clean-makeopts-perform-test '--load-average=25 -kj16' '-kj16' - _scons-clean-makeopts-perform-test '--load-average 25 -k -j17' '-k -j17' - _scons-clean-makeopts-perform-test '-j2 HOME=/tmp' '-j2' - _scons-clean-makeopts-perform-test '--jobs funnystuff -k' "--jobs=${jc} -k" + _scons_clean_makeopts_perform_test '--load-average=25 -kj16' '-kj16' + _scons_clean_makeopts_perform_test '--load-average 25 -k -j17' '-k -j17' + _scons_clean_makeopts_perform_test '-j2 HOME=/tmp' '-j2' + _scons_clean_makeopts_perform_test '--jobs funnystuff -k' "--jobs=${jc} -k" }