From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1490824-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id DF712158030
	for <garchives@archives.gentoo.org>; Sun, 26 Feb 2023 20:22:50 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 2BCA4E0843;
	Sun, 26 Feb 2023 20:22:50 +0000 (UTC)
Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id F20B0E0843
	for <gentoo-commits@lists.gentoo.org>; Sun, 26 Feb 2023 20:22:49 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 17DD4340E23
	for <gentoo-commits@lists.gentoo.org>; Sun, 26 Feb 2023 20:22:49 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 9423F807
	for <gentoo-commits@lists.gentoo.org>; Sun, 26 Feb 2023 20:22:47 +0000 (UTC)
From: "Sam James" <sam@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, "Sam James" <sam@gentoo.org>
Message-ID: <1677442962.dc1e8d7b9ad8f7253fa14e068547b63b14c829b7.sam@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: bin/install-qa-check.d/
X-VCS-Repository: proj/portage
X-VCS-Files: bin/install-qa-check.d/90config-impl-decl
X-VCS-Directories: bin/install-qa-check.d/
X-VCS-Committer: sam
X-VCS-Committer-Name: Sam James
X-VCS-Revision: dc1e8d7b9ad8f7253fa14e068547b63b14c829b7
X-VCS-Branch: master
Date: Sun, 26 Feb 2023 20:22:47 +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-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: 6a5ac490-2781-4f08-a3ca-00cce26603b3
X-Archives-Hash: 2c719ad0669190af4b25d35ea414bf30

commit:     dc1e8d7b9ad8f7253fa14e068547b63b14c829b7
Author:     Oskari Pirhonen <xxc3ncoredxx <AT> gmail <DOT> com>
AuthorDate: Wed Feb  1 04:32:20 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Feb 26 20:22:42 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=dc1e8d7b

install-qa-check.d/90config-impl-decl: check config log for warnings

Check for -Wimplicit-function-declaration in:

- config.log
- CMakeError.log
- meson-log.txt

and log the config log, line number, and function name on-screen and in
qa.log under the tag 'config.log-impl-decl'. In ebuilds, use the
`QA_CONFIG_IMPL_DECL_SKIP` array to skip false positives.

Closes: https://bugs.gentoo.org/892651
Signed-off-by: Oskari Pirhonen <xxc3ncoredxx <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/install-qa-check.d/90config-impl-decl | 87 +++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/bin/install-qa-check.d/90config-impl-decl b/bin/install-qa-check.d/90config-impl-decl
new file mode 100644
index 000000000..2fb8307ea
--- /dev/null
+++ b/bin/install-qa-check.d/90config-impl-decl
@@ -0,0 +1,87 @@
+# Check for implicit function declaration warnings in configure logs
+#
+# ebuilds should set the QA_CONFIG_IMPL_DECL_SKIP array to skip known false
+# positives.
+#
+# Some examples of logs to look for:
+# bash: work/bash-5.1/config.log
+#       ^---  easy
+# python: work/Python-3.10.9/config.log
+#         ^---  easy
+# gcc: work/build/config.log
+#      ^---  can be out-of-tree
+# clang: work/x/y/clang-abi_x86_64.amd64/CMakeFiles/CMakeError.log
+#        ^---  can be non-autotools (and very deep)
+# systemd-utils: work/systemd-stable-251.10-abi_x86_64.amd64/meson-logs/meson-log.txt
+#                ^---  can be non-autotools
+#
+# Adapted from macports portconfigure.tcl with love.
+#
+# See also: bug 892651
+
+find_log_targets() {
+	local log_targets=(
+		'config.log'
+		'CMakeError.log'
+		'meson-log.txt'
+	)
+	local find_args=()
+	local log
+
+	# Find config logs. Assume the dirs can have spaces in them, even though
+	# that is hella evil and goes against good filesystem manners!
+	for log in "${log_targets[@]}"; do
+		find_args+=( '-name' "${log}" '-o' )
+	done
+	unset -v 'find_args[-1]'
+	printf '%s\0' "${WORKDIR}" |
+		find -files0-from - -type f \( "${find_args[@]}" \) -print0
+}
+
+config_impl_decl_check() {
+	local files=()
+	local lines=()
+	local funcs=()
+	local l
+	local entry
+	local line
+	local func
+	local re=" function '([[:print:]]+)'"
+
+	# Iterate over every log file found and check for '-Wimplicit-function-declaration'
+	while IFS= read -rd '' l; do
+		while IFS= read -ru3 entry; do
+			# Strip ANSI codes (color and erase in line have been seen at least)
+			entry="$(printf '%s\n' "${entry}" | sed -E -e $'s/\033\[[0-9;]*[A-Za-z]//g')"
+
+			line="${entry%%:*}"
+			# This conditional should always be true unless compiler warnings
+			# get drastically changed
+			if [[ ${entry} =~ ${re} ]]; then
+				func="${BASH_REMATCH[1]}"
+			fi
+
+			has "${func}" "${QA_CONFIG_IMPL_DECL_SKIP[@]}" && continue
+
+			files+=( "${l}" )
+			lines+=( "${line}" )
+			funcs+=( "${func}" )
+		# Using -I to ignore binary files is a GNU extension for grep
+		done 3< <(grep -nEI -e '-Wimplicit-function-declaration' "${l}")
+	done < <(find_log_targets)
+
+	# Drop out early if no impl decls found (all the arrays are the same size)
+	[[ ${#files[@]} -eq 0 ]] && return
+
+	eqawarn 'Found the following implicit function declarations in configure logs:'
+	for l in "${!files[@]}"; do
+		eqawarn "  ${files[l]}:${lines[l]} - ${funcs[l]}"
+		eqatag 'config.log-impl-decl' "line=${lines[l]}" "func=${funcs[l]}" "${files[l]}"
+	done
+	eqawarn 'Check that no features were accidentally disabled.'
+}
+
+config_impl_decl_check
+: # guarantee successful exit
+
+# vim:ft=sh noexpandtab: