Gentoo Archives: gentoo-portage-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] ebuild: set up bash compat levels
Date: Wed, 11 Nov 2015 04:39:35
Message-Id: 1447216769-7116-1-git-send-email-vapier@gentoo.org
1 To try and provide better stability across bash versions,
2 set the language compat level based on the current EAPI.
3 ---
4 bin/eapi.sh | 8 ++++++++
5 bin/ebuild.sh | 39 +++++++++++++++++++++++++++++++++++++++
6 2 files changed, 47 insertions(+)
7
8 diff --git a/bin/eapi.sh b/bin/eapi.sh
9 index 528e6f2..b236344 100644
10 --- a/bin/eapi.sh
11 +++ b/bin/eapi.sh
12 @@ -191,3 +191,11 @@ ___eapi_enables_failglob_in_global_scope() {
13 ___eapi_enables_globstar() {
14 [[ ${1-${EAPI-0}} =~ ^(4-python|5-progress)$ ]]
15 }
16 +
17 +__eapi_bash_3_2() {
18 + [[ ${1-${EAPI-0}} =~ ^(0|1|2|3|4|4-python|4-slot-abi|5|5-hdepend|5-progress)$ ]]
19 +}
20 +
21 +__eapi_bash_4_2() {
22 + [[ ${1-${EAPI-0}} =~ ^(6)$ ]]
23 +}
24 diff --git a/bin/ebuild.sh b/bin/ebuild.sh
25 index 75a9d24..2d09fb8 100755
26 --- a/bin/ebuild.sh
27 +++ b/bin/ebuild.sh
28 @@ -6,8 +6,47 @@
29 # Make sure it's before everything so we don't mess aliases that follow.
30 unalias -a
31
32 +# Make sure this isn't exported to scripts we execute.
33 +unset BASH_COMPAT
34 +
35 source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit 1
36
37 +# Set up the bash version compatibility level.
38 +__check_bash_version() {
39 + # Figure out which min version of bash we require.
40 + local maj min
41 + if __eapi_bash_3_2 ; then
42 + maj=3 min=2
43 + elif __eapi_bash_4_2 ; then
44 + maj=4 min=2
45 + else
46 + return
47 + fi
48 +
49 + # Make sure the active bash is sane.
50 + if [[ ${BASH_VERSINFO[0]} -lt ${maj} ]] ||
51 + [[ ${BASH_VERSINFO[0]} -eq ${maj} && ${BASH_VERSINFO[1]} -lt ${min} ]] ; then
52 + die ">=bash-${maj}.${min} is required"
53 + fi
54 +
55 + # Set the compat level in case things change with newer ones. We must not
56 + # export this into the env otherwise we might break other shell scripts we
57 + # execute (e.g. ones in /usr/bin).
58 + BASH_COMPAT="${maj}.${min}"
59 +
60 + # The variable above is new to bash-4.3. For older versions, we have to use
61 + # a compat knob. Further, the compat knob only exists with older versions
62 + # (e.g. bash-4.3 has compat42 but not compat43). This means we only need to
63 + # turn the knob with older EAPIs, and only when running newer bash versions:
64 + # there is no bash-3.3 (it went 3.2 to 4.0), and when requiring bash-4.2, the
65 + # var works with bash-4.3+, and you don't need to set compat to 4.2 when you
66 + # are already running 4.2.
67 + if __eapi_bash_3_2 && [[ ${BASH_VERSINFO[0]} -gt 3 ]] ; then
68 + shopt -s compat32
69 + fi
70 +}
71 +__check_bash_version
72 +
73 if [[ $EBUILD_PHASE != depend ]] ; then
74 source "${PORTAGE_BIN_PATH}/phase-functions.sh" || die
75 source "${PORTAGE_BIN_PATH}/save-ebuild-env.sh" || die
76 --
77 2.6.2

Replies