commit: 239c343e71315e9314670cfca5691b72881332a0
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Aug 13 09:03:06 2022 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Thu Nov 24 04:15:56 2022 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=239c343e
bin/ebuild.sh: Compare BASHOPTS rather than the output of the shopt builtin
Both the __qa_source() and __qa_call() functions capture the output of the shopt
builtin twice, for the purpose of comparing and warning in the case that
something being sourced or executed alters the global shell options without
later restoring them to their prior state.
The output of shopt is verbose in nature and it is somewhat aggravating to see
its output routinely appearing in bash execution traces. As of bash-4.1, a
BASHOPTS variable is available, which contains a colon-separated list of enabled
options, rendering it terse in nature, while still being suitable for the QA
test in question. So, let's use it and avoid incurring two subshells into the
bargain.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/ebuild.sh | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/bin/ebuild.sh b/bin/ebuild.sh
index 417bca78a..c1fbcf75a 100755
--- a/bin/ebuild.sh
+++ b/bin/ebuild.sh
@@ -104,12 +104,12 @@ export
PORTAGE_BZIP2_COMMAND=${PORTAGE_BZIP2_COMMAND:-bzip2}
# when they are done.
__qa_source() {
- local shopts=$(shopt) OLDIFS="${IFS}"
+ local bashopts="${BASHOPTS:?}" OLDIFS="${IFS}"
local retval
source "$@"
retval=$?
set +e
- [[ ${shopts} != $(shopt) ]] &&
+ [[ "${BASHOPTS}" != "${bashopts}" ]] &&
eqawarn "QA Notice: Global shell options changed and were not
restored while sourcing '$*'"
[[ "${IFS}" != "${OLDIFS}" ]] &&
eqawarn "QA Notice: Global IFS changed and was not restored
while sourcing '$*'"
@@ -117,12 +117,12 @@ __qa_source() {
}
__qa_call() {
- local shopts=$(shopt) OLDIFS="${IFS}"
+ local bashopts="${BASHOPTS:?}" OLDIFS="${IFS}"
local retval
"$@"
retval=$?
set +e
- [[ ${shopts} != $(shopt) ]] &&
+ [[ "${BASHOPTS}" != "${bashopts}" ]] &&
eqawarn "QA Notice: Global shell options changed and were not
restored while calling '$*'"
[[ "${IFS}" != "${OLDIFS}" ]] &&
eqawarn "QA Notice: Global IFS changed and was not restored
while calling '$*'"