1 |
To try and provide better stability across bash versions, |
2 |
set the language compat level based on the current EAPI. |
3 |
This does not ban newer features, it tells bash to use |
4 |
the older bash behavior when the behavior changes across |
5 |
versions. |
6 |
--- |
7 |
bin/eapi.sh | 8 ++++++++ |
8 |
bin/ebuild.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ |
9 |
bin/save-ebuild-env.sh | 2 +- |
10 |
3 files changed, 51 insertions(+), 1 deletion(-) |
11 |
|
12 |
diff --git a/bin/eapi.sh b/bin/eapi.sh |
13 |
index 528e6f2..cd3e1a4 100644 |
14 |
--- a/bin/eapi.sh |
15 |
+++ b/bin/eapi.sh |
16 |
@@ -191,3 +191,11 @@ ___eapi_enables_failglob_in_global_scope() { |
17 |
___eapi_enables_globstar() { |
18 |
[[ ${1-${EAPI-0}} =~ ^(4-python|5-progress)$ ]] |
19 |
} |
20 |
+ |
21 |
+___eapi_bash_3_2() { |
22 |
+ [[ ${1-${EAPI-0}} =~ ^(0|1|2|3|4|4-python|4-slot-abi|5|5-hdepend|5-progress)$ ]] |
23 |
+} |
24 |
+ |
25 |
+___eapi_bash_4_2() { |
26 |
+ [[ ${1-${EAPI-0}} =~ ^(6)$ ]] |
27 |
+} |
28 |
diff --git a/bin/ebuild.sh b/bin/ebuild.sh |
29 |
index 75a9d24..78a93f0 100755 |
30 |
--- a/bin/ebuild.sh |
31 |
+++ b/bin/ebuild.sh |
32 |
@@ -6,8 +6,50 @@ |
33 |
# Make sure it's before everything so we don't mess aliases that follow. |
34 |
unalias -a |
35 |
|
36 |
+# Make sure this isn't exported to scripts we execute. |
37 |
+unset BASH_COMPAT |
38 |
+ |
39 |
source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit 1 |
40 |
|
41 |
+# Set up the bash version compatibility level. This does not disable |
42 |
+# features when running with a newer version, but makes it so that when |
43 |
+# bash changes behavior in an incompatible way, the older behavior is |
44 |
+# used instead. |
45 |
+__check_bash_version() { |
46 |
+ # Figure out which min version of bash we require. |
47 |
+ local maj min |
48 |
+ if ___eapi_bash_3_2 ; then |
49 |
+ maj=3 min=2 |
50 |
+ elif ___eapi_bash_4_2 ; then |
51 |
+ maj=4 min=2 |
52 |
+ else |
53 |
+ return |
54 |
+ fi |
55 |
+ |
56 |
+ # Make sure the active bash is sane. |
57 |
+ if [[ ${BASH_VERSINFO[0]} -lt ${maj} ]] || |
58 |
+ [[ ${BASH_VERSINFO[0]} -eq ${maj} && ${BASH_VERSINFO[1]} -lt ${min} ]] ; then |
59 |
+ die ">=bash-${maj}.${min} is required" |
60 |
+ fi |
61 |
+ |
62 |
+ # Set the compat level in case things change with newer ones. We must not |
63 |
+ # export this into the env otherwise we might break other shell scripts we |
64 |
+ # execute (e.g. ones in /usr/bin). |
65 |
+ BASH_COMPAT="${maj}.${min}" |
66 |
+ |
67 |
+ # The variable above is new to bash-4.3. For older versions, we have to use |
68 |
+ # a compat knob. Further, the compat knob only exists with older versions |
69 |
+ # (e.g. bash-4.3 has compat42 but not compat43). This means we only need to |
70 |
+ # turn the knob with older EAPIs, and only when running newer bash versions: |
71 |
+ # there is no bash-3.3 (it went 3.2 to 4.0), and when requiring bash-4.2, the |
72 |
+ # var works with bash-4.3+, and you don't need to set compat to 4.2 when you |
73 |
+ # are already running 4.2. |
74 |
+ if ___eapi_bash_3_2 && [[ ${BASH_VERSINFO[0]} -gt 3 ]] ; then |
75 |
+ shopt -s compat32 |
76 |
+ fi |
77 |
+} |
78 |
+__check_bash_version |
79 |
+ |
80 |
if [[ $EBUILD_PHASE != depend ]] ; then |
81 |
source "${PORTAGE_BIN_PATH}/phase-functions.sh" || die |
82 |
source "${PORTAGE_BIN_PATH}/save-ebuild-env.sh" || die |
83 |
diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh |
84 |
index 477ed28..1120297 100644 |
85 |
--- a/bin/save-ebuild-env.sh |
86 |
+++ b/bin/save-ebuild-env.sh |
87 |
@@ -75,7 +75,7 @@ __save_ebuild_env() { |
88 |
__ebuild_main __ebuild_phase __ebuild_phase_with_hooks \ |
89 |
__ebuild_arg_to_phase __ebuild_phase_funcs default \ |
90 |
__unpack_tar __unset_colors \ |
91 |
- __source_env_files __try_source \ |
92 |
+ __source_env_files __try_source __check_bash_version \ |
93 |
__eqaquote __eqatag \ |
94 |
${QA_INTERCEPTORS} |
95 |
|
96 |
-- |
97 |
2.6.2 |