Gentoo Archives: gentoo-portage-dev

From: Bertrand SIMONNET <bsimonnet@××××××××.org>
To: gentoo-portage-dev@l.g.o
Cc: Bertrand SIMONNET <bsimonnet@××××××××.org>
Subject: [gentoo-portage-dev] [PATCH 1/3] Refactor bashrc scripts sourcing
Date: Tue, 30 Sep 2014 00:12:55
Message-Id: 1412035957-32071-2-git-send-email-bsimonnet@chromium.org
In Reply to: [gentoo-portage-dev] [PATCH] per package environment: generalize the mechanism to be profile specific by Bertrand SIMONNET
1 Creates two new helper functions __try_source and __source_env_files to simplify
2 __source_all_bashrcs.
3 ---
4 bin/ebuild.sh | 75 +++++++++++++++++++++++++++++++++-----------------
5 bin/save-ebuild-env.sh | 1 +
6 2 files changed, 51 insertions(+), 25 deletions(-)
7
8 diff --git a/bin/ebuild.sh b/bin/ebuild.sh
9 index be044e0..14cc321 100755
10 --- a/bin/ebuild.sh
11 +++ b/bin/ebuild.sh
12 @@ -375,39 +375,64 @@ __source_all_bashrcs() {
13 done
14 fi
15
16 - if [ -r "${PORTAGE_BASHRC}" ] ; then
17 - if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
18 - source "${PORTAGE_BASHRC}"
19 - else
20 - set -x
21 - source "${PORTAGE_BASHRC}"
22 - set +x
23 - fi
24 - fi
25 + # The user's bashrc is the ONLY non-portage bit of code
26 + # that can change shopts without a QA violation.
27 + __try_source --no-qa "${PORTAGE_BASHRC}"
28
29 if [[ $EBUILD_PHASE != depend ]] ; then
30 - # The user's bashrc is the ONLY non-portage bit of code that can
31 - # change shopts without a QA violation.
32 - for x in "${PM_EBUILD_HOOK_DIR}"/${CATEGORY}/{${PN},${PN}:${SLOT%/*},${P},${PF}}; do
33 - if [ -r "${x}" ]; then
34 - # If $- contains x, then tracing has already been enabled
35 - # elsewhere for some reason. We preserve it's state so as
36 - # not to interfere.
37 - if [ "$PORTAGE_DEBUG" != "1" ] || [ "${-/x/}" != "$-" ]; then
38 - source "${x}"
39 - else
40 - set -x
41 - source "${x}"
42 - set +x
43 - fi
44 - fi
45 - done
46 + __source_env_files --no-qa "${PM_EBUILD_HOOK_DIR}"
47 fi
48
49 [ ! -z "${OCC}" ] && export CC="${OCC}"
50 [ ! -z "${OCXX}" ] && export CXX="${OCXX}"
51 }
52
53 +# @FUNCTION: __source_env_files
54 +# @USAGE: [--no-qa] <ENV_DIRECTORY>
55 +# @DESCRIPTION:
56 +# Source the files relevant to the current package from the given path.
57 +# If --no-qa is specified, use source instead of __qa_source to source the
58 +# files.
59 +__source_env_files() {
60 + local argument=()
61 + if [[ $1 == --no-qa ]]; then
62 + argument=( --no-qa )
63 + shift
64 + fi
65 + for x in "${1}"/${CATEGORY}/{${PN},${PN}:${SLOT%/*},${P},${PF}}; do
66 + __try_source "${argument[@]}" "${x}"
67 + done
68 +}
69 +
70 +# @FUNCTION: __try_source
71 +# @USAGE: [--no-qa] <FILE>
72 +# @DESCRIPTION:
73 +# If the path given as argument exists, source the file while preserving
74 +# $-.
75 +# If --no-qa is specified, source the file with source instead of __qa_source.
76 +__try_source() {
77 + local qa=true
78 + if [[ $1 == --no-qa ]]; then
79 + qa=false
80 + shift
81 + fi
82 + if [[ -r "$1" ]]; then
83 + local debug_on=false
84 + if [[ "$PORTAGE_DEBUG" == "1" ]] && [[ "${-/x/}" == "$-" ]]; then
85 + debug_on=true
86 + fi
87 + $debug_on && set -x
88 + # If $- contains x, then tracing has already been enabled
89 + # elsewhere for some reason. We preserve it's state so as
90 + # not to interfere.
91 + if [[ ${qa} ]]; then
92 + source "${1}"
93 + else
94 + __qa_source "${1}"
95 + fi
96 + $debug_on && set +x
97 + fi
98 +}
99 # === === === === === === === === === === === === === === === === === ===
100 # === === === === === functions end, main part begins === === === === ===
101 # === === === === === === === === === === === === === === === === === ===
102 diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh
103 index 98cff83..f114c48 100644
104 --- a/bin/save-ebuild-env.sh
105 +++ b/bin/save-ebuild-env.sh
106 @@ -75,6 +75,7 @@ __save_ebuild_env() {
107 __ebuild_main __ebuild_phase __ebuild_phase_with_hooks \
108 __ebuild_arg_to_phase __ebuild_phase_funcs default \
109 __unpack_tar __unset_colors \
110 + __source_env_files __try_source \
111 ${QA_INTERCEPTORS}
112
113 ___eapi_has_usex && unset -f usex
114 --
115 2.1.0.rc2.206.gedb03e5

Replies

Subject Author
[gentoo-portage-dev] [PATCH 2/3] Add profile-formats to profile_complex Bertrand SIMONNET <bsimonnet@××××××××.org>