commit:     0d4ffd51d3dc86782dae2db9fe632f45af7eec87
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 15 09:56:55 2020 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Sat Feb 15 09:56:55 2020 +0000
URL:        https://gitweb.gentoo.org/proj/pms.git/commit/?id=0d4ffd51

ebuild-functions.tex: Update array detection code.

Remove the space after "declare -a" for matching "declare -p" output.
With the update of the bash version to 4.2 in EAPI 6, variables can
have other attributes in addition, which would make the test fail.
For example, see https://bugs.gentoo.org/444832#c7. The implementation
in Portage already omits the space.

Replace grep by functionally equivalent code in bash. This is how the
test is implemented in package managers, and follows the principle
that external programs should not be called unnecessarily.

Redirect stderr for "declare -p", because it outputs an error message
if the PATCHES variable is not defined.

Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>

 ebuild-functions.tex | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/ebuild-functions.tex b/ebuild-functions.tex
index 33c003a..4a13db6 100644
--- a/ebuild-functions.tex
+++ b/ebuild-functions.tex
@@ -133,7 +133,7 @@ as:
 \caption{\t{src_prepare}, format~6}
 \begin{verbatim}
 src_prepare() {
-    if declare -p PATCHES | grep -q "^declare -a "; then
+    if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]]; then
         [[ -n ${PATCHES[@]} ]] && eapply "${PATCHES[@]}"
     else
         [[ -n ${PATCHES} ]] && eapply ${PATCHES}
@@ -325,13 +325,13 @@ src_install() {
         emake DESTDIR="${D}" install
     fi
 
-    if ! declare -p DOCS >/dev/null 2>&1 ; then
+    if ! declare -p DOCS >/dev/null 2>&1; then
         local d
         for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
-                THANKS BUGS FAQ CREDITS CHANGELOG ; do
+                THANKS BUGS FAQ CREDITS CHANGELOG; do
             [[ -s "${d}" ]] && dodoc "${d}"
         done
-    elif declare -p DOCS | grep -q "^declare -a " ; then
+    elif [[ $(declare -p DOCS) == "declare -a"* ]]; then
         dodoc "${DOCS[@]}"
     else
         dodoc ${DOCS}

Reply via email to