1 |
On Tue, 10 Nov 2015 23:39:29 -0500 |
2 |
Mike Frysinger <vapier@g.o> wrote: |
3 |
|
4 |
> To try and provide better stability across bash versions, |
5 |
> set the language compat level based on the current EAPI. |
6 |
> --- |
7 |
> bin/eapi.sh | 8 ++++++++ |
8 |
> bin/ebuild.sh | 39 +++++++++++++++++++++++++++++++++++++++ |
9 |
> 2 files changed, 47 insertions(+) |
10 |
> |
11 |
> diff --git a/bin/eapi.sh b/bin/eapi.sh |
12 |
> index 528e6f2..b236344 100644 |
13 |
> --- a/bin/eapi.sh |
14 |
> +++ b/bin/eapi.sh |
15 |
> @@ -191,3 +191,11 @@ ___eapi_enables_failglob_in_global_scope() { |
16 |
> ___eapi_enables_globstar() { |
17 |
> [[ ${1-${EAPI-0}} =~ ^(4-python|5-progress)$ ]] |
18 |
> } |
19 |
> + |
20 |
> +__eapi_bash_3_2() { |
21 |
> + [[ ${1-${EAPI-0}} =~ ^(0|1|2|3|4|4-python|4-slot-abi|5|5-hdepend|5-progress)$ ]] |
22 |
> +} |
23 |
> + |
24 |
> +__eapi_bash_4_2() { |
25 |
> + [[ ${1-${EAPI-0}} =~ ^(6)$ ]] |
26 |
> +} |
27 |
> diff --git a/bin/ebuild.sh b/bin/ebuild.sh |
28 |
> index 75a9d24..2d09fb8 100755 |
29 |
> --- a/bin/ebuild.sh |
30 |
> +++ b/bin/ebuild.sh |
31 |
> @@ -6,8 +6,47 @@ |
32 |
> # Make sure it's before everything so we don't mess aliases that follow. |
33 |
> unalias -a |
34 |
> |
35 |
> +# Make sure this isn't exported to scripts we execute. |
36 |
> +unset BASH_COMPAT |
37 |
> + |
38 |
> source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit 1 |
39 |
> |
40 |
> +# Set up the bash version compatibility level. |
41 |
> +__check_bash_version() { |
42 |
> + # Figure out which min version of bash we require. |
43 |
> + local maj min |
44 |
> + if __eapi_bash_3_2 ; then |
45 |
> + maj=3 min=2 |
46 |
> + elif __eapi_bash_4_2 ; then |
47 |
> + maj=4 min=2 |
48 |
> + else |
49 |
> + return |
50 |
> + fi |
51 |
> + |
52 |
> + # Make sure the active bash is sane. |
53 |
> + if [[ ${BASH_VERSINFO[0]} -lt ${maj} ]] || |
54 |
> + [[ ${BASH_VERSINFO[0]} -eq ${maj} && ${BASH_VERSINFO[1]} -lt ${min} ]] ; then |
55 |
> + die ">=bash-${maj}.${min} is required" |
56 |
> + fi |
57 |
> + |
58 |
> + # Set the compat level in case things change with newer ones. We must not |
59 |
> + # export this into the env otherwise we might break other shell scripts we |
60 |
> + # execute (e.g. ones in /usr/bin). |
61 |
> + BASH_COMPAT="${maj}.${min}" |
62 |
> + |
63 |
> + # The variable above is new to bash-4.3. For older versions, we have to use |
64 |
> + # a compat knob. Further, the compat knob only exists with older versions |
65 |
> + # (e.g. bash-4.3 has compat42 but not compat43). This means we only need to |
66 |
> + # turn the knob with older EAPIs, and only when running newer bash versions: |
67 |
> + # there is no bash-3.3 (it went 3.2 to 4.0), and when requiring bash-4.2, the |
68 |
> + # var works with bash-4.3+, and you don't need to set compat to 4.2 when you |
69 |
> + # are already running 4.2. |
70 |
> + if __eapi_bash_3_2 && [[ ${BASH_VERSINFO[0]} -gt 3 ]] ; then |
71 |
> + shopt -s compat32 |
72 |
> + fi |
73 |
> +} |
74 |
> +__check_bash_version |
75 |
> + |
76 |
> if [[ $EBUILD_PHASE != depend ]] ; then |
77 |
> source "${PORTAGE_BIN_PATH}/phase-functions.sh" || die |
78 |
> source "${PORTAGE_BIN_PATH}/save-ebuild-env.sh" || die |
79 |
|
80 |
I'm not convinced we ought to do this for EAPI < 6. It is a breaking |
81 |
change after all, and as such changes the behavior of EAPI < 6 ebuilds. |
82 |
|
83 |
There are some ebuilds/eclasses that have bash version checks, |
84 |
and execute bash-4 code when bash-4 is available. As far as I |
85 |
understand, this will effectively prohibit bash-4 code even though |
86 |
BASH_VERSINFO will still indicate bash-4 is being used. |
87 |
|
88 |
-- |
89 |
Best regards, |
90 |
Michał Górny |
91 |
<http://dev.gentoo.org/~mgorny/> |