> # @ECLASS_VARIABLE: DB_VERSIONS > # @REQUIRED > # @DESCRIPTION: > # This variable contains a list of sys-libs/db SLOT versions the package > # works with. Please always sort the list so that higher slot versions come > # first or else the package might not depend on the latest possible version of > # sys-libs/db > # > # Example: > # @CODE > # DB_VERSIONS=( 5.0 4.8 ) > # inherit db-use-r1 > # @CODE > # > # Please note that you can also use bash brace expansion if you like: > # @CODE > # DB_VERSIONS=( 5.{3,2,1,0} 4.8 ) > # inherit db-use-r1 > # @CODE > if ! declare -p DB_VERSIONS &>/dev/null; then > die "DB_VERSIONS not declared." > fi
You may want to add here an additional check if it is an array. Otherwise, you may end up with some random behavior when someone sets it to single string. > # @ECLASS-VARIABLE: DB_DEPS > # @DESCRIPTION: > # This eclass sets and exports DB_DEPS which should be uses as follows: > # > # @CODE > # RDEPEND="${DB_DEPEND}" > # @CODE DB_DEPS or DB_DEPEND? > # > # or > # > # @CODE > # RDEPEND="berkdb? ( ${DB_DEPEND} )" > # @CODE > DB_DEPEND="" > if [ "${#DB_VERSIONS[@]}" -gt 1 ] ; then > DB_DEPEND="|| (" > fi I think it's perfectly valid to have '|| ( single-atom )'. IMO it's not worth the effort to add it conditionally. > for db_slotver in ${DB_VERSIONS[@]} ; do > DB_DEPEND+=" sys-libs/db:${db_slotver}" > done You can do it without the loop: DB_DEPEND+=${DB_VERSIONS[@]/#/ sys-libs/db:} > if [ "${#DB_VERSIONS[@]}" -gt 1 ] ; then > DB_DEPEND+=" )" > fi > export DB_DEPEND > [[ ! -n ${DB_DEPEND} ]] && die "Cannot assing sys-libs/db dependency" Looks like impossible to me. Well, unless DB_VERSIONS are empty but then it looks like erring on the result rather than reason. > inherit versionator multilib > > # @FUNCTION: db_ver_to_slot > # @USAGE: <db-version> > # @DESCRIPTION: > # Convert a version to a db slot. You need to submit at least the first two > # Version components > # This is meant for ebuilds using the real version number of a sys-libs/db > # package. This eclass doesn't use it internally. > db_ver_to_slot() { > if [ $# -ne 1 ]; then > eerror "Function db_ver_to_slot needs one argument" >&2 Shouldn't eerror use stderr on itself? > eerror "args given:" >&2 > for f in $@ Missing quoting. > do > eerror " - \"$@\"" >&2 > done > return 1 > fi > if [ "$(get_version_component_count $1)" -lt 2 ] ; then > eerror "db_ver_to_slot function needs at least a version > component" > eerror "count of two." > return 1 'die', please. > fi > echo -n "$(get_version_component_range 1-2 $1)" Just FYI, '-n' is not really necessary here since shell automatically strips trailing newline in $(). > } > > # @FUNCTION: db_findver > # @USAGE: > # @DESCRIPTION: > # Find the highest installed db version that fits DB_VERSIONS > db_findver() { > local db_slotver > for db_slotver in ${DB_VERSIONS[@]} ; do > if has_version sys-libs/db:${db_slotver} \ > && [ -d "/usr/include/db${db_slotver}" ] ; then Why do you need both checks? > echo -n "${db_slotver}" > return 0 > fi > done > return 1 > } > > # @FUNCTION: db_includedir > # @USAGE: > # @DESCRIPTION: > # Get the include dir for berkeley db. This function returns the best version > # found by db_findver() > db_includedir() { > VER="$(db_findver)" || return 1 Shouldn't this be 'local'? > einfo "include version ${VER}" >&2 Looks more like debug-print candidate. Or, at least mention 'berkdb' somewhere since user will have no idea 'version of what'. > if [ -d "/usr/include/db${VER}" ]; then > echo -n "/usr/include/db${VER}" > return 0 > else > eerror "sys-libs/db package requested, but headers not found" > >&2 > return 1 > fi > } > > # @FUNCTION: db_libname > # @USAGE: > # @DESCRIPTION: > # Get the library name for berkeley db. Something like "db-4.2" will be the > # outcome. This function returns the best version found by db_findver() > db_libname() { > VER="$(db_findver)" || return 1 > if [ -e "/usr/$(get_libdir)/libdb-${VER}.so" ]; then > echo -n "db-${VER}" > return 0 > else > eerror "sys-libs/db package requested, but library not found" > >&2 > return 1 > fi > } -- Best regards, Michał Górny
signature.asc
Description: PGP signature