From 53a1e246b3c2fc06991acd7fe2f1c373a5a28254 Mon Sep 17 00:00:00 2001
From: Florian Schmaus <flow@cs.fau.de>
Date: Tue, 30 Mar 2021 14:52:40 +0200
Subject: [PATCH] [check-iwyu] Add iwyu log file size check and minor fixes

---
 tools/check-iwyu | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tools/check-iwyu b/tools/check-iwyu
index c693bcd9..645e22ea 100755
--- a/tools/check-iwyu
+++ b/tools/check-iwyu
@@ -3,6 +3,10 @@ set -euo pipefail
 
 # Meson issue regarding iwyu integration: https://github.com/mesonbuild/meson/issues/2637
 
+echoerr() {
+	echo "${@}" 1>&2
+}
+
 # Pretty fancy method to get reliable the absolute path of a shell
 # script, *even if it is sourced*. Credits go to GreenFox on
 # stackoverflow: http://stackoverflow.com/a/12197518/194894
@@ -65,21 +69,28 @@ ${IWYU_TOOL} ${IWYU_TOOL_ARGS[@]} \
 			 -Xiwyu --mapping_file="${MESON_SOURCE_ROOT}/iwyu-mappings.imp" \
 			 > "${IWYU_LOG}"
 
-# Sadly, iwyu_tool.py does not (yet) return an non-zero exit value if
+if [[ ! -s "${IWYU_LOG}" ]]; then
+	echoerr "${IWYU_LOG} is empty (or non existent)"
+	exit 1
+fi
+
+# Sadly, older iwyu_tool.py version do not return an non-zero exit value if
 # there are include issues, so we have to check the output manually.
 # See https://github.com/include-what-you-use/include-what-you-use/issues/790
-# Also note that the output contains "error: nos uch file or
+# Also note that the output contains "error: no such file or
 # directory: 'cc'" if ccache is used (which meson does by default if
 # ccache is available).
-# See https://github.com/include-what-you-use/include-what-you-use/issues/789
+# See
+# - https://github.com/include-what-you-use/include-what-you-use/issues/789
+# - https://github.com/include-what-you-use/include-what-you-use/commit/a7499e4a2b416592777cc4c33fca746d091af738
 ERROR_STRINGS=()
 ERROR_STRINGS+=("should add these lines:")
 ERROR_STRINGS+=("fatal error:")
 
 for ERROR_STRING in "${ERROR_STRINGS[@]}"; do
 	if grep -q "${ERROR_STRING}" "${IWYU_LOG}"; then
-		echo "IWYU found errors!"  
-		cat "${IWYU_LOG}"		   
+		echo "IWYU found errors!"
+		cat "${IWYU_LOG}"
 		exit 1
 	fi
 done
-- 
GitLab