public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Aaron W. Swenson" <titanofold@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] New Eclasses: postgres and postgres-multi
Date: Mon, 25 Jan 2016 07:29:20 -0500	[thread overview]
Message-ID: <20160125122920.GG32165@martineau.grandmasfridge.local> (raw)
In-Reply-To: <56A561D7.8030708@gentoo.org>


[-- Attachment #1.1: Type: text/plain, Size: 1070 bytes --]

On 2016-01-24 18:44, Michael Orlitzky wrote:
> On 01/24/2016 06:29 PM, Aaron W. Swenson wrote:
> > Okay, provided that the new USE_EXPAND is okay for POSTGRES_TARGETS,
> > attached are the eclasses that I'll commit to the tree.
> > 
> 
> > case ${EAPI:-0} in
> >   0|1|2|3|4) die "postgres-multi.eclass requires EAPI 5 or higher" ;;
> >   *) ;;
> > esac
> 
> Does this really work with EAPI=6? I didn't try, but it looks like it
> would need an eapply_user somewhere in src_prepare. And, pedantry
> warning, there's no such thing as "EAPI 5 or higher." The lawyers will
> tell you to do something like this instead (stolen from git-r3):
> 
>   case "${EAPI:-0}" in
> 	  5|6)
> 		  ;;
> 	  *)
> 		  die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
> 		  ;;
>   esac
> 
> That will require an edit for every new EAPI, but prevents weird crashes
> from things like a missing eapply_user.
> 
> 

Thank you.

I've added the eapply_user to postgres-multi and modified the case
condition to match the hot goods you're selling on the sly.

[-- Attachment #1.2: postgres-multi.eclass --]
[-- Type: text/plain, Size: 4482 bytes --]

# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

inherit multibuild postgres
EXPORT_FUNCTIONS pkg_setup src_prepare src_compile src_install src_test


# @ECLASS: postgres-multi
# @MAINTAINER:
# PostgreSQL <pgsql-bugs@gentoo.org>
# @AUTHOR: Aaron W. Swenson <titanofold@gentoo.org>
# @BLURB: An eclass to build PostgreSQL-related packages against multiple slots
# @DESCRIPTION:
# postgres-multi enables ebuilds, particularly PostgreSQL extensions, to
# build against any and all compatible PostgreSQL slots that are also
# enabled by the user. Additionally makes a developer's life easier with
# exported default functions to do the right thing.


case ${EAPI:-0} in
  0|1|2|3|4) die "postgres-multi.eclass requires EAPI 5 or higher" ;;
  *) ;;
esac


# @ECLASS-VARIABLE: POSTGRES_COMPAT
# @REQUIRED
# @DESCRIPTION:
# A Bash array containing a list of compatible PostgreSQL slots as
# defined by the developer. Must be declared before inheriting this eclass.
if ! declare -p POSTGRES_COMPAT &>/dev/null; then
	die 'Required variable POSTGRES_COMPAT not declared.'
fi

# @ECLASS-VARIABLE: _POSTGRES_UNION_SLOTS
# @INTERNAL
# @DESCRIPTION:
# A Bash array containing the union set of user-enabled slots that are
# also in POSTGRES_COMPAT.
export _POSTGRES_UNION_SLOTS=( )

# @FUNCTION _postgres-multi_multibuild_wrapper
# @INTERNAL
# @USAGE: _postgres-multi_multibuild_wrapper <command> [<arg> ...]
# @DESCRIPTION:
# For the given variant, set the values of the PG_SLOT and PG_CONFIG
# environment variables accordingly and replace any appearance of
# @PG_SLOT@ in the command and arguments with value of ${PG_SLOT}.
_postgres-multi_multibuild_wrapper() {
	debug-print-function ${FUNCNAME} "${@}"
	export PG_SLOT=${MULTIBUILD_VARIANT}
	export PG_CONFIG=$(which pg_config${MULTIBUILD_VARIANT//./})
	$(echo "${@}" | sed "s/@PG_SLOT@/${PG_SLOT}/g")
}

# @FUNCTION: postgres-multi_foreach
# @USAGE: postgres-multi_foreach <command> <arg> [<arg> ...]
# @DESCRIPTION:
# Run the given command in the package's source directory for each
# PostgreSQL slot in the union set of the developer defined
# POSTGRES_COMPAT and user-enabled slots. The PG_CONFIG environment
# variable is updated on each iteration to point to the matching
# pg_config command for the current slot. Any appearance of @PG_SLOT@ in
# the command or arguments will be substituted with the slot (e.g., 9.5)
# of the current iteration.
postgres-multi_foreach() {
	local MULTIBUILD_VARIANTS=("${_POSTGRES_UNION_SLOTS[@]}")

	multibuild_foreach_variant \
		_postgres-multi_multibuild_wrapper run_in_build_dir ${@}
}

# @FUNCTION: postgres-multi_forbest
# @USAGE: postgres-multi_forbest <command> <arg> [<arg> ...]
# @DESCRIPTION:
# Run the given command in the package's source directory for the best,
# compatible PostgreSQL slot. The PG_CONFIG environment variable is set
# to the matching pg_config command. Any appearance of @PG_SLOT@ in the
# command or arguments will be substituted with the matching slot (e.g., 9.5).
postgres-multi_forbest() {
	# POSTGRES_COMPAT is reverse sorted once in postgres.eclass so
	# element 0 has the highest slot version.
	local MULTIBUILD_VARIANTS=("${_POSTGRES_UNION_SLOTS[0]}")

	multibuild_foreach_variant \
		_postgres-multi_multibuild_wrapper run_in_build_dir ${@}
}

# @FUNCTION: postgres-multi_pkg_setup
# @USAGE: postgres-multi_pkg_setup
# @DESCRIPTION:
# Initialize internal environment variable(s). This is required if
# pkg_setup() is declared in the ebuild.
postgres-multi_pkg_setup() {
	local user_slot

	for user_slot in "${POSTGRES_COMPAT[@]}"; do
		use "postgres_targets_postgres${user_slot/\./_}" && \
			_POSTGRES_UNION_SLOTS+=( "${user_slot}" )
	done

	if [[ "${#_POSTGRES_UNION_SLOTS[@]}" -eq "0" ]]; then
		die "One of the postgres_targets_postgresSL_OT use flags must be enabled"
	fi

	elog "Multibuild variants: ${_POSTGRES_UNION_SLOTS[@]}"
}

postgres-multi_src_prepare() {
	if [[ "${#_POSTGRES_UNION_SLOTS[@]}" -eq "0" ]]; then
		eerror "Internal array _POSTGRES_UNION_SLOTS is empty."
		die "Did you forget to call postgres-multi_pkg_setup?"
	fi

	eapply_user

	local MULTIBUILD_VARIANT
	local MULTIBUILD_VARIANTS=("${_POSTGRES_UNION_SLOTS[@]}")
	multibuild_copy_sources
}

postgres-multi_src_compile() {
	postgres-multi_foreach emake
}

postgres-multi_src_install() {
	postgres-multi_foreach emake install DESTDIR="${D}"
}

postgres-multi_src_test() {
	postgres-multi_foreach emake installcheck
}

[-- Attachment #1.3: postgres.eclass --]
[-- Type: text/plain, Size: 3828 bytes --]

# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

inherit user

# @ECLASS: postgres
# @MAINTAINER:
# PostgreSQL <pgsql-bugs@gentoo.org>
# @AUTHOR: Aaron W. Swenson <titanofold@gentoo.org>
# @BLURB: An eclass for PostgreSQL-related packages
# @DESCRIPTION:
# This eclass provides common utility functions that many
# PostgreSQL-related packages perform, such as checking that the
# currently selected PostgreSQL slot is within a range, adding a system
# user to the postgres system group, and generating dependencies.


case ${EAPI:-0} in
	5|6) ;;
	*) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
esac


# @ECLASS-VARIABLE: POSTGRES_COMPAT
# @DESCRIPTION:
# A Bash array containing a list of compatible PostgreSQL slots as
# defined by the developer. If declared, must be declared before
# inheriting this eclass. Example: POSTGRES_COMPAT=( 9.4 9.{5,6} )

# @ECLASS-VARIABLE: POSTGRES_USEDEP
# @DESCRIPTION:
# Add the, without brackets, 2-Style and/or 4-Style use dependencies to
# be used for POSTGRES_DEP. If declared, must be declared before
# inheriting this eclass.

# @ECLASS-VARIABLE: POSTGRES_DEP
# @DESCRIPTION:
# An automatically generated dependency string suitable for use in
# DEPEND and RDEPEND declarations.

# @ECLASS-VARIABLE: POSTGRES_REQ_USE
# @DESCRIPTION:
# An automatically generated REQUIRED_USE-compatible string built upon
# POSTGRES_COMPAT. REQUIRED_USE="... ${POSTGRES_REQ_USE}" is only
# required if the package must build against one of the PostgreSQL slots
# declared in POSTGRES_COMPAT.

if declare -p POSTGRES_COMPAT &> /dev/null ; then
	# Reverse sort the given POSTGRES_COMPAT so that the most recent
	# slot is preferred over an older slot.
	# -- do we care if dependencies are deterministic by USE flags?
	readarray -t POSTGRES_COMPAT < <(printf '%s\n' "${POSTGRES_COMPAT[@]}" | sort -nr)

	POSTGRES_DEP=""
	POSTGRES_REQ_USE=" || ("
	for slot in "${POSTGRES_COMPAT[@]}" ; do
		POSTGRES_DEP+=" postgres_targets_postgres${slot/\./_}? ( dev-db/postgresql:${slot}="
		declare -p POSTGRES_USEDEP &>/dev/null && \
			POSTGRES_DEP+="[${POSTGRES_USEDEP}]"
		POSTGRES_DEP+=" )"

		IUSE+=" postgres_targets_postgres${slot/\./_}"
		POSTGRES_REQ_USE+=" postgres_targets_postgres${slot/\./_}"
	done
	POSTGRES_REQ_USE+=" )"
else
	POSTGRES_DEP="dev-db/postgresql:="
	declare -p POSTGRES_USEDEP &>/dev/null && \
		POSTGRES_DEP+="[${POSTGRES_USEDEP}]"
fi


# @FUNCTION: postgres_check_slot
# @DESCRIPTION:
# Verify that the currently selected PostgreSQL slot is set to one of
# the slots defined in POSTGRES_COMPAT. Automatically dies unless a
# POSTGRES_COMPAT slot is selected. Should be called in pkg_pretend().
postgres_check_slot() {
	if ! declare -p POSTGRES_COMPAT &>/dev/null; then
		die 'POSTGRES_COMPAT not declared.'
	fi

	# Don't die because we can't run postgresql-config during pretend.
	[[ "$EBUILD_PHASE" = "pretend" && -z "$(which postgresql-config 2> /dev/null)" ]] \
		&& return 0

	if has $(postgresql-config show 2> /dev/null) "${POSTGRES_COMPAT[@]}"; then
		return 0
	else
		eerror "PostgreSQL slot must be set to one of: "
		eerror "    ${POSTGRES_COMPAT[@]}"
		die "Incompatible PostgreSQL slot eselected"
	fi
}

# @FUNCTION: postgres_new_user
# @DESCRIPTION:
# Creates the "postgres" system group and user -- which is separate from
# the database user -- in addition to the developer defined user. Takes
# the same arguments as "enewuser".
postgres_new_user() {
	enewgroup postgres 70
	enewuser postgres 70 /bin/bash /var/lib/postgresql postgres

	if [[ $# -gt 0 ]] ; then
		if [[ "$1" = "postgres" ]] ; then
			ewarn "Username 'postgres' implied, skipping"
		else
			local groups=$5
			[[ -n "${groups}" ]] && groups+=",postgres" || groups="postgres"
			enewuser "$1" "$2" "$3" "$4" "${groups}"
		fi
	fi
}

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 345 bytes --]

  reply	other threads:[~2016-01-25 12:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-12 19:22 [gentoo-dev] New Eclasses: postgres and postgres-multi Aaron W. Swenson
2016-01-12 20:57 ` Manuel Rüger
2016-01-12 21:53   ` Aaron W. Swenson
2016-01-13 16:11     ` Ian Stakenvicius
2016-01-15 16:43       ` Aaron W. Swenson
2016-01-15 17:43         ` Ian Stakenvicius
2016-01-15 18:26           ` Ian Stakenvicius
2016-01-15 19:24           ` Aaron W. Swenson
2016-01-22 16:51             ` Ian Stakenvicius
2016-01-22 20:11               ` Aaron W. Swenson
2016-01-23 15:51                 ` Ian Stakenvicius
2016-01-25 15:31                   ` Ian Stakenvicius
2016-01-26 11:06                     ` Aaron W. Swenson
2016-01-24 23:29 ` Aaron W. Swenson
2016-01-24 23:44   ` Michael Orlitzky
2016-01-25 12:29     ` Aaron W. Swenson [this message]
2016-01-26  3:34       ` [gentoo-dev] " Jonathan Callen
2016-01-26 11:14         ` Aaron W. Swenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160125122920.GG32165@martineau.grandmasfridge.local \
    --to=titanofold@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox