mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-12 10:13:51 +01:00
Merge pull request #147 from keith-bennett-airmap/keith/shellcheck
This commit is contained in:
commit
7b8654382a
62
shellcheck.sh
Normal file
62
shellcheck.sh
Normal file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# Shellcheck is a static analyzer for shell scripts: https://shellcheck.net/
|
||||
# It is available in several operating systems and also as a docker image.
|
||||
#
|
||||
# If it finds any issues, it will output a small blurb describing the affected
|
||||
# line(s) and will have a generic issue ID. The issue ID can be opened on its
|
||||
# website to learn more about what the underlying problem is, why it's a
|
||||
# problem, and (usually) suggests a way to fix.
|
||||
# Specific shellcheck issues can be disabled (aka silenced). Doing so is
|
||||
# usually pretty loud during code review.
|
||||
# https://github.com/koalaman/shellcheck/wiki/Directive
|
||||
|
||||
# https://stackoverflow.com/a/2871034/1111557
|
||||
set -euo pipefail
|
||||
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
SHELLCHECK="${SHELLCHECK:-"/usr/bin/shellcheck"}"
|
||||
SEARCH_DIR="${SEARCH_DIR:-"$HERE"}"
|
||||
cd "${SEARCH_DIR}" #so that we can call git
|
||||
|
||||
#
|
||||
# This block will:
|
||||
# 1) `find` files under `SEARCH_DIR`
|
||||
# 2) skip anything under `/thirdparty/`, `/.git/`
|
||||
# 3) in a loop reading each path:
|
||||
# 3a) ignore files that git also ignores
|
||||
# 3b) use `file` to filter only script files
|
||||
# 3c) run shellcheck against that script
|
||||
# 4) if any paths are found to have an error, their paths are collated.
|
||||
FAILED_PATHS=()
|
||||
while read -r file_path
|
||||
do
|
||||
if git rev-parse --git-dir > /dev/null 2>&1;
|
||||
then
|
||||
git check-ignore --quiet "${file_path}" && continue
|
||||
fi
|
||||
file "${file_path}" | grep -q 'shell script' || continue
|
||||
SCRIPT_PATH="${file_path}"
|
||||
echo "Checking: ${SCRIPT_PATH}"
|
||||
"${SHELLCHECK}" \
|
||||
"${SCRIPT_PATH}" \
|
||||
|| FAILED_PATHS+=( "${SCRIPT_PATH}" )
|
||||
done < <(
|
||||
find "${SEARCH_DIR}" -type f \
|
||||
| grep -v '/\.git/\|/thirdparty/'
|
||||
)
|
||||
|
||||
#
|
||||
# If there are any failed paths, summarize them here.
|
||||
# Then report a failing status to our caller.
|
||||
if [[ 0 -lt "${#FAILED_PATHS[@]}" ]]; then
|
||||
>&2 echo "These scripts aren't shellcheck-clean:"
|
||||
for path in "${FAILED_PATHS[@]}"; do
|
||||
>&2 echo "${path}"
|
||||
done
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If we get here, then none of the scripts had any warnings.
|
||||
echo "All scripts found (listed above) passed shellcheck"
|
@ -9,13 +9,15 @@ cmake -Dvalijson_BUILD_EXAMPLES=FALSE \
|
||||
-Dvalijson_EXCLUDE_BOOST=TRUE \
|
||||
..
|
||||
|
||||
make -j$(nproc)
|
||||
make -j"$(nproc)"
|
||||
|
||||
cd ../tests/fuzzing
|
||||
|
||||
find ../.. -name "*.o" -exec ar rcs fuzz_lib.a {} \;
|
||||
|
||||
$CXX $CXXFLAGS -DVALIJSON_USE_EXCEPTIONS=1 \
|
||||
# CXXFLAGS may contain spaces
|
||||
# shellcheck disable=SC2086
|
||||
"$CXX" $CXXFLAGS -DVALIJSON_USE_EXCEPTIONS=1 \
|
||||
-I/src/valijson/thirdparty/rapidjson-48fbd8c/include \
|
||||
-I/src/valijson/thirdparty/rapidjson-48fbd8c/include/rapidjson \
|
||||
-I/src/valijson/include \
|
||||
@ -23,10 +25,11 @@ $CXX $CXXFLAGS -DVALIJSON_USE_EXCEPTIONS=1 \
|
||||
-I/src/valijson/include/valijson/adapters \
|
||||
-c fuzzer.cpp -o fuzzer.o
|
||||
|
||||
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE \
|
||||
# shellcheck disable=SC2086
|
||||
"$CXX" $CXXFLAGS "$LIB_FUZZING_ENGINE" \
|
||||
-DVALIJSON_USE_EXCEPTIONS=1 \
|
||||
-rdynamic fuzzer.o \
|
||||
-o $OUT/fuzzer fuzz_lib.a
|
||||
-o "${OUT}/fuzzer fuzz_lib.a"
|
||||
|
||||
zip $OUT/fuzzer_seed_corpus.zip \
|
||||
$SRC/valijson/doc/schema/draft-03.json
|
||||
zip "${OUT}/fuzzer_seed_corpus.zip" \
|
||||
"${SRC}/valijson/doc/schema/draft-03.json"
|
||||
|
Loading…
Reference in New Issue
Block a user