Gentoo Archives: gentoo-commits

From: Benda XU <heroxbd@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Mon, 04 Sep 2017 06:27:49
Message-Id: 1504506454.36c48e29867d7460dd5a9da1ca198ed6e97238e6.heroxbd@gentoo
1 commit: 36c48e29867d7460dd5a9da1ca198ed6e97238e6
2 Author: Benda Xu <heroxbd <AT> gentoo <DOT> org>
3 AuthorDate: Mon Sep 4 06:07:10 2017 +0000
4 Commit: Benda XU <heroxbd <AT> gentoo <DOT> org>
5 CommitDate: Mon Sep 4 06:27:34 2017 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=36c48e29
7
8 prefix.eclass: extend the hprefixify to accept quotes.
9
10 also apply the pattern substitution to beginning of lines.
11
12 eclass/prefix.eclass | 26 ++++++++++++++++++--------
13 1 file changed, 18 insertions(+), 8 deletions(-)
14
15 diff --git a/eclass/prefix.eclass b/eclass/prefix.eclass
16 index 56aedc81422..eb5843182f3 100644
17 --- a/eclass/prefix.eclass
18 +++ b/eclass/prefix.eclass
19 @@ -48,7 +48,8 @@ eprefixify() {
20 }
21
22 # @FUNCTION: hprefixify
23 -# @USAGE: [ -w <line match> ] [-e <extended regex> ] <list of files>
24 +# @USAGE: [ -w <line match> ] [ -e <extended regex> ] [ -q <quotation char> ]
25 +# <list of files>
26 # @DESCRIPTION:
27 # Tries a set of heuristics to prefixify the given files. Dies if no
28 # arguments are given, a file does not exist, or changing a file failed.
29 @@ -56,7 +57,10 @@ eprefixify() {
30 # Additional extended regular expression can be passed by -e or
31 # environment variable PREFIX_EXTRA_REGEX. The default heuristics can
32 # be constrained to lines that match a sed expression passed by -w or
33 -# environment variable PREFIX_LINE_MATCH.
34 +# environment variable PREFIX_LINE_MATCH. Quotation characters can be
35 +# specified by -q or environment variable PREFIX_QUOTE_CHAR, unless
36 +# EPREFIX is empty.
37 +#
38 # @EXAMPLE:
39 # Only prefixify the 30th line,
40 # hprefixify -w 30 configure
41 @@ -64,18 +68,21 @@ eprefixify() {
42 # hprefixify -w "/PATH/" configure
43 # Also delete all the /opt/gnu search paths,
44 # hprefixify -e "/\/opt\/gnu/d" configure
45 +# Quote the inserted EPREFIX
46 +# hprefixify -q '"' etc/profile
47 hprefixify() {
48 use prefix || return 0
49
50 - local PREFIX_EXTRA_REGEX PREFIX_LINE_MATCH xl=() x
51 + local xl=() x
52 while [[ $# -gt 0 ]]; do
53 case $1 in
54 - -e)
55 - PREFIX_EXTRA_REGEX="$2"
56 + -e) local PREFIX_EXTRA_REGEX="$2"
57 + shift
58 + ;;
59 + -w) local PREFIX_LINE_MATCH="$2"
60 shift
61 ;;
62 - -w)
63 - PREFIX_LINE_MATCH="$2"
64 + -q) local PREFIX_QUOTE_CHAR="${EPREFIX:+$2}"
65 shift
66 ;;
67 *)
68 @@ -84,6 +91,8 @@ hprefixify() {
69 esac
70 shift
71 done
72 + local dirs="/(usr|lib(|[onx]?32|n?64)|etc|bin|sbin|var|opt|run)" \
73 + eprefix="${PREFIX_QUOTE_CHAR}${EPREFIX}${PREFIX_QUOTE_CHAR}"
74
75 [[ ${#xl[@]} -lt 1 ]] && die "at least one file operand is required"
76 einfo "Adjusting to prefix ${EPREFIX:-/}"
77 @@ -91,7 +100,8 @@ hprefixify() {
78 if [[ -e ${x} ]] ; then
79 ebegin " ${x##*/}"
80 sed -r \
81 - -e "${PREFIX_LINE_MATCH}s,([^[:alnum:]}\)\.])/(usr|lib(|[onx]?32|n?64)|etc|bin|sbin|var|opt|run),\1${EPREFIX}/\2,g" \
82 + -e "${PREFIX_LINE_MATCH}s,([^[:alnum:]}\)\.])${dirs},\1${eprefix}/\2,g" \
83 + -e "${PREFIX_LINE_MATCH}s,^${dirs},${eprefix}/\1," \
84 -e "${PREFIX_EXTRA_REGEX}" \
85 -i "${x}"
86 eend $? || die "failed to prefixify ${x}"