commit: 36c48e29867d7460dd5a9da1ca198ed6e97238e6 Author: Benda Xu <heroxbd <AT> gentoo <DOT> org> AuthorDate: Mon Sep 4 06:07:10 2017 +0000 Commit: Benda XU <heroxbd <AT> gentoo <DOT> org> CommitDate: Mon Sep 4 06:27:34 2017 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=36c48e29
prefix.eclass: extend the hprefixify to accept quotes. also apply the pattern substitution to beginning of lines. eclass/prefix.eclass | 26 ++++++++++++++++++-------- 1 file 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}"