1 |
On Thu, 28 Feb 2013 05:09:15 -0800 |
2 |
Alec Warner <antarus@g.o> wrote: |
3 |
|
4 |
> On Wed, Feb 27, 2013 at 1:43 PM, Michał Górny <mgorny@g.o> wrote: |
5 |
> > This allows us to spawn 'tee' as separate process while keeping |
6 |
> > the function code executed in the main shell. |
7 |
> |
8 |
> Can you explain why this is 'better'? I'd prefer way more |
9 |
> documentation in the code itself. You are using a number of what I'd |
10 |
> consider 'banned' constructs and you don't go very far out of your way |
11 |
> to explain why you cannot live without them. |
12 |
|
13 |
Well, if we used simple pipes, like: |
14 |
|
15 |
foo | tee ... |
16 |
|
17 |
Then any variable exported by foo would be discarded. This broke a few |
18 |
ebuilds already. |
19 |
|
20 |
By banned constructs, do you mean 'eval'? I hate it too but wasn't able |
21 |
to solve it anyhow better. |
22 |
|
23 |
> > gx86/eclass/multibuild.eclass | 19 ++++++++++--------- |
24 |
> > 1 file changed, 10 insertions(+), 9 deletions(-) |
25 |
> > |
26 |
> > diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass |
27 |
> > index 716d34f..d42b8a7 100644 |
28 |
> > --- a/gx86/eclass/multibuild.eclass |
29 |
> > +++ b/gx86/eclass/multibuild.eclass |
30 |
> > @@ -108,18 +108,20 @@ multibuild_foreach() { |
31 |
> > local MULTIBUILD_VARIANT=${v} |
32 |
> > local MULTIBUILD_ID=${prev_id}${v} |
33 |
> > local BUILD_DIR=${bdir%%/}-${v} |
34 |
> > + local log_fd |
35 |
> > |
36 |
> > - einfo "${v}: running ${@}" \ |
37 |
> > - | tee -a "${T}/build-${MULTIBUILD_ID}.log" |
38 |
> > + # redirect_alloc_fd accepts files only. so we need to open |
39 |
> > + # a random file and then reuse the fd for logger process. |
40 |
> > + redirect_alloc_fd log_fd /dev/null |
41 |
> > + eval "exec ${log_fd}> "'>(exec tee -a "${T}/build-${MULTIBUILD_ID}.log")' |
42 |
> The quoting here is a nightmare. |
43 |
> Do the leading single quotes have to be *right next to* the double quotes? |
44 |
> Why is there a space between the first > and the "? |
45 |
> vim hi-lighting makes this more readable, but still weird looking. |
46 |
|
47 |
Yes, I know. I'm thinking of trying to put it all into a single eval, |
48 |
and just use \$ rather than mixing single and double quotes. |
49 |
|
50 |
> Also please document clearly why 'eval' is required (it is not clear |
51 |
> to me..or I suspect most readers ;p) |
52 |
|
53 |
Well, for the very simple reason that 'fd=2; echo 11 >&${fd}' doesn't |
54 |
work. The eval simply changes that into 'echo 11>&2'. |
55 |
|
56 |
> Are we not just making an fd and pointing the 'read end' at a tee subprocess? |
57 |
|
58 |
Yes, exactly that. |
59 |
|
60 |
> > + |
61 |
> > + eval 'einfo "${v}: running ${@}" >&'${log_fd}' 2>&1' |
62 |
> And again here, why can't we just redirect directly to log_fd? |
63 |
> |
64 |
> > |
65 |
> > # _multibuild_parallel() does redirection internally. |
66 |
> > # this is a hidden API to avoid writing multilib_foreach twice. |
67 |
> We do not use the _multibuild_parellel stuff anymore...is this comment relevant? |
68 |
|
69 |
You are correct, my mistake. |
70 |
|
71 |
-- |
72 |
Best regards, |
73 |
Michał Górny |