--- gx86/eclass/distutils-r1.eclass | 50 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-)
diff --git a/gx86/eclass/distutils-r1.eclass b/gx86/eclass/distutils-r1.eclass index 6bec5bb..cce47a7 100644 --- a/gx86/eclass/distutils-r1.eclass +++ b/gx86/eclass/distutils-r1.eclass @@ -105,6 +105,22 @@ DEPEND=${PYTHON_DEPS} # HTML_DOCS=( doc/html/ ) # @CODE +# @ECLASS-VARIABLE: DISTUTILS_IN_SOURCE_BUILD +# @DEFAULT_UNSET +# @DESCRIPTION: +# If set to a non-null value, in-source builds will be enabled. +# If unset, the default is to use in-source builds when python_prepare() +# is declared, and out-of-source builds otherwise. +# +# If in-source builds are used, the eclass will create a copy of package +# sources for each Python implementation in python_prepare_all(), +# and work on that copy afterwards. +# +# If out-of-source builds are used, the eclass will instead work +# on the sources directly, prepending setup.py arguments with +# 'build --build-base ${BUILD_DIR}' to enforce keeping & using built +# files in the specific root. + # @ECLASS-VARIABLE: myesetuppyargs # @DEFAULT_UNSET # @DESCRIPTION: @@ -130,7 +146,16 @@ DEPEND=${PYTHON_DEPS} esetuppy() { debug-print-function ${FUNCNAME} "${@}" - set -- "${PYTHON:-python}" setup.py \ + local args=() + if [[ ! ${DISTUTILS_IN_SOURCE_BUILD} ]]; then + if [[ ! ${BUILD_DIR} ]]; then + die 'Out-of-source build requested, yet BUILD_DIR unset.' + fi + + args+=( build --build-base "${BUILD_DIR}" ) + fi + + set -- "${PYTHON:-python}" setup.py "${args[@]}" \ "${myesetuppyargs[@]}" "${@}" echo "${@}" >&2 @@ -152,8 +177,17 @@ distutils-r1_python_prepare_all() { epatch_user - # create source copies for each implementation - python_copy_sources + # by default, use in-source build if python_prepare() is used + if [[ ! ${DISTUTILS_IN_SOURCE_BUILD+1} ]]; then + if declare -f python_prepare >/dev/null; then + DISTUTILS_IN_SOURCE_BUILD=1 + fi + fi + + if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then + # create source copies for each implementation + python_copy_sources + fi } # @FUNCTION: distutils-r1_python_prepare @@ -297,9 +331,15 @@ distutils-r1_python_install_all() { distutils-r1_run_phase() { debug-print-function ${FUNCNAME} "${@}" - pushd "${BUILD_DIR}" &>/dev/null || die + if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then + pushd "${BUILD_DIR}" &>/dev/null || die + fi + "${@}" || die "${1} failed." - popd &>/dev/null || die + + if [[ ${DISTUTILS_IN_SOURCE_BUILD} ]]; then + popd &>/dev/null || die + fi } distutils-r1_src_prepare() { -- 1.7.12.4