Re: [gentoo-dev] RFC: extension to prefix.eclass

2016-06-29 Thread Benda Xu
Hi anonymous reviewer,

R0b0t1  writes:

> What is it intended to solve?

To simplify ebuilds that need to call eprefixify.

> The current behavior seems to make more sense. Hiding defaults causes
> problems. 

I am not sure what you mean by "Hiding defaults". It is documented, not
hidden.

The regular expression
  
  "s,([^[:alnum:]}])/(usr|etc|bin|sbin|var|opt)/,\1${EPREFIX}/\2/,g"

is conesrvative.  And it will be scrutinized by the community.

Most files can be trivially prefixified by this regular expression.

Traditionally, we need generate a patch with @GENTOO_PORTAGE_EPREFIX@,
apply the patch and then eprefixify the source (which was
"s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g").  We need a lot of such
trivial patches and it is not version-bump-proof.

Having a sane default improves maintainability.  That's the point of
ebuild helpers and eclasses.

> `fprefixify` is redundant.

No, it's not redundant.  An example of fprefixify is attached.

Benda

--- a/app-shells/bash/bash-4.3_p42-r2.ebuild
+++ b/app-shells/bash/bash-4.3_p42-r2.ebuild
@@ -88,11 +88,7 @@ src_prepare() {
 	epatch "${FILESDIR}"/${PN}-4.3-mapfile-improper-array-name-validation.patch
 	epatch "${FILESDIR}"/${PN}-4.3-arrayfunc.patch
 
-	epatch "${FILESDIR}"/${PN}-4.0-configs-prefix.patch
-	eprefixify pathnames.h.in
-	# modify the bashrc file for prefix
-	cp "${FILESDIR}"/bashrc "${T}"/ || die
-	eprefixify "${T}"/bashrc
+	fprefixify epatch "${FILESDIR}"/${PN}-4.0-configs-prefix.patch
 
 	epatch_user
 }
@@ -183,7 +179,7 @@ src_install() {
 
 	insinto /etc/bash
 	doins "${FILESDIR}"/bash_logout
-	doins "${T}"/bashrc
+	fprefixify doins "${FILESDIR}"/bashrc
 	keepdir /etc/bash/bashrc.d
 	insinto /etc/skel
 	for f in bash{_logout,_profile,rc} ; do


Re: [gentoo-dev] RFC: extension to prefix.eclass

2016-06-28 Thread R0b0t1
On Tue, Jun 28, 2016 at 8:54 PM, Benda Xu  wrote:
> Hi,
>
> This is a patch to extend prefix.eclass.
>
>   1. a set of heuristics is added to eprefixify:
>  "s,([^[:alnum:]}])/(usr|etc|bin|sbin|var|opt)/,\1${EPREFIX}/\2/,g"
>
>   2. a function wrapper "fprefixity" to do inplace substitution in ${T}.
>
> Please help review it.
> Benda
>

What is it intended to solve?

The current behavior seems to make more sense. Hiding defaults causes
problems. `fprefixify` is redundant.



[gentoo-dev] RFC: extension to prefix.eclass

2016-06-28 Thread Benda Xu
Hi,

This is a patch to extend prefix.eclass.

  1. a set of heuristics is added to eprefixify:
 "s,([^[:alnum:]}])/(usr|etc|bin|sbin|var|opt)/,\1${EPREFIX}/\2/,g"

  2. a function wrapper "fprefixity" to do inplace substitution in ${T}.

Please help review it.
Benda

--- prefix.eclass	2015-08-09 09:38:18.0 +0900
+++ prefix.eclass.new	2016-06-29 10:45:00.101628307 +0900
@@ -25,20 +25,36 @@
 
 
 # @FUNCTION: eprefixify
-# @USAGE: 
+# @USAGE: [-e ] 
 # @DESCRIPTION:
-# replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
-# dies if no arguments are given, a file does not exist, or changing a
+# Replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
+# tries a set of heuristics if @GENTOO_PORTAGE_EPREFIX@ is not found.
+# Additional extended regular expression can be passed by -e or
+# environment variable PREFIX_EXTRA_REGEX.
+# Dies if no arguments are given, a file does not exist, or changing a
 # file failed.
 eprefixify() {
 	[[ $# -lt 1 ]] && die "at least one argument required"
+	local PREFIX_EXTRA_REGEX
+	if [[ ${1} == -e ]]; then
+		PREFIX_EXTRA_REGEX="${2}"
+		shift 2
+	fi
 
+	[[ $# -lt 1 ]] && die "at least one file operand is required"
 	einfo "Adjusting to prefix ${EPREFIX:-/}"
 	local x
 	for x in "$@" ; do
 		if [[ -e ${x} ]] ; then
 			ebegin "  ${x##*/}"
-			sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}"
+			if grep -qs @GENTOO_PORTAGE_EPREFIX@ "${x}" ; then
+sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}"
+			else
+sed -r \
+	-e "s,([^[:alnum:]}])/(usr|etc|bin|sbin|var|opt)/,\1${EPREFIX}/\2/,g" \
+	-e "${PREFIX_EXTRA_REGEX}" \
+	-i "${x}"
+			fi
 			eend $? || die "failed to eprefixify ${x}"
 		else
 			die "${x} does not exist"
@@ -48,5 +64,54 @@
 	return 0
 }
 
+# @FUNCTION: __temp_prefixify
+# @USAGE: a single file. Internal use only.
+# @DESCRIPTION:
+# copies the files to ${T}, calls eprefixify, echos the new file.
+__temp_prefixify() {
+	if [[ -e $1 ]] ; then
+		local f=${1##*/}
+		cp "$1" "${T}" || die "failed to copy file"
+		eprefixify "${T}"/${f} > /dev/null
+		echo "${T}"/${f}
+	else
+		die "$1 does not exist"
+	fi
+}
+
+# @FUNCTION: fprefixify
+# @USAGE:  
+# @DESCRIPTION:
+# prefixify a function call.
+# copies the files to ${T}, calls eprefixify, and calls the function.
+# @EXAMPLE:
+# fprefixify doexe ${FILESDIR}/fix_libtool_files.sh
+# fprefixify epatch ${FILESDIR}/${PN}-4.0.2-path.patch
+fprefixify() {
+	[[ $# -lt 2 ]] && die "at least two arguments required"
+
+	local func=$1 f
+	einfo "Adjusting ${func} to prefix ${EPREFIX:-/}"
+	shift
+	case ${func} in
+		new*)
+			[[ $# -ne 2 ]] && die "${func} takes two arguments"
+			ebegin "  ${1##*/}"
+			f=$(__temp_prefixify "$1")
+			${func} "${f}" "$2"
+			eend $? || die "failed to execute ${func}"
+			;;
+		*)
+			for x in "$@" ; do
+ebegin "  ${x##*/}"
+f=$(__temp_prefixify "${x}")
+${func} "${f}"
+eend $? || die "failed to execute ${func}"
+			done
+			;;
+	esac
+
+	return 0
+}
 
 # vim: tw=72: