Gentoo Archives: gentoo-dev

From: Steve Long <slong@××××××××××××××××××.uk>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: Re: Default src_install for EAPI-2 or following EAPI
Date: Sun, 21 Sep 2008 12:11:26
Message-Id: gb5dkp$h30$1@ger.gmane.org
In Reply to: Re: [gentoo-dev] Re: Default src_install for EAPI-2 or following EAPI by Vaeth
1 Vaeth wrote:
2
3 > Steve Long wrote:
4 >
5 >> Thomas Sachau wrote: [...]
6 >>
7 >> > [[ -n ${DOCS} ]] && dodoc ${DOCS}
8 > [...]
9 >>
10 >> It might be wise to use an array for DOCS there
11 >
12 > Since I have now seen suggestions for using arrays unnecessarily
13 > at least twice (see also
14 > [RFC] Ability to pass arguments to src_configure/src_compile
15 > but I am only speaking about the usage of _arrays_ here),
16 > let me remark that the more clever way to this is
17 >
18 > [ -n "${DOCS}" ] && eval "dodoc ${DOCS}"
19 >
20 eval is _not_ clever. Try: /msg greybot eval
21 ..or check http://wooledge.org:8000/BashFAQ/048
22
23 > This way, people can simply quote as they like:
24 >
25 > DOCS="'filename with spaces' filename_without_space doc/*"
26 >
27 Yeuch.
28
29 > or also
30 >
31 > DOCS="just_one_filename_without_special_characters"
32 >
33 You don't need quotes there.
34
35 > or also - when Push from /usr/bin/functions-eix.sh is used
36 > (which might be implemented simpler without using other functions):
37 >
38 > Push DOCS 'filename with spaces' filename_without_space "${S}"/doc/*
39 >
40 Or just do DOCS+=(foo/* someFile 'some other File') at any point.
41
42 BASH arrays will cope with *any* character apart from NUL, which isn't
43 allowed in filenames. Can you _guarantee_ the same?
44
45 For instance, what if some crazy designer puts a file called:
46 Vaeth's "Latest" Hits
47 ..in that doc dir; what happens after the Push function has been called and,
48 only at a later stage, the eval is run on the result of that glob
49 expansion?
50
51 > Not only has this the advantage that it is POSIX (and thus does not
52 > force ebuilds to use the particular shell "bash" - a policy which perhaps
53 > some day might be changed: It is dangerous to depend on a particular
54 > implementation),
55
56 I'm not getting back into that discussion, since we had the same one over a
57 period of months already. Ebuilds require BASH; get over it. If we could
58 move ahead with actually using BASH properly (and cleanly) it would be
59 nice. BASH is as portable as GNU make is, and you clearly have no issue
60 depending on that, and Python or C++.
61
62 BTW, POSIX sh doesn't need ${DOCS} or ${S} either, you're just wasting
63 characters.
64
65 > the array-less solution is also much simpler to
66 > implement, easy to understand from the source, and clearer in usage.
67
68 Not to me it's not, it looks awful, to read and to type, as well as being
69 fragile.
70
71 Furthermore you're bringing eval into the script new people are going to
72 look at to learn from (it's core functionality, fulfilling a basic task)
73 which is dangerous from a long-term pov, imo. Leave aside having to
74 maintain that cruft.
75
76 > Case distinctions like
77 >
78 >> if isArr DOCS; then
79 >> ((${#DOCS[@]})) && dodoc "${DOCS[@]}"
80 >> else [[ $DOCS ]] && dodoc $DOCS
81 >> fi
82 >
83 > are just awful.
84
85 Actually if you factor out that isArr is a utility function (exactly like
86 Push) that code is very easy to follow, as well as coping with all
87 filenames, and itself would be part of a lib function. The only reason to
88 have the check is for backward-compatibility, or to allow people to use
89 whichever they feel most comfortable with.
90
91 One might not know how to count/use arrays in BASH, fair enough; that's how.
92 Given that basic knowledge[1] of the tool used to write ebuilds since the
93 very beginning, I cannot see how that is hard to follow.
94
95 I'm willing to bet your sh scripts aren't really as portable as you think.
96 If you want to see how portable sh is done, read:
97 http://sources.redhat.com/autobook/autobook/autobook_210.html#SEC210
98 (all of it) and then try to persuade us that we should be writing ebuilds
99 like that.
100
101 If you want to do that kind of thing, much better imo to do another type of
102 ebuild, eg a pbuild using Python, and only call sh when absolutely
103 necessary, if at all.
104
105 BTW, thanks for eix; it's a lovely utility.
106
107 [1] http://wooledge.org/mywiki/BashFAQ/005

Replies