1 |
commit: 605ad0d675a64eb39144122cf284100192cdfea0 |
2 |
Author: Thomas Bracht Laumann Jespersen <t <AT> laumann <DOT> xyz> |
3 |
AuthorDate: Thu Apr 21 08:41:14 2022 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Apr 28 15:50:16 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=605ad0d6 |
7 |
|
8 |
ebegin/eend: accept properly nested calls in different functions |
9 |
|
10 |
Turn the EBEGIN_EEND variable into a stack that tracks which function |
11 |
called ebegin. Calls to ebegin may be stacked and do not generate a QA |
12 |
warning if the callers are different functions. Calls to eend then check |
13 |
that the function name at the top of the stack matches the caller's |
14 |
function name. |
15 |
|
16 |
Bug: https://bugs.gentoo.org/839585 |
17 |
Bug: https://bugs.gentoo.org/839588 |
18 |
Signed-off-by: Thomas Bracht Laumann Jespersen <t <AT> laumann.xyz> |
19 |
Closes: https://github.com/gentoo/portage/pull/824 |
20 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
21 |
|
22 |
bin/isolated-functions.sh | 22 ++++++++++++++++++---- |
23 |
bin/phase-functions.sh | 4 +++- |
24 |
2 files changed, 21 insertions(+), 5 deletions(-) |
25 |
|
26 |
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh |
27 |
index 03983a9fa..912782914 100644 |
28 |
--- a/bin/isolated-functions.sh |
29 |
+++ b/bin/isolated-functions.sh |
30 |
@@ -340,9 +340,15 @@ ebegin() { |
31 |
LAST_E_LEN=$(( 3 + ${#RC_INDENTATION} + ${#msg} )) |
32 |
LAST_E_CMD="ebegin" |
33 |
if [[ -v EBEGIN_EEND ]] ; then |
34 |
- eqawarn "QA Notice: ebegin called, but missing call to eend (phase: ${EBUILD_PHASE})" |
35 |
+ # Already a call to ebegin |
36 |
+ local prev="${EBEGIN_EEND[-1]}" |
37 |
+ if [[ "${prev}" == "${FUNCNAME[1]}" ]] ; then |
38 |
+ eqawarn "QA Notice: ebegin called in ${prev}, but missing call to eend (${FUNCNAME[1]})" |
39 |
+ fi |
40 |
+ EBEGIN_EEND+=( "${FUNCNAME[1]}" ) |
41 |
+ else |
42 |
+ EBEGIN_EEND=( "${FUNCNAME[1]}" ) |
43 |
fi |
44 |
- EBEGIN_EEND=1 |
45 |
return 0 |
46 |
} |
47 |
|
48 |
@@ -372,9 +378,17 @@ __eend() { |
49 |
eend() { |
50 |
[[ -n $1 ]] || eqawarn "QA Notice: eend called without first argument" |
51 |
if [[ -v EBEGIN_EEND ]] ; then |
52 |
- unset EBEGIN_EEND |
53 |
+ local caller="${FUNCNAME[1]}" |
54 |
+ local tos="${EBEGIN_EEND[-1]}" |
55 |
+ if [[ "${caller}" != "${tos}" ]] ; then |
56 |
+ eqawarn "QA Notice: eend (in ${caller}) improperly matched with ebegin (called in ${tos})" |
57 |
+ fi |
58 |
+ unset EBEGIN_EEND[-1] |
59 |
+ if [[ ${#EBEGIN_EEND[@]} -eq 0 ]] ; then |
60 |
+ unset EBEGIN_EEND |
61 |
+ fi |
62 |
else |
63 |
- eqawarn "QA Notice: eend called without preceding ebegin (phase: ${EBUILD_PHASE})" |
64 |
+ eqawarn "QA Notice: eend called without preceding ebegin (phase: ${FUNCNAME[1]})" |
65 |
fi |
66 |
local retval=${1:-0} |
67 |
shift |
68 |
|
69 |
diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh |
70 |
index bccf88226..6b48c2351 100644 |
71 |
--- a/bin/phase-functions.sh |
72 |
+++ b/bin/phase-functions.sh |
73 |
@@ -1089,7 +1089,9 @@ __ebuild_main() { |
74 |
esac |
75 |
|
76 |
if [[ -v EBEGIN_EEND ]] ; then |
77 |
- eqawarn "QA Notice: ebegin called, but missing call to eend (phase: ${1})" |
78 |
+ for func in "${EBEGIN_EEND[@]}" ; do |
79 |
+ eqawarn "QA Notice: ebegin called in ${func} but missing call to eend" |
80 |
+ done |
81 |
fi |
82 |
|
83 |
# Save the env only for relevant phases. |