public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Benda XU" <heroxbd@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] dev/heroxbd:master commit in: eclass/
Date: Thu, 21 Jul 2016 02:23:10 +0000 (UTC)	[thread overview]
Message-ID: <1468741675.f940e6ec473b0e918c6bde8801ca17d88f9834b0.heroxbd@gentoo> (raw)

commit:     f940e6ec473b0e918c6bde8801ca17d88f9834b0
Author:     Benda Xu <heroxbd <AT> gmail <DOT> com>
AuthorDate: Sun Jul 17 07:47:55 2016 +0000
Commit:     Benda XU <heroxbd <AT> gentoo <DOT> org>
CommitDate: Sun Jul 17 07:47:55 2016 +0000
URL:        https://gitweb.gentoo.org/dev/heroxbd.git/commit/?id=f940e6ec

prefix.eclass: split the heuristics into hprefixify.

 eclass/prefix.eclass | 79 ++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 61 insertions(+), 18 deletions(-)

diff --git a/eclass/prefix.eclass b/eclass/prefix.eclass
index 40e5097..411b365 100644
--- a/eclass/prefix.eclass
+++ b/eclass/prefix.eclass
@@ -27,25 +27,17 @@ fi
 # @FUNCTION: eprefixify
 # @USAGE: <list of to be eprefixified files>
 # @DESCRIPTION:
-# replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
-# tries a set of heuristics if @GENTOO_PORTAGE_EPREFIX@ is not found,
-# dies if no arguments are given, a file does not exist, or changing a
+# Replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
+# 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"
-
+	[[ $# -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##*/}"
-			if grep -q @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" \
-					-i "${x}"
-			fi
+			sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}"
 			eend $? || die "failed to eprefixify ${x}"
 		else
 			die "${x} does not exist"
@@ -55,28 +47,78 @@ eprefixify() {
 	return 0
 }
 
+# @FUNCTION: hprefixify
+# @USAGE: [ -w <line matching regex> ] [-e <extended regex>] <list of files>
+# @DESCRIPTION:
+#
+# Tries a set of heuristics to prefixify the given files, Dies if no
+# arguments are given, a file does not exist, or changing a file failed.
+#
+# Additional extended regular expression can be passed by -e or
+# environment variable PREFIX_EXTRA_REGEX.  The default heuristics can
+# be constrained to lines matching regular expressions passed by -w or
+# environment variable PREFIX_LINE_MATCH.
+hprefixify() {
+	local PREFIX_EXTRA_REGEX PREFIX_LINE_MATCH xl=() x
+	while [[ $# -gt 0 ]]; do
+		case $1 in
+			-e)
+				PREFIX_EXTRA_REGEX="$2"
+				shift
+				;;
+			-w)
+				PREFIX_LINE_MATCHING="$2"
+				shift
+				;;
+			*)
+				xl+=( "$1" )
+				;;
+		esac
+		shift
+	done
+
+	[[ ${#xl[@]} -lt 1 ]] && die "at least one file operand is required"
+	einfo "Adjusting to prefix ${EPREFIX:-/}"
+	for x in "${xl[@]}" ; do
+		if [[ -e ${x} ]] ; then
+			ebegin "  ${x##*/}"
+			sed -r \
+				-e "${PREFIX_LINE_MATCH}s,([^[:alnum:]}\)\.])/(usr|lib(|[onx]?32|n?64)|etc|bin|sbin|var|opt),\1${EPREFIX}/\2,g" \
+				-e "${PREFIX_EXTRA_REGEX}" \
+				-i "${x}"
+			eend $? || die "failed to prefixify ${x}"
+		else
+			die "${x} does not exist"
+		fi
+	done
+}
+
 # @FUNCTION: __temp_prefixify
-# @USAGE: on a single file
+# @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}
+		local x="${T}"/${f}
+		if grep -qs @GENTOO_PORTAGE_EPREFIX@ "${x}" ; then
+			eprefixify "${T}"/${f} > /dev/null
+		else
+			hprefixify "${T}"/${f} > /dev/null
+		fi
+		echo "${x}"
 	else
 		die "$1 does not exist"
 	fi
 }
 
 # @FUNCTION: fprefixify
-# @USAGE: fprefixfy function files
+# @USAGE: <function> <files>
 # @DESCRIPTION:
 # prefixify a function call.
 # copies the files to ${T}, calls eprefixify, and calls the function.
-#
-# For example:
+# @EXAMPLE:
 # fprefixify doexe ${FILESDIR}/fix_libtool_files.sh
 # fprefixify epatch ${FILESDIR}/${PN}-4.0.2-path.patch
 fprefixify() {
@@ -100,6 +142,7 @@ fprefixify() {
 				${func} "${f}"
 				eend $? || die "failed to execute ${func}"
 			done
+			;;
 	esac
 
 	return 0


WARNING: multiple messages have this Message-ID (diff)
From: "Benda XU" <heroxbd@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/android:master commit in: eclass/
Date: Thu, 21 Jul 2016 02:19:36 +0000 (UTC)	[thread overview]
Message-ID: <1468741675.f940e6ec473b0e918c6bde8801ca17d88f9834b0.heroxbd@gentoo> (raw)
Message-ID: <20160721021936.K3Co201aduXKdVQUYw4JdBXF_rx5_Nb1umXeXJMsBsQ@z> (raw)

commit:     f940e6ec473b0e918c6bde8801ca17d88f9834b0
Author:     Benda Xu <heroxbd <AT> gmail <DOT> com>
AuthorDate: Sun Jul 17 07:47:55 2016 +0000
Commit:     Benda XU <heroxbd <AT> gentoo <DOT> org>
CommitDate: Sun Jul 17 07:47:55 2016 +0000
URL:        https://gitweb.gentoo.org/proj/android.git/commit/?id=f940e6ec

prefix.eclass: split the heuristics into hprefixify.

 eclass/prefix.eclass | 79 ++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 61 insertions(+), 18 deletions(-)

diff --git a/eclass/prefix.eclass b/eclass/prefix.eclass
index 40e5097..411b365 100644
--- a/eclass/prefix.eclass
+++ b/eclass/prefix.eclass
@@ -27,25 +27,17 @@ fi
 # @FUNCTION: eprefixify
 # @USAGE: <list of to be eprefixified files>
 # @DESCRIPTION:
-# replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
-# tries a set of heuristics if @GENTOO_PORTAGE_EPREFIX@ is not found,
-# dies if no arguments are given, a file does not exist, or changing a
+# Replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
+# 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"
-
+	[[ $# -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##*/}"
-			if grep -q @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" \
-					-i "${x}"
-			fi
+			sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}"
 			eend $? || die "failed to eprefixify ${x}"
 		else
 			die "${x} does not exist"
@@ -55,28 +47,78 @@ eprefixify() {
 	return 0
 }
 
+# @FUNCTION: hprefixify
+# @USAGE: [ -w <line matching regex> ] [-e <extended regex>] <list of files>
+# @DESCRIPTION:
+#
+# Tries a set of heuristics to prefixify the given files, Dies if no
+# arguments are given, a file does not exist, or changing a file failed.
+#
+# Additional extended regular expression can be passed by -e or
+# environment variable PREFIX_EXTRA_REGEX.  The default heuristics can
+# be constrained to lines matching regular expressions passed by -w or
+# environment variable PREFIX_LINE_MATCH.
+hprefixify() {
+	local PREFIX_EXTRA_REGEX PREFIX_LINE_MATCH xl=() x
+	while [[ $# -gt 0 ]]; do
+		case $1 in
+			-e)
+				PREFIX_EXTRA_REGEX="$2"
+				shift
+				;;
+			-w)
+				PREFIX_LINE_MATCHING="$2"
+				shift
+				;;
+			*)
+				xl+=( "$1" )
+				;;
+		esac
+		shift
+	done
+
+	[[ ${#xl[@]} -lt 1 ]] && die "at least one file operand is required"
+	einfo "Adjusting to prefix ${EPREFIX:-/}"
+	for x in "${xl[@]}" ; do
+		if [[ -e ${x} ]] ; then
+			ebegin "  ${x##*/}"
+			sed -r \
+				-e "${PREFIX_LINE_MATCH}s,([^[:alnum:]}\)\.])/(usr|lib(|[onx]?32|n?64)|etc|bin|sbin|var|opt),\1${EPREFIX}/\2,g" \
+				-e "${PREFIX_EXTRA_REGEX}" \
+				-i "${x}"
+			eend $? || die "failed to prefixify ${x}"
+		else
+			die "${x} does not exist"
+		fi
+	done
+}
+
 # @FUNCTION: __temp_prefixify
-# @USAGE: on a single file
+# @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}
+		local x="${T}"/${f}
+		if grep -qs @GENTOO_PORTAGE_EPREFIX@ "${x}" ; then
+			eprefixify "${T}"/${f} > /dev/null
+		else
+			hprefixify "${T}"/${f} > /dev/null
+		fi
+		echo "${x}"
 	else
 		die "$1 does not exist"
 	fi
 }
 
 # @FUNCTION: fprefixify
-# @USAGE: fprefixfy function files
+# @USAGE: <function> <files>
 # @DESCRIPTION:
 # prefixify a function call.
 # copies the files to ${T}, calls eprefixify, and calls the function.
-#
-# For example:
+# @EXAMPLE:
 # fprefixify doexe ${FILESDIR}/fix_libtool_files.sh
 # fprefixify epatch ${FILESDIR}/${PN}-4.0.2-path.patch
 fprefixify() {
@@ -100,6 +142,7 @@ fprefixify() {
 				${func} "${f}"
 				eend $? || die "failed to execute ${func}"
 			done
+			;;
 	esac
 
 	return 0


             reply	other threads:[~2016-07-21  2:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-21  2:23 Benda XU [this message]
2016-07-21  2:19 ` [gentoo-commits] proj/android:master commit in: eclass/ Benda XU
  -- strict thread matches above, loose matches on Subject: below --
2016-07-21  2:19 Benda XU
2016-07-21  2:23 ` [gentoo-commits] dev/heroxbd:master " Benda XU
2016-06-24  3:07 [gentoo-commits] proj/android:master " Benda XU
2016-07-21  2:23 ` [gentoo-commits] dev/heroxbd:master " Benda XU
2016-06-15 11:40 [gentoo-commits] proj/android:master " Benda XU
2016-07-21  2:23 ` [gentoo-commits] dev/heroxbd:master " Benda XU
2016-06-14  2:00 [gentoo-commits] proj/android:master " Benda XU
2016-07-21  2:23 ` [gentoo-commits] dev/heroxbd:master " Benda XU
2016-05-26  4:05 [gentoo-commits] proj/android:master " Benda XU
2016-05-26  4:04 ` [gentoo-commits] dev/heroxbd:master " Benda XU
2016-05-26  4:05 [gentoo-commits] proj/android:master " Benda XU
2016-05-26  4:04 ` [gentoo-commits] dev/heroxbd:master " Benda XU
2016-05-26  4:05 [gentoo-commits] proj/android:master " Benda XU
2016-05-23  6:18 ` [gentoo-commits] dev/heroxbd:master " Benda XU
2016-05-26  4:05 [gentoo-commits] proj/android:master " Benda XU
2016-05-23  6:18 ` [gentoo-commits] dev/heroxbd:master " Benda XU
2016-05-23 16:15 Benda XU
2016-05-23  6:18 Benda XU
2016-05-23  6:18 Benda XU
2016-05-23  6:18 Benda XU
2014-12-04  8:17 Benda XU
2014-11-24 15:41 Benda XU

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=1468741675.f940e6ec473b0e918c6bde8801ca17d88f9834b0.heroxbd@gentoo \
    --to=heroxbd@gentoo.org \
    --cc=gentoo-commits@lists.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