1 |
Thanks for the patch. I have a few comments though. |
2 |
|
3 |
Dnia 2014-09-16, o godz. 14:37:04 |
4 |
Bertrand Simonnet <bsimonnet@××××××.com> napisał(a): |
5 |
|
6 |
> From 4bf1ee98bb97136e3f6f2182e205aed7ca597640 Mon Sep 17 00:00:00 2001 |
7 |
> From: Bertrand SIMONNET <bsimonnet@××××××××.org> |
8 |
> Date: Fri, 12 Sep 2014 05:07:20 -0700 |
9 |
> Subject: [PATCH] Make env/ bash scripts profile specific |
10 |
> |
11 |
> This generalize the /etc/portage/env mechanism to be stackable with profiles. |
12 |
> ebuild.sh will walk the profiles and sources scripts in env/ following the same |
13 |
> matching rules as for /etc/portage/env. |
14 |
> |
15 |
> Change-Id: I16bcd75790213d2204f83d4aa6e8b910f8829b6e |
16 |
|
17 |
^^^^^^^^^ What is this? I don't know this tag. |
18 |
|
19 |
> --- |
20 |
> bin/ebuild.sh | 86 ++++++++++++++-------- |
21 |
> bin/save-ebuild-env.sh | 3 +- |
22 |
> .../package/ebuild/_config/LocationsManager.py | 6 ++ |
23 |
> .../package/ebuild/_config/special_env_vars.py | 2 +- |
24 |
> pym/portage/package/ebuild/config.py | 2 + |
25 |
> pym/portage/package/ebuild/doebuild.py | 2 + |
26 |
> pym/portage/repository/config.py | 2 +- |
27 |
> 7 files changed, 68 insertions(+), 35 deletions(-) |
28 |
> |
29 |
> diff --git a/bin/ebuild.sh b/bin/ebuild.sh |
30 |
> index be044e0..26b9190 100755 |
31 |
> --- a/bin/ebuild.sh |
32 |
> +++ b/bin/ebuild.sh |
33 |
> @@ -67,11 +67,11 @@ unset BASH_ENV |
34 |
> # earlier portage versions do not detect a version change in this case |
35 |
> # (9999 to 9999) and therefore they try execute an incompatible version of |
36 |
> # ebuild.sh during the upgrade. |
37 |
> -export PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2} |
38 |
> +export PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2} |
39 |
|
40 |
While whitespace fixes are generally a good idea, please don't mix them |
41 |
with feature patches. It makes reviewing harder, for a start. |
42 |
|
43 |
[...] |
44 |
|
45 |
> @@ -369,45 +369,67 @@ __source_all_bashrcs() { |
46 |
> save_IFS |
47 |
> IFS=$'\n' |
48 |
> local path_array=($PROFILE_PATHS) |
49 |
> + local profile_attributes=($PORTAGE_PROFILE_ATTRIBUTES) |
50 |
> + local profile_path |
51 |
> restore_IFS |
52 |
> - for x in "${path_array[@]}" ; do |
53 |
> - [ -f "$x/profile.bashrc" ] && __qa_source "$x/profile.bashrc" |
54 |
> + for i in "${!path_array[@]}" ; do |
55 |
> + profile_path="${path_array[$i]}" |
56 |
> + [ -f "${profile_path}/profile.bashrc" ] && \ |
57 |
> + __qa_source "${profile_path}/profile.bashrc" |
58 |
> + [[ "${profile_attributes[$i]}" == *profile-env* ]] && \ |
59 |
|
60 |
I think you should use 'has' helper function here. The pattern match |
61 |
would also succeed with 'subprofile-envofoobar' and we don't want |
62 |
that :). |
63 |
|
64 |
> + __source_env_files "${profile_path}/env" |
65 |
|
66 |
Could you split the patch into smaller, logical changes? If that's too |
67 |
much of a hassle, then nevermind but I would prefer to have it like: |
68 |
|
69 |
1) refactor the code to use __source_env_files and so on without |
70 |
having anything directly related to new features yet, |
71 |
|
72 |
2) add support for querying profile attributes, |
73 |
|
74 |
3) add new profile-env support. |
75 |
|
76 |
This way, we could distinguish better between what you refactored |
77 |
and what you added. |
78 |
|
79 |
> done |
80 |
> fi |
81 |
> |
82 |
> - if [ -r "${PORTAGE_BASHRC}" ] ; then |
83 |
> - if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then |
84 |
> - source "${PORTAGE_BASHRC}" |
85 |
> - else |
86 |
> - set -x |
87 |
> - source "${PORTAGE_BASHRC}" |
88 |
> - set +x |
89 |
> - fi |
90 |
> - fi |
91 |
> + # The user's bashrc is the ONLY non-portage bit of code |
92 |
> + # that can change shopts without a QA violation. |
93 |
> + __try_source "${PORTAGE_BASHRC}" "no_qa" |
94 |
^^^^^^^ |
95 |
|
96 |
This looks like a very confusing usage for a function. It would be |
97 |
really preferable to use syntax similar to standard utilities, e.g.: |
98 |
|
99 |
__try_source --no-qa "${PORTAGE_BASHRC}" |
100 |
|
101 |
> if [[ $EBUILD_PHASE != depend ]] ; then |
102 |
> - # The user's bashrc is the ONLY non-portage bit of code that can |
103 |
> - # change shopts without a QA violation. |
104 |
> - for x in "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT%/*},${P},${PF}}; do |
105 |
> - if [ -r "${x}" ]; then |
106 |
> - # If $- contains x, then tracing has already been enabled |
107 |
> - # elsewhere for some reason. We preserve it's state so as |
108 |
> - # not to interfere. |
109 |
> - if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then |
110 |
> - source "${x}" |
111 |
> - else |
112 |
> - set -x |
113 |
> - source "${x}" |
114 |
> - set +x |
115 |
> - fi |
116 |
> - fi |
117 |
> - done |
118 |
> + __source_env_files "${PM_EBUILD_HOOK_DIR}" "no_qa" |
119 |
> fi |
120 |
> |
121 |
> [ ! -z "${OCC}" ] && export CC="${OCC}" |
122 |
> [ ! -z "${OCXX}" ] && export CXX="${OCXX}" |
123 |
> } |
124 |
> |
125 |
> +# @FUNCTION: __source_env_files |
126 |
|
127 |
Please describe the parameters as well (@USAGE). |
128 |
|
129 |
> +# @DESCRIPTION: |
130 |
> +# Source the files relevant to the current package from the given path. |
131 |
> +# If $2 is not 'no_qa', all the scripts are sourced with __qa_source. |
132 |
> +__source_env_files() { |
133 |
> + for x in "${1}"/${CATEGORY}/{${PN},${PN}:${SLOT%/*},${P},${PF}}; do |
134 |
> + __try_source "${x}" "${2}" |
135 |
> + done |
136 |
> +} |
137 |
|
138 |
Now I understand what the patch does. I don't think we want to actually |
139 |
expand use of this verbose-style env files. I'd rather go for |
140 |
package.env only since it is more in line with other package.* files. |
141 |
|
142 |
> + |
143 |
> +# @FUNCTION: __try_source |
144 |
> +# @DESCRIPTION: |
145 |
> +# If the path given as argument exists, source the file while preserving |
146 |
> +# $-. |
147 |
> +# If $2 is not 'no_qa', the file is sourced with __qa_source. |
148 |
> +__try_source() { |
149 |
> + if [[ -r "$1" ]]; then |
150 |
> + # If $- contains x, then tracing has already been enabled |
151 |
> + # elsewhere for some reason. We preserve it's state so as |
152 |
> + # not to interfere. |
153 |
> + if [[ "$PORTAGE_DEBUG" != "1" ]] || [[ "${-/x/}" != "$-" ]]; then |
154 |
> + if [[ "${2}" == "no_qa" ]]; then |
155 |
> + source "${x}" |
156 |
> + else |
157 |
> + __qa_source "${x}" |
158 |
> + fi |
159 |
> + else |
160 |
> + set -x |
161 |
> + if [[ "${2}" == "no_qa" ]]; then |
162 |
> + source "${x}" |
163 |
> + else |
164 |
> + __qa_source "${x}" |
165 |
> + fi |
166 |
> + set +x |
167 |
> + fi |
168 |
> + fi |
169 |
> +} |
170 |
|
171 |
I'm pretty sure you could get this smaller if you put the long |
172 |
conditional in a variable and use it twice just to control 'set -x' / |
173 |
'set +x'. In pseudocode: |
174 |
|
175 |
[[ ${debug_on} ]] && set -x |
176 |
if [[ ... ]]; then |
177 |
source |
178 |
else |
179 |
qa_source |
180 |
fi |
181 |
[[ ${debug_on} ]] && set +x |
182 |
|
183 |
> diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py |
184 |
> index 5e0d055..ef8054e 100644 |
185 |
> --- a/pym/portage/repository/config.py |
186 |
> +++ b/pym/portage/repository/config.py |
187 |
> @@ -40,7 +40,7 @@ if sys.hexversion >= 0x3000000: |
188 |
> _invalid_path_char_re = re.compile(r'[^a-zA-Z0-9._\-+:/]') |
189 |
> |
190 |
> _valid_profile_formats = frozenset( |
191 |
> - ['pms', 'portage-1', 'portage-2']) |
192 |
> + ['pms', 'portage-1', 'portage-2', 'profile-env']) |
193 |
|
194 |
I'm not sure if dedicated profile format is the best way to go. If I |
195 |
understand your patch correctly, this means that 'profile-env' has only |
196 |
features of PMS profile but not of 'portage-*' formats. This could mean |
197 |
that some people would have to choose between features of one or |
198 |
the other. Since both are compatible, i suggest 'portage-3' instead. |
199 |
|
200 |
-- |
201 |
Best regards, |
202 |
Michał Górny |