Project:Python/scons-utils integration

From Gentoo Wiki
Jump to: navigation, search

As of dev-utils/scons package version 3.0.1-r100, multiple implementations of Python are supported. Since SConstruct and SConscript files are written in Python, this raised the problem of compatibility of those files with new versions of Python. As a result, scons-utils now requires using appropriate Python eclass.

Requirements for using scons-utils

Any ebuild using scons-utils needs to:

  1. Set a proper value of PYTHON_COMPAT being the intersection of Python implementations supported by build system scripts and the package (if applicable).
  2. Inherit a proper Python eclass (python-any-r1, python-single-r1 or python-r1).

Which eclass to use?

The usual rules for choosing the eclass apply. That is:

  1. If the package installs Python modules that need to be installed for multiple Python implementations, use python-r1 and remember to call python_setup if you want to use SCons outside of python_foreach_impl,
  2. If the package installs Python modules or scripts, use python-single-r1,
  3. Otherwise, use python-any-r1 to express purely build-time dependency on Python.

Examples

Purely build-time dependency

Assumes that only SCons (and possibly some other build/test scripts) require Python.

CODE Example ebuild with scons & build-time dep on Python
PYTHON_COMPAT=( python2_7 python3_4 )

inherit python-any-r1 scons-utils

pkg_setup() { python-any-r1_pkg_setup; } # if necessary

src_compile() {
    escons # ...
}

Simple run-time dependency + scons

A package that installs some Python scripts/modules and uses scons.

CODE Example ebuild with scons & simple run-time dep on Python
PYTHON_COMPAT=( python2_7 )

inherit python-single-r1 scons-utils

RDEPEND=${PYTHON_DEPS}
DEPEND=${RDEPEND}
REQUIRED_USE=${PYTHON_REQUIRED_USE}

pkg_setup() { python-single-r1_pkg_setup; } # if necessary

src_compile() {
    escons # ...
}

Conditional run-time dependency + scons

A package that installs some Python scripts/modules conditionally and uses scons (unconditionally).

CODE Example ebuild with scons & conditional run-time dep on Python
PYTHON_COMPAT=( python2_7 )

inherit python-single-r1 scons-utils

IUSE="python"

RDEPEND="python? ( ${PYTHON_DEPS} )"
DEPEND=${PYTHON_DEPS}
REQUIRED_USE=${PYTHON_REQUIRED_USE}

# has MERGE_TYPE check inside, so applies to source build only
pkg_setup() { python-single-r1_pkg_setup; }

# if you needed Python during pkg_pre/post* as well...
# pkg_setup() {
#     if [[ ${MERGE_TYPE} != binary ]] || use python; then
#         python_setup
#     fi
# }

python-r1 + scons (for Python modules)

A package that uses SCons to build various Python modules.

CODE Example ebuild with scons & python-r1
EAPI=7
PYTHON_COMPAT=( python{2_7,3_6} )

inherit python-r1 scons-utils

RDEPEND="${PYTHON_DEPS}"
# python-r1 requires explicit dep on scons
BDEPEND="dev-util/scons[${PYTHON_USEDEP}]"
REQUIRED_USE=${PYTHON_REQUIRED_USE}

src_compile() {
    python_foreach_impl escons # ...
}

python-r1 + scons (independent)

A package that uses SCons to build something independent from Python modules, and python-r1 to build some Python modules. Provides the ability to support different sets of Python implementations.

CODE Example ebuild with scons & independent python-r1
EAPI=7
# for python modules
PYTHON_COMPAT=( python{2_7,3_6} )

inherit python-r1 scons-utils

RDEPEND="${PYTHON_DEPS}"
# scons supports py2.7/pypy
BDEPEND="$(python_gen_any_dep 'dev-util/scons[${PYTHON_USEDEP}]' python2_7 pypy)"
REQUIRED_USE=${PYTHON_REQUIRED_USE}

python_check_deps() {
    has_version "dev-util/scons[${PYTHON_USEDEP}]"
}

src_compile() {
    # for scons
    python_setup python2_7 pypy
    escons # ...

    python_foreach_impl do_something_else
}