From: Jeroen Roovers <jer@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] RFC: sed script redundancy
Date: Mon, 10 Jun 2013 05:47:49 +0200 [thread overview]
Message-ID: <20130610054749.64add1da@marga.jer-c2.orkz.net> (raw)
In-Reply-To: <20110520173922.391ea292@epia.jer-c2.orkz.net>
[-- Attachment #1: Type: text/plain, Size: 499 bytes --]
On Fri, 20 May 2011 17:39:22 +0200
Jeroen Roovers <jer@gentoo.org> wrote:
> for a while now I've been wondering if all those sed scripts in all
> those ebuilds are really effective.
This took rather long to find some spare time for.
Plonk the attached bash script into /etc/portage/bashrc.d (which you
source in /etc/portage/bashrc or something) and you should probably be
on your merry way.
The script probably doesn't catch all cases, but sed use in most
ebuilds is pretty standard.
jer
[-- Attachment #2: sed --]
[-- Type: text/plain, Size: 1209 bytes --]
#!/bin/bash
SED=$(type -P sed)
sed() {
case ${FUNCNAME[1]} in
# we only care about direct calls in some ebuild phases
src_prepare|src_configure|src_compile|src_install)
local arg args file files scripts
while [[ $# -gt 0 ]]; do
arg="${1}"
if [ -f "${arg}" ]; then
files+=" ${arg}"
else
case ${arg} in
-e) : ;;
--expression=*) scripts+=( "${arg/--expression=}" ) ;;
-i*|--in-place=*) : ;;
-f)
local scriptfile="${arg}"
shift
scriptfile+=" ${arg}"
scripts+=( "${scriptfile}" )
;;
--file=*) scripts+=( "${arg/--file=}" ) ;;
-*) args+=" ${arg}" ;;
*) scripts+=( "${arg}" ) ;;
esac
fi
shift
done
for file in ${files}; do
for idx in ${!scripts[@]}; do
${SED} ${args} -e "${scripts[@]:${idx}:1}" ${file} > ${file}.jer-qa-sed
if cmp -s ${file}{,.jer-qa-sed}; then
echo -e "\033[01;33m!!! JeR-QA: sed expression "${scripts[@]:${idx}:1}" did not change ${file}\033[00;00m" \
| tee -a ${T}/sed.log > /dev/stderr
else
mv ${file}{.jer-qa-sed,}
fi
done
done
;;
*) ${SED} "${@}"
;;
esac
}
prev parent reply other threads:[~2013-06-10 3:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-20 15:39 [gentoo-dev] RFC: sed script redundancy Jeroen Roovers
2011-05-20 15:56 ` Fabian Groffen
2011-05-21 17:34 ` Jeroen Roovers
2011-05-22 10:50 ` Fabian Groffen
2011-05-29 10:44 ` Christopher Schwan
2011-05-29 11:00 ` Fabian Groffen
2011-05-29 11:49 ` Christopher Schwan
2011-10-28 1:08 ` [gentoo-dev] " Ryan Hill
2013-06-10 3:47 ` Jeroen Roovers [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130610054749.64add1da@marga.jer-c2.orkz.net \
--to=jer@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox