1 |
On Sun, Oct 21, 2012 at 5:16 AM, Michał Górny <mgorny@g.o> wrote: |
2 |
> Hello, |
3 |
> |
4 |
> Right now, there are two variables which are set per-implementation -- |
5 |
> PYTHON & EPYTHON. However, one of our users (sorry for not remembering |
6 |
> who) requested an ability to get Python libdir, site-packages directory |
7 |
> as well. This raises a question on the interface which should be used |
8 |
> to get those values. |
9 |
> |
10 |
> The common interface in Gentoo is to use 'getter' functions. Since bash |
11 |
> doesn't have any real concept of return values, those functions use |
12 |
> output capturing -- and that involves subshelling which is pretty bad |
13 |
> for commonly used functions. An alternative is to use an 'export' |
14 |
> function like tc-export() in toolchain-funcs. |
15 |
> |
16 |
> I'd like to shortly point out advantages and disadvantages of each |
17 |
> solution. |
18 |
> |
19 |
> |
20 |
> 1) getter functions |
21 |
> - python_get_PYTHON [<impl>] |
22 |
> - python_get_EPYTHON <impl> |
23 |
> - python_get_sitedir [<impl>] |
24 |
> |
25 |
> + clear separation between variables |
26 |
> -> especially useful to keep docs clear and short |
27 |
> |
28 |
> - one subshell (and function call) for each variable, for each |
29 |
> implementation |
30 |
> -> that makes it 2 * n-impls for each phase function in distutils-r1 |
31 |
> |
32 |
> |
33 |
> 2) a single export function |
34 |
> - python_export [<impl>] <var>... |
35 |
> e.g. python_export python2_7 PYTHON EPYTHON PYTHON_SITEDIR |
36 |
> |
37 |
> + no subshelling |
38 |
> |
39 |
> + multiple variables can be set in a single function call |
40 |
> |
41 |
> - potential for variable conflicts |
42 |
> -> e.g. when PYTHON_SITEDIR is used differently by the build system, |
43 |
> the ebuild would need to 'move' it (unlikely but possible) |
44 |
> |
45 |
> - mixing of implementation and variables in parameters (optional first |
46 |
> parameter) |
47 |
> -> technically it's acceptable but looks a bit bad. |
48 |
> |
49 |
> |
50 |
> What are your thoughts? |
51 |
> |
52 |
|
53 |
I think creating sub-shells in sections which are not processed in |
54 |
global scope is really not a big deal. |
55 |
|
56 |
I think the getter functions are more intuitive. However, I also like |
57 |
the idea of setting variables at the same time, similar to the way |
58 |
this is handled in _tc-getPROG. The result is stored in a variable and |
59 |
also echoed, leaving it up to the end user to decide how he wants to |
60 |
process it. |
61 |
|
62 |
So, I vote for getters that emulate the toolchain-funcs behavior. |