SDL: build-scripts: Add a buildbot script for CodeChecker static analysis.

From f7ee06f3a53f7ef39228003e03cce51c87542619 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Fri, 27 Aug 2021 00:50:43 -0400
Subject: [PATCH] build-scripts: Add a buildbot script for CodeChecker static
 analysis.

---
 build-scripts/codechecker-buildbot.sh | 53 +++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 build-scripts/codechecker-buildbot.sh

diff --git a/build-scripts/codechecker-buildbot.sh b/build-scripts/codechecker-buildbot.sh
new file mode 100644
index 0000000000..f39c08b8a1
--- /dev/null
+++ b/build-scripts/codechecker-buildbot.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+# This is a script used by some Buildbot build workers to push the project
+#  through Clang's static analyzer and prepare the output to be uploaded
+#  back to the buildmaster. You might find it useful too.
+
+# Install Clang (you already have it on macOS, apt-get install clang
+#  on Ubuntu, etc), install CMake, and pip3 install codechecker.
+
+FINALDIR="$1"
+
+set -x
+set -e
+
+cd `dirname "$0"`
+cd ..
+
+rm -rf codechecker-buildbot
+if [ ! -z "$FINALDIR" ]; then
+    rm -rf "$FINALDIR"
+fi
+
+mkdir codechecker-buildbot
+cd codechecker-buildbot
+
+# We turn off deprecated declarations, because we don't care about these warnings during static analysis.
+cmake -Wno-dev -DSDL_STATIC=OFF -DCMAKE_BUILD_TYPE=Debug -DASSERTIONS=enabled -DCMAKE_C_FLAGS="-Wno-deprecated-declarations" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ..
+
+# CMake on macOS adds "-arch arm64" or whatever is appropriate, but this confuses CodeChecker, so strip it out.
+perl -w -pi -e 's/\-arch\s+.*?\s+//g;' compile_commands.json
+
+rm -rf ../analysis
+CodeChecker analyze compile_commands.json -o ./reports
+CodeChecker parse ./reports -e html -o ../analysis
+
+cd ..
+chmod -R a+r analysis
+chmod -R go-w analysis
+find analysis -type d -exec chmod a+x {} \;
+if [ -x /usr/bin/xattr ]; then find analysis -exec /usr/bin/xattr -d com.apple.quarantine {} \; 2>/dev/null ; fi
+
+if [ ! -z "$FINALDIR" ]; then
+    mv analysis "$FINALDIR"
+else
+    FINALDIR=analysis
+fi
+
+rm -rf codechecker-buildbot
+
+echo "Done. Final output is in '$FINALDIR' ..."
+
+# end of codechecker-buildbot.sh ...
+