1 |
commit: b846c59c1e2ad80163745de024154cbe845fedaa |
2 |
Author: Oskari Pirhonen <xxc3ncoredxx <AT> gmail <DOT> com> |
3 |
AuthorDate: Mon Feb 27 02:05:39 2023 +0000 |
4 |
Commit: Sam James <sam <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Feb 27 04:43:48 2023 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=b846c59c |
7 |
|
8 |
90config-impl-decl: bug fixes |
9 |
|
10 |
- Match "-Werror=impl..." from gcc |
11 |
- Use separate RE to check for UTF-8 and ASCII quoting when extracting |
12 |
the function name |
13 |
|
14 |
Signed-off-by: Oskari Pirhonen <xxc3ncoredxx <AT> gmail.com> |
15 |
Signed-off-by: Sam James <sam <AT> gentoo.org> |
16 |
|
17 |
bin/install-qa-check.d/90config-impl-decl | 31 +++++++++++++++++++++++++------ |
18 |
1 file changed, 25 insertions(+), 6 deletions(-) |
19 |
|
20 |
diff --git a/bin/install-qa-check.d/90config-impl-decl b/bin/install-qa-check.d/90config-impl-decl |
21 |
index 2fb8307ea..d1bc0e067 100644 |
22 |
--- a/bin/install-qa-check.d/90config-impl-decl |
23 |
+++ b/bin/install-qa-check.d/90config-impl-decl |
24 |
@@ -38,6 +38,12 @@ find_log_targets() { |
25 |
find -files0-from - -type f \( "${find_args[@]}" \) -print0 |
26 |
} |
27 |
|
28 |
+has_utf8_ctype() { |
29 |
+ # Use python to check if the locale is UTF-8 since tools like locale(1) may |
30 |
+ # not exist (eg, musl systems). |
31 |
+ [[ "$("${PORTAGE_PYTHON:-/usr/bin/python}" -c 'import locale; print(locale.getlocale()[1])')" == UTF-8 ]] |
32 |
+} |
33 |
+ |
34 |
config_impl_decl_check() { |
35 |
local files=() |
36 |
local lines=() |
37 |
@@ -46,19 +52,32 @@ config_impl_decl_check() { |
38 |
local entry |
39 |
local line |
40 |
local func |
41 |
- local re=" function '([[:print:]]+)'" |
42 |
+ local re_uni |
43 |
+ local re_asc |
44 |
+ local is_utf8 |
45 |
+ |
46 |
+ # Given the UTF-8 character type, both gcc and clang may enclose the |
47 |
+ # function name between the LEFT SINGLE QUOTATION MARK and RIGHT SINGLE |
48 |
+ # QUOTATION MARK codepoints. |
49 |
+ re_uni=$' function \u2018([^\u2019]+)\u2019' |
50 |
+ |
51 |
+ # This variant matches ASCII single quotes. |
52 |
+ re_asc=$' function \x27([^\x27]+)\x27' |
53 |
+ |
54 |
+ # Is UTF-8 the effective character type? |
55 |
+ has_utf8_ctype; is_utf8=$(( $? == 0 )) |
56 |
|
57 |
# Iterate over every log file found and check for '-Wimplicit-function-declaration' |
58 |
while IFS= read -rd '' l; do |
59 |
while IFS= read -ru3 entry; do |
60 |
# Strip ANSI codes (color and erase in line have been seen at least) |
61 |
- entry="$(printf '%s\n' "${entry}" | sed -E -e $'s/\033\[[0-9;]*[A-Za-z]//g')" |
62 |
+ entry="$(printf '%s\n' "${entry}" | LC_ALL='C' sed -E -e $'s/\033\[[0-9;]*[A-Za-z]//g')" |
63 |
|
64 |
line="${entry%%:*}" |
65 |
- # This conditional should always be true unless compiler warnings |
66 |
- # get drastically changed |
67 |
- if [[ ${entry} =~ ${re} ]]; then |
68 |
+ if [[ ${is_utf8} -eq 1 && ${entry} =~ ${re_uni} ]] || [[ ${entry} =~ ${re_asc} ]]; then |
69 |
func="${BASH_REMATCH[1]}" |
70 |
+ else |
71 |
+ continue |
72 |
fi |
73 |
|
74 |
has "${func}" "${QA_CONFIG_IMPL_DECL_SKIP[@]}" && continue |
75 |
@@ -67,7 +86,7 @@ config_impl_decl_check() { |
76 |
lines+=( "${line}" ) |
77 |
funcs+=( "${func}" ) |
78 |
# Using -I to ignore binary files is a GNU extension for grep |
79 |
- done 3< <(grep -nEI -e '-Wimplicit-function-declaration' "${l}") |
80 |
+ done 3< <(grep -nEI -e '-W(error=)?implicit-function-declaration' "${l}") |
81 |
done < <(find_log_targets) |
82 |
|
83 |
# Drop out early if no impl decls found (all the arrays are the same size) |