Skip to content

Instantly share code, notes, and snippets.



Created Oct 26, 2016
What would you like to do?
# Run clang static analyzer on magenta.
# Usage:
# To build a single target, set the TARGET variable:
# TARGET=build-magenta-pc-x86-64/dev/hw_rng/hw_rng.mod.o ./
set -e
# Location of toolchain
export PATH="$TC/bin:$PATH"
export PATH="$TC/libexec:$PATH"
export PATH="~/doc/llvm/tools/clang/tools/xtu-build:$PATH"
export OUT_FILE="xtu-out/$(date -Iseconds).log"
for tool in objcopy nm ld strip readelf; do
cp "$BINUTILS/x86_64-elf-$tool" "$TC/bin/$tool"
# and other xtu-* tools need this
export CLANG_PATH="$TC/bin"
# ccc-analyzer needs this
export CCC_CC="$TC/bin/clang"
export XTU_SCRIPT_DIR=~/doc/llvm/tools/clang/tools/xtu-build-new
export CLANGIFIED_COMPILE_DATABASE=clang_compile_commands.json
# Sanity checks
for tool in clang ld ccc-analyzer; do
LOC=`which "$tool"`
if [ "$?" != "0" ]; then
(>&2 echo "Unable to find path to $tool");
exit 1
(>&2 echo "Using $tool from $LOC")
mkdir -p xtu-out
echo >$OUT_FILE
export TARGET="${TARGET:-magenta-px-x86-64}"
echo "Building target $TARGET"
# Initially, run the build process as usual, but wrapped up in bear to
# generate a compile_commands.json file.
bear make \
USE_CLANG=true \
LIBGCC=$TC/lib/clang/4.0.0/lib/linux/libclang_rt.builtins-x86_64.a \
V=1 \
-j 48 $TARGET 2>&1 | tee --append $OUT_FILE
# Bear is seeing compiler invocations as invocations to "cc" rather than
# "clang" for some reason. This is bad, since if we re-play those
# invocations we'll end up being redirected to GCC. Replace occurrences
# of "cc" with the path to clang in compile_commands.json
./ --clang-path "$TC/bin/clang" > $CLANGIFIED_COMPILE_DATABASE
(>&2 echo Running xtu-build with compilation database)
(echo Running xtu-build with compilation database >> $OUT_FILE)
--clang-path "$TC/bin" -v -b $CLANGIFIED_COMPILE_DATABASE \
2>&1 | tee --append $OUT_FILE
(>&2 echo Running
(echo Running >> $OUT_FILE)
rm -rf .xtu-out
CCC_CC="$TC/bin/clang" "$XTU_SCRIPT_DIR/" \
--ccc-analyzer-path ~/doc/build/libexec --output-format html \
2>&1 | tee --append $OUT_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment