From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0348B13832E for ; Thu, 21 Jul 2016 02:19:44 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 04D9021C176; Thu, 21 Jul 2016 02:19:42 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 11C3A21C038 for ; Thu, 21 Jul 2016 02:19:40 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id C8E60340DF0 for ; Thu, 21 Jul 2016 02:19:39 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id C60527C9 for ; Thu, 21 Jul 2016 02:19:36 +0000 (UTC) From: "Benda XU" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Benda XU" Message-ID: <1468741675.f940e6ec473b0e918c6bde8801ca17d88f9834b0.heroxbd@gentoo> Subject: [gentoo-commits] proj/android:master commit in: eclass/ X-VCS-Repository: proj/android X-VCS-Files: eclass/prefix.eclass X-VCS-Directories: eclass/ X-VCS-Committer: heroxbd X-VCS-Committer-Name: Benda XU X-VCS-Revision: f940e6ec473b0e918c6bde8801ca17d88f9834b0 X-VCS-Branch: master Date: Thu, 21 Jul 2016 02:19:36 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 9b3a1389-0f84-446c-bafb-e17b03b037b1 X-Archives-Hash: d4562159f25fb81cae9c590d231699b3 Message-ID: <20160721021936.K3Co201aduXKdVQUYw4JdBXF_rx5_Nb1umXeXJMsBsQ@z> commit: f940e6ec473b0e918c6bde8801ca17d88f9834b0 Author: Benda Xu gmail com> AuthorDate: Sun Jul 17 07:47:55 2016 +0000 Commit: Benda XU gentoo 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: # @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 ] [-e ] +# @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: # @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