summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenda Xu <heroxbd@gentoo.org>2017-09-04 15:07:10 +0900
committerBenda Xu <heroxbd@gentoo.org>2017-09-04 15:27:34 +0900
commit36c48e29867d7460dd5a9da1ca198ed6e97238e6 (patch)
treef1201787acfa38b97106bca3d3556da7aa72e3ff /eclass/prefix.eclass
parentdev-ruby/sprockets-rails: add 3.2.1 (diff)
downloadgentoo-36c48e29867d7460dd5a9da1ca198ed6e97238e6.tar.gz
gentoo-36c48e29867d7460dd5a9da1ca198ed6e97238e6.tar.bz2
gentoo-36c48e29867d7460dd5a9da1ca198ed6e97238e6.zip
prefix.eclass: extend the hprefixify to accept quotes.
also apply the pattern substitution to beginning of lines.
Diffstat (limited to 'eclass/prefix.eclass')
-rw-r--r--eclass/prefix.eclass26
1 files changed, 18 insertions, 8 deletions
diff --git a/eclass/prefix.eclass b/eclass/prefix.eclass
index 56aedc81422..eb5843182f3 100644
--- a/eclass/prefix.eclass
+++ b/eclass/prefix.eclass
@@ -48,7 +48,8 @@ eprefixify() {
}
# @FUNCTION: hprefixify
-# @USAGE: [ -w <line match> ] [-e <extended regex> ] <list of files>
+# @USAGE: [ -w <line match> ] [ -e <extended regex> ] [ -q <quotation char> ]
+# <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.
@@ -56,7 +57,10 @@ eprefixify() {
# Additional extended regular expression can be passed by -e or
# environment variable PREFIX_EXTRA_REGEX. The default heuristics can
# be constrained to lines that match a sed expression passed by -w or
-# environment variable PREFIX_LINE_MATCH.
+# environment variable PREFIX_LINE_MATCH. Quotation characters can be
+# specified by -q or environment variable PREFIX_QUOTE_CHAR, unless
+# EPREFIX is empty.
+#
# @EXAMPLE:
# Only prefixify the 30th line,
# hprefixify -w 30 configure
@@ -64,18 +68,21 @@ eprefixify() {
# hprefixify -w "/PATH/" configure
# Also delete all the /opt/gnu search paths,
# hprefixify -e "/\/opt\/gnu/d" configure
+# Quote the inserted EPREFIX
+# hprefixify -q '"' etc/profile
hprefixify() {
use prefix || return 0
- local PREFIX_EXTRA_REGEX PREFIX_LINE_MATCH xl=() x
+ local xl=() x
while [[ $# -gt 0 ]]; do
case $1 in
- -e)
- PREFIX_EXTRA_REGEX="$2"
+ -e) local PREFIX_EXTRA_REGEX="$2"
+ shift
+ ;;
+ -w) local PREFIX_LINE_MATCH="$2"
shift
;;
- -w)
- PREFIX_LINE_MATCH="$2"
+ -q) local PREFIX_QUOTE_CHAR="${EPREFIX:+$2}"
shift
;;
*)
@@ -84,6 +91,8 @@ hprefixify() {
esac
shift
done
+ local dirs="/(usr|lib(|[onx]?32|n?64)|etc|bin|sbin|var|opt|run)" \
+ eprefix="${PREFIX_QUOTE_CHAR}${EPREFIX}${PREFIX_QUOTE_CHAR}"
[[ ${#xl[@]} -lt 1 ]] && die "at least one file operand is required"
einfo "Adjusting to prefix ${EPREFIX:-/}"
@@ -91,7 +100,8 @@ hprefixify() {
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|run),\1${EPREFIX}/\2,g" \
+ -e "${PREFIX_LINE_MATCH}s,([^[:alnum:]}\)\.])${dirs},\1${eprefix}/\2,g" \
+ -e "${PREFIX_LINE_MATCH}s,^${dirs},${eprefix}/\1," \
-e "${PREFIX_EXTRA_REGEX}" \
-i "${x}"
eend $? || die "failed to prefixify ${x}"