Gentoo Archives: gentoo-dev

From: Steve Long <slong@××××××××××××××××××.uk>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: to patch or sed was -> repoman and checking for correct quoting
Date: Sun, 11 Nov 2007 10:46:19
Message-Id: fh6mbk$t92$1@ger.gmane.org
In Reply to: Re: [gentoo-dev] to patch or sed was -> repoman and checking for correct quoting by "William L. Thomson Jr."
1 William L. Thomson Jr. wrote:
2 > On Sat, 2007-11-10 at 18:36 +0100, Bo Ørsted Andresen wrote:
3 >> On Sat, Nov 10, 2007 at 11:51:37AM +0100, Krzysiek Pawlik wrote:
4 >> > It's purpose is to remove the ${D} from makefile, additionally ${D} is
5 >> > in single quotes, so it will not be expanded - is it a bug in repoman
6 >> > check?
7 >>
8 >> What ${D} ? I see none in that makefile. Which is why I think a patch
9 >> would be better in this case. A patch would actually tell you when half
10 >> of the substitutions don't match anything... I think this is a point
11 >> worth making even if it doesn't change your point.
12 >
13 > I have kinda gone back and forth between patches and sed. While I agree
14 > patches are better since they fail to apply at times. Sed stuff can be
15 > more portable amongst revisions, as I have found with maintaining assp.
16 > Where the patch grew to the point it had to be mirrored :(.
17 >
18 > Now I know some will scream, puke, throw up in their mouth, and so on.
19 > But seems like sed should have an OPTIONAL argument or etc to tell sed
20 > to either fail if it can't make the change anywhere. And/or keep/output
21 > a count of how many things were modified.
22 >
23 ed does this by default (which can make it trickier) -- if a standard search
24 and replace doesn't match, it's considered an error. I appreciate ed isn't
25 currently part of system set, but imo it should be, since it's specified in
26 posix. A workaround is grep -q, eg:
27
28 if grep -qF '${D}' file; then
29 sed -i '#\${D}##' file
30 fi
31
32 (You need to escape $ in a regex or it'll be treated as end marker.) This is
33 more useful in cases where you need to know what is in the file for
34 whatever reason (eg grep -q '^FEATURES="[^"]*-blah' /etc/make.conf [1]),
35 since the sed will not affect the file if there is no match.
36
37 Of course, repoman still needs to ignore stuff in single quotes.
38
39 [1] if ! grep -qF sandbox < <(portageq envvar FEATURES); then .. (for
40 example) is safer for general case.
41
42
43 --
44 gentoo-dev@g.o mailing list