From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-846073-garchives=archives.gentoo.org@lists.gentoo.org> Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 382791384B4 for <garchives@archives.gentoo.org>; Fri, 13 Nov 2015 01:43:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 68B7921C079; Fri, 13 Nov 2015 01:43:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0141F21C079 for <gentoo-commits@lists.gentoo.org>; Fri, 13 Nov 2015 01:42:59 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5D780340634 for <gentoo-commits@lists.gentoo.org>; Fri, 13 Nov 2015 01:42:58 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 204B5A44 for <gentoo-commits@lists.gentoo.org>; Fri, 13 Nov 2015 01:42:50 +0000 (UTC) From: "Mike Frysinger" <vapier@gentoo.org> To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" <vapier@gentoo.org> Message-ID: <1447378948.15cfd145f4d28e34f1901d7630bd6d8cff9d323f.vapier@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/eapi.sh bin/ebuild.sh bin/save-ebuild-env.sh X-VCS-Directories: bin/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 15cfd145f4d28e34f1901d7630bd6d8cff9d323f X-VCS-Branch: master Date: Fri, 13 Nov 2015 01:42:50 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: c3e2a311-8c08-4597-b990-b8b9acda4888 X-Archives-Hash: bcd2f7d36458d07a528d7196d747d84d commit: 15cfd145f4d28e34f1901d7630bd6d8cff9d323f Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> AuthorDate: Wed Nov 11 04:34:22 2015 +0000 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> CommitDate: Fri Nov 13 01:42:28 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=15cfd145 ebuild: set up bash compat levels To try and provide better stability across bash versions, set the language compat level based on the current EAPI. This does not ban newer features, it tells bash to use the older bash behavior when the behavior changes across versions. bin/eapi.sh | 8 ++++++++ bin/ebuild.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ bin/save-ebuild-env.sh | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/bin/eapi.sh b/bin/eapi.sh index 528e6f2..cd3e1a4 100644 --- a/bin/eapi.sh +++ b/bin/eapi.sh @@ -191,3 +191,11 @@ ___eapi_enables_failglob_in_global_scope() { ___eapi_enables_globstar() { [[ ${1-${EAPI-0}} =~ ^(4-python|5-progress)$ ]] } + +___eapi_bash_3_2() { + [[ ${1-${EAPI-0}} =~ ^(0|1|2|3|4|4-python|4-slot-abi|5|5-hdepend|5-progress)$ ]] +} + +___eapi_bash_4_2() { + [[ ${1-${EAPI-0}} =~ ^(6)$ ]] +} diff --git a/bin/ebuild.sh b/bin/ebuild.sh index cc6a22f..4319a17 100755 --- a/bin/ebuild.sh +++ b/bin/ebuild.sh @@ -6,8 +6,50 @@ # Make sure it's before everything so we don't mess aliases that follow. unalias -a +# Make sure this isn't exported to scripts we execute. +unset BASH_COMPAT + source "${PORTAGE_BIN_PATH}/isolated-functions.sh" || exit 1 +# Set up the bash version compatibility level. This does not disable +# features when running with a newer version, but makes it so that when +# bash changes behavior in an incompatible way, the older behavior is +# used instead. +__check_bash_version() { + # Figure out which min version of bash we require. + local maj min + if ___eapi_bash_3_2 ; then + maj=3 min=2 + elif ___eapi_bash_4_2 ; then + maj=4 min=2 + else + return + fi + + # Make sure the active bash is sane. + if [[ ${BASH_VERSINFO[0]} -lt ${maj} ]] || + [[ ${BASH_VERSINFO[0]} -eq ${maj} && ${BASH_VERSINFO[1]} -lt ${min} ]] ; then + die ">=bash-${maj}.${min} is required" + fi + + # Set the compat level in case things change with newer ones. We must not + # export this into the env otherwise we might break other shell scripts we + # execute (e.g. ones in /usr/bin). + BASH_COMPAT="${maj}.${min}" + + # The variable above is new to bash-4.3. For older versions, we have to use + # a compat knob. Further, the compat knob only exists with older versions + # (e.g. bash-4.3 has compat42 but not compat43). This means we only need to + # turn the knob with older EAPIs, and only when running newer bash versions: + # there is no bash-3.3 (it went 3.2 to 4.0), and when requiring bash-4.2, the + # var works with bash-4.3+, and you don't need to set compat to 4.2 when you + # are already running 4.2. + if ___eapi_bash_3_2 && [[ ${BASH_VERSINFO[0]} -gt 3 ]] ; then + shopt -s compat32 + fi +} +__check_bash_version + if [[ $EBUILD_PHASE != depend ]] ; then source "${PORTAGE_BIN_PATH}/phase-functions.sh" || die source "${PORTAGE_BIN_PATH}/save-ebuild-env.sh" || die diff --git a/bin/save-ebuild-env.sh b/bin/save-ebuild-env.sh index 17e4cdc..8036342 100644 --- a/bin/save-ebuild-env.sh +++ b/bin/save-ebuild-env.sh @@ -75,7 +75,7 @@ __save_ebuild_env() { __ebuild_main __ebuild_phase __ebuild_phase_with_hooks \ __ebuild_arg_to_phase __ebuild_phase_funcs default \ __unpack_tar __unset_colors \ - __source_env_files __try_source \ + __source_env_files __try_source __check_bash_version \ __eqaquote __eqatag \ ${QA_INTERCEPTORS}