1 |
On Wed, Feb 27, 2013 at 1:43 PM, Michał Górny <mgorny@g.o> wrote: |
2 |
> This allows us to spawn 'tee' as separate process while keeping |
3 |
> the function code executed in the main shell. |
4 |
|
5 |
Can you explain why this is 'better'? I'd prefer way more |
6 |
documentation in the code itself. You are using a number of what I'd |
7 |
consider 'banned' constructs and you don't go very far out of your way |
8 |
to explain why you cannot live without them. |
9 |
|
10 |
> --- |
11 |
> gx86/eclass/multibuild.eclass | 19 ++++++++++--------- |
12 |
> 1 file changed, 10 insertions(+), 9 deletions(-) |
13 |
> |
14 |
> diff --git a/gx86/eclass/multibuild.eclass b/gx86/eclass/multibuild.eclass |
15 |
> index 716d34f..d42b8a7 100644 |
16 |
> --- a/gx86/eclass/multibuild.eclass |
17 |
> +++ b/gx86/eclass/multibuild.eclass |
18 |
> @@ -108,18 +108,20 @@ multibuild_foreach() { |
19 |
> local MULTIBUILD_VARIANT=${v} |
20 |
> local MULTIBUILD_ID=${prev_id}${v} |
21 |
> local BUILD_DIR=${bdir%%/}-${v} |
22 |
> + local log_fd |
23 |
> |
24 |
> - einfo "${v}: running ${@}" \ |
25 |
> - | tee -a "${T}/build-${MULTIBUILD_ID}.log" |
26 |
> + # redirect_alloc_fd accepts files only. so we need to open |
27 |
> + # a random file and then reuse the fd for logger process. |
28 |
> + redirect_alloc_fd log_fd /dev/null |
29 |
> + eval "exec ${log_fd}> "'>(exec tee -a "${T}/build-${MULTIBUILD_ID}.log")' |
30 |
The quoting here is a nightmare. |
31 |
Are the single quotes required? |
32 |
Do the leading single quotes have to be *right next to* the double quotes? |
33 |
Why is there a space between the first > and the "? |
34 |
vim hi-lighting makes this more readable, but still weird looking. |
35 |
Also please document clearly why 'eval' is required (it is not clear |
36 |
to me..or I suspect most readers ;p) |
37 |
Are we not just making an fd and pointing the 'read end' at a tee subprocess? |
38 |
|
39 |
> + |
40 |
> + eval 'einfo "${v}: running ${@}" >&'${log_fd}' 2>&1' |
41 |
And again here, why can't we just redirect directly to log_fd? |
42 |
|
43 |
> |
44 |
> # _multibuild_parallel() does redirection internally. |
45 |
> # this is a hidden API to avoid writing multilib_foreach twice. |
46 |
We do not use the _multibuild_parellel stuff anymore...is this comment relevant? |
47 |
|
48 |
> - if [[ ${1} == _multibuild_parallel ]]; then |
49 |
> - "${@}" |
50 |
> - else |
51 |
> - "${@}" 2>&1 | tee -a "${T}/build-${MULTIBUILD_ID}.log" |
52 |
> - fi |
53 |
> + eval '"${@}" >&'${log_fd}' 2>&1' |
54 |
> lret=${?} |
55 |
> + eval "exec ${log_fd}>&-" |
56 |
> done |
57 |
> [[ ${ret} -eq 0 && ${lret} -ne 0 ]] && ret=${lret} |
58 |
> |
59 |
> @@ -145,8 +147,7 @@ multibuild_parallel_foreach() { |
60 |
> _multibuild_parallel() { |
61 |
> ( |
62 |
> multijob_child_init |
63 |
> - "${@}" 2>&1 | tee -a "${T}/build-${MULTIBUILD_ID}.log" |
64 |
> - exit ${PIPESTATUS[0]} |
65 |
> + "${@}" |
66 |
> ) & |
67 |
> multijob_post_fork |
68 |
> } |
69 |
> -- |
70 |
> 1.8.1.4 |
71 |
> |
72 |
> |