ClickHouse/docker/packager/other/fuzzer.sh

36 lines
1.4 KiB
Bash
Raw Normal View History

2021-08-24 00:09:19 +00:00
#!/usr/bin/env bash
# This script is responsible for building all fuzzers, and copy them to output directory
# as an archive.
2021-08-24 23:11:48 +00:00
# Script is supposed that we are in build directory.
set -x -e
printenv
2021-08-24 00:09:19 +00:00
# Delete previous cache, because we add a new flags -DENABLE_FUZZING=1 and -DFUZZER=libfuzzer
rm -f CMakeCache.txt
read -ra CMAKE_FLAGS <<< "${CMAKE_FLAGS:-}"
# Hope, that the most part of files will be in cache, so we just link new executables
2021-10-26 17:30:34 +00:00
# Please, add or change flags directly in cmake
cmake --debug-trycompile --verbose=1 -DCMAKE_VERBOSE_MAKEFILE=1 -LA -DCMAKE_C_COMPILER="$CC" -DCMAKE_CXX_COMPILER="$CXX" \
-DSANITIZE="$SANITIZER" -DENABLE_FUZZING=1 -DFUZZER='libfuzzer' -DENABLE_PROTOBUF=1 -DUSE_INTERNAL_PROTOBUF_LIBRARY=1 "${CMAKE_FLAGS[@]}" ..
2021-08-24 00:09:19 +00:00
FUZZER_TARGETS=$(find ../src -name '*_fuzzer.cpp' -execdir basename {} .cpp ';' | tr '\n' ' ')
2021-10-26 17:30:34 +00:00
NUM_JOBS=$(($(nproc || grep -c ^processor /proc/cpuinfo)))
2021-08-24 00:09:19 +00:00
mkdir -p /output/fuzzers
for FUZZER_TARGET in $FUZZER_TARGETS
do
# shellcheck disable=SC2086 # No quotes because I want it to expand to nothing if empty.
2021-10-26 17:30:34 +00:00
ninja $NINJA_FLAGS $FUZZER_TARGET -j $NUM_JOBS
2021-08-24 00:09:19 +00:00
# Find this binary in build directory and strip it
FUZZER_PATH=$(find ./src -name "$FUZZER_TARGET")
strip --strip-unneeded "$FUZZER_PATH"
mv "$FUZZER_PATH" /output/fuzzers
done
tar -zcvf /output/fuzzers.tar.gz /output/fuzzers
rm -rf /output/fuzzers