Skip to content

Instantly share code, notes, and snippets.

@karkhaz

karkhaz/run.sh

Created Oct 26, 2016
Embed
What would you like to do?
#!/bin/sh
#
# Run clang static analyzer on magenta.
#
# Usage:
# run.sh
#
# To build a single target, set the TARGET variable:
# TARGET=build-magenta-pc-x86-64/dev/hw_rng/hw_rng.mod.o ./run.sh
set -e
# Location of toolchain
TC=~/doc/build
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"
BINUTILS=~/doc/fuchsia/magenta/prebuilt/downloads/x86_64-elf-6.2.0-Linux-x86_64/bin
for tool in objcopy nm ld ld.gold strip readelf; do
cp "$BINUTILS/x86_64-elf-$tool" "$TC/bin/$tool"
done
# strace_interceptor.py 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
fi
(>&2 echo "Using $tool from $LOC")
done
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 \
TOOLCHAIN_PREFIX=$TC/bin/ \
ARCH_x86_64_TOOLCHAIN_PREFIX=$TC/bin/ \
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
./clangify.py --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)
"$XTU_SCRIPT_DIR/xtu-build.py" \
--clang-path "$TC/bin" -v -b $CLANGIFIED_COMPILE_DATABASE \
2>&1 | tee --append $OUT_FILE
(>&2 echo Running xtu-analyze.py)
(echo Running xtu-analyze.py >> $OUT_FILE)
rm -rf .xtu-out
CCC_CC="$TC/bin/clang" "$XTU_SCRIPT_DIR/xtu-analyze.py" \
-b $CLANGIFIED_COMPILE_DATABASE --clang-path="$TC" \
--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