* [gentoo-dev] RFC: extension to prefix.eclass
@ 2016-06-29 1:54 99% Benda Xu
0 siblings, 0 replies; 1+ results
From: Benda Xu @ 2016-06-29 1:54 UTC (permalink / raw
To: gentoo-dev
[-- Attachment #1: Type: text/plain, Size: 273 bytes --]
Hi,
This is a patch to extend prefix.eclass.
1. a set of heuristics is added to eprefixify:
"s,([^[:alnum:]}])/(usr|etc|bin|sbin|var|opt)/,\1${EPREFIX}/\2/,g"
2. a function wrapper "fprefixity" to do inplace substitution in ${T}.
Please help review it.
Benda
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: prefix.patch --]
[-- Type: text/x-diff, Size: 2858 bytes --]
--- prefix.eclass 2015-08-09 09:38:18.000000000 +0900
+++ prefix.eclass.new 2016-06-29 10:45:00.101628307 +0900
@@ -25,20 +25,36 @@
# @FUNCTION: eprefixify
-# @USAGE: <list of to be eprefixified files>
+# @USAGE: [-e <extended regex>] <list of to be eprefixified files>
# @DESCRIPTION:
-# replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
-# dies if no arguments are given, a file does not exist, or changing a
+# Replaces @GENTOO_PORTAGE_EPREFIX@ with ${EPREFIX} for the given files,
+# tries a set of heuristics if @GENTOO_PORTAGE_EPREFIX@ is not found.
+# Additional extended regular expression can be passed by -e or
+# environment variable PREFIX_EXTRA_REGEX.
+# 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"
+ local PREFIX_EXTRA_REGEX
+ if [[ ${1} == -e ]]; then
+ PREFIX_EXTRA_REGEX="${2}"
+ shift 2
+ fi
+ [[ $# -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##*/}"
- sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}"
+ if grep -qs @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" \
+ -e "${PREFIX_EXTRA_REGEX}" \
+ -i "${x}"
+ fi
eend $? || die "failed to eprefixify ${x}"
else
die "${x} does not exist"
@@ -48,5 +64,54 @@
return 0
}
+# @FUNCTION: __temp_prefixify
+# @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}
+ else
+ die "$1 does not exist"
+ fi
+}
+
+# @FUNCTION: fprefixify
+# @USAGE: <function> <files>
+# @DESCRIPTION:
+# prefixify a function call.
+# copies the files to ${T}, calls eprefixify, and calls the function.
+# @EXAMPLE:
+# fprefixify doexe ${FILESDIR}/fix_libtool_files.sh
+# fprefixify epatch ${FILESDIR}/${PN}-4.0.2-path.patch
+fprefixify() {
+ [[ $# -lt 2 ]] && die "at least two arguments required"
+
+ local func=$1 f
+ einfo "Adjusting ${func} to prefix ${EPREFIX:-/}"
+ shift
+ case ${func} in
+ new*)
+ [[ $# -ne 2 ]] && die "${func} takes two arguments"
+ ebegin " ${1##*/}"
+ f=$(__temp_prefixify "$1")
+ ${func} "${f}" "$2"
+ eend $? || die "failed to execute ${func}"
+ ;;
+ *)
+ for x in "$@" ; do
+ ebegin " ${x##*/}"
+ f=$(__temp_prefixify "${x}")
+ ${func} "${f}"
+ eend $? || die "failed to execute ${func}"
+ done
+ ;;
+ esac
+
+ return 0
+}
# vim: tw=72:
^ permalink raw reply [relevance 99%]
Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-06-29 1:54 99% [gentoo-dev] RFC: extension to prefix.eclass Benda Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox