El sáb, 12-01-2013 a las 04:49 -0800, Zac Medico escribió:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 01/12/2013 02:34 AM, Pacho Ramos wrote:
> > El sáb, 12-01-2013 a las 02:01 -0800, Zac Medico escribió:
> >> On 01/12/2013 01:46 AM, Pacho Ramos wrote:
> >>> El mié, 09-01-2013 a las 12:04 -0800, Zac Medico escribió:
> >>>> On 01/09/2013 11:53 AM, Pacho Ramos wrote:
> >>>>> This changes the name of eclass to readme.gentoo.eclass and
> >>>>> gets information from ${FILESDIR}/README.gentoo
> >>>> 
> >>>> What if there are multiple versions/slots that have
> >>>> different README.gentoo content? Maybe the eclass should
> >>>> accommodate that somehow?
> >>> 
> >>> This should work, it will read DOC_CONTENTS variable from
> >>> ebuild and, if not set, rely on common
> >>> ${FILESDIR}/README.gentoo
> >> 
> >> You might add a loop to search for a version-specific
> >> README.gentoo, like this:
> >> 
> >> file= for suffix in -${PV} -${PV}-${PR} "" ; do [[ -f
> >> ${FILESDIR}/README.gentoo${suffix} ]] && \ 
> >> file=${FILESDIR}/README.gentoo${suffix}  && break done if [[
> >> ${file} ]] ; then cp "${file}" "${T}"/README.gentoo dodoc
> >> "${T}"/README.gentoo fi
> >> 
> > 
> > Thank for explaining me how to do that. The problem is that I doubt
> > if it would really be useful as we usually won't need whan
> > README.gentoo per version, only to update if for some special cases
> > from time to time :/
> > 
> > For example: foo-1.0 relies on common README.gentoo file, foo-1.1
> > adds new feature and, then, would use README.gentoo-1.1 file... but
> > foo-1.2 will probably use the same README.gentoo-1.1 file :|
> 
> Still, it maybe it would be reasonable to use a different
> README.gentoo for each SLOT, it there's more than one? Maybe it makes
> more sense to have another variable like DOC_CONTENTS, but have it
> refer to a filename? Then you should have multiple revisions of an
> ebuild refer to the same file, without having to have duplicate
> CONTENTS settings.
> - -- 
> Thanks,
> Zac

What about this approach?
# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# @ECLASS: readme.gentoo
# @MAINTAINER:
# Pacho Ramos <pa...@gentoo.org>
# @AUTHOR:
# Author: Pacho Ramos <pa...@gentoo.org>
# @BLURB: An eclass for installing a README.gentoo doc file recording tips
# shown via elog messages. With this eclass, those elog messages will only be
# shown at first package installation and a file for later reviewing will be
# installed under /usr/share/doc/${PF}
# @DESCRIPTION:
# An eclass for installing a README.gentoo doc file recording tips           
# shown via elog messages. With this eclass, those elog messages will only be
# shown at first package installation and a file for later reviewing will be
# installed under /usr/share/doc/${PF}

if [[ ${___ECLASS_ONCE_README_GENTOO} != "recur -_+^+_- spank" ]] ; then
___ECLASS_ONCE_README_GENTOO="recur -_+^+_- spank"

inherit eutils

case "${EAPI:-0}" in
	0|1|2|3)
		die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
		;;
	4|5)
		# EAPI>=4 is required for REPLACING_VERSIONS preventing us
		# from needing to export another pkg_preinst phase to save has_version
		# result. Also relies on EAPI >=4 default src_install phase.
		;;
	*)
		die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
		;;
esac

EXPORT_FUNCTIONS src_install pkg_postinst

# @FUNCTION: readme.gentoo_create_doc
# @DESCRIPTION:
# Create doc file with ${DOC_CONTENTS} variable and, if not set,
# with "${FILESDIR}/README.gentoo" contents.
# Usually called at src_install phase.
readme.gentoo_create_doc() {
	debug-print-function ${FUNCNAME} "${@}"

	if [[ -n "${DOC_CONTENTS}" ]]; then
		eshopts_push
		set -f
		echo ${DOC_CONTENTS} | fmt > "${T}"/README.gentoo
		eshopts_pop
		dodoc "${T}"/README.gentoo
	else
		if [[ -f "${FILESDIR}/README.gentoo-${SLOT}" ]]; then
			cp "${FILESDIR}/README.gentoo-${SLOT}" "${T}"/README.gentoo
			dodoc "${T}"/README.gentoo
		else
			if [[ -f "${FILESDIR}/README.gentoo" ]]; then
				cp "${FILESDIR}/README.gentoo" "${T}"/README.gentoo
				dodoc "${T}"/README.gentoo
			else
				die "You are not specifying README.gentoo contents!"
			fi
		fi
	fi
}

# @FUNCTION: readme.gentoo_print_elog
# @DESCRIPTION:
# Print elog messages with "${T}"/README.gentoo contents.
# Usually called at pkg_postinst phase.
readme.gentoo_print_elog() {
	debug-print-function ${FUNCNAME} "${@}"

	if [[ -f "${FILESDIR}/README.gentoo-${SLOT}" ]]; then
		if [[ -f "${T}"/README.gentoo ]]; then
			if ! [[ "${REPLACING_VERSIONS}:${SLOT}" ]]; then
				eshopts_push
				set -f
				cat "${T}"/README.gentoo | fmt | while read -r ELINE; do elog "${ELINE}"; done
				eshopts_pop
			fi
		else
			die "README.gentoo wasn't created at src_install!"
		fi
	else
		if [[ -f "${T}"/README.gentoo ]]; then
			if ! [[ "${REPLACING_VERSIONS}" ]]; then
				eshopts_push
				set -f
				cat "${T}"/README.gentoo | fmt | while read -r ELINE; do elog "${ELINE}"; done
				eshopts_pop
			fi
		else
			die "README.gentoo wasn't created at src_install!"
		fi
	fi
}


# @FUNCTION: readme.gentoo_src_install
# @DESCRIPTION:
# Show elog messages from DOC_CONTENTS variable, that will be
# shared with /usr/share/doc/${PF}/README.gentoo content.
readme.gentoo_src_install() {
	debug-print-function ${FUNCNAME} "${@}"

	default
	readme.gentoo_create_doc
}

# @FUNCTION: readme.gentoo_pkg_postinst
# @DESCRIPTION:
# Show elog messages from DOC_CONTENTS variable, that will be
# shared with /usr/share/doc/${PF}/README.gentoo content.
readme.gentoo_pkg_postinst() {
	debug-print-function ${FUNCNAME} "${@}"
	readme.gentoo_print_elog
}

fi

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to