# Copyright 1999-2016 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id$ # Description: eblit.eclass contains the core functions for creating "eblits". # eblits are a place to store common code shared among multiple # ebuilds for a specific package. # # Original Eblit Author: Mike Frysinger # Original Eclass Author: Joshua Kinard # Maintainer: base-system@gentoo.org # Implementation Note: Since code in an eblit is used by multiple ebuilds, # PLEASE revbump the eblit files when changes are made. Then update each # ebuild to use the new eblit version. Remove old eblit versions when there # are no more consumers. This makes it a lot easier to debug problems with # the shared code within an eblit, as well as the affected ebuilds. # To create an eblit: # 1. Create an "eblits" subdirectory under ${FILESDIR}, if one does not # already exist. # 2. Create a new file name using the following formula: # [a-z0-9_]-v[0-9]+.eblit # 3. Add the shared code, save, and close the file. # # Try to keep eblits specific to the functions they implement. E.g., if a # number of ebuilds have a large, but common src_unpack() function, and it # is not already provided by an eclass, then add that code to an eblit named # "src_unpack-vX.eblit". # To load and use eblits: # 1. Inherit the "eblit" eclass (this class). # 2. Define a new function called "load_eblit_funcs" in the ebuild immediately # after the global ebuild variables # eblit-core # Usage: [version] # Main eblit engine eblit-core() { local e v func=$1 ver=$2 for v in ${ver:+-}${ver} -${PVR} -${PV} "" ; do e="${FILESDIR}/eblits/${func}${v}.eblit" if [[ -e ${e} ]] ; then . "${e}" [[ ${func} == pkg_* ]] && eval "${func}() { eblit-run ${func} ${ver} ; }" return 0 fi done return 1 } # eblit-include # Usage: [--skip] [version] # Includes an "eblit" -- a chunk of common code among ebuilds in a given # package so that its functions can be sourced and utilized within the # ebuild. eblit-include() { local skipable=false r=0 [[ $1 == "--skip" ]] && skipable=true && shift [[ $1 == pkg_* ]] && skipable=true [[ -z $1 ]] && die "Usage: eblit-include [version]" eblit-core $1 $2 r="$?" ${skipable} && return 0 [[ "$r" -gt "0" ]] && die "Could not locate requested eblit '$1' in ${FILESDIR}/eblits/" } # eblit-run-maybe # Usage: # Runs a function if it is defined in an eblit eblit-run-maybe() { [[ $(type -t "$@") == "function" ]] && "$@" } # eblit-run # Usage: [version] # Runs a function defined in an eblit eblit-run() { eblit-include --skip common "${*:2}" eblit-include "$@" eblit-run-maybe eblit-$1-pre eblit-${PN}-$1 eblit-run-maybe eblit-$1-post } # eblit-pkg # Usage: [version] # Runs the pkg_* functions AND evals them so they're included in the binpkgs eblit-pkg() { [[ -z $1 ]] && die "Usage: eblit-pkg [version]" eblit-core pkg_$1 $2 }