1#!/bin/sh 2 3SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 4 5# Guess path to LLVM_CHECKOUT if not provided 6if [ "${LLVM_CHECKOUT}" = "" ]; then 7 LLVM_CHECKOUT="${SCRIPT_DIR}/../../../../../" 8fi 9 10# python tools setup 11CPPLINT=${SCRIPT_DIR}/cpplint.py 12LITLINT=${SCRIPT_DIR}/litlint.py 13if [ "${PYTHON_EXECUTABLE}" != "" ]; then 14 CPPLINT="${PYTHON_EXECUTABLE} ${CPPLINT}" 15 LITLINT="${PYTHON_EXECUTABLE} ${LITLINT}" 16fi 17 18# Filters 19# TODO: remove some of these filters 20COMMON_LINT_FILTER=-build/include,-build/header_guard,-legal/copyright,-whitespace/comments,-readability/casting,\ 21-build/namespaces 22ASAN_RTL_LINT_FILTER=${COMMON_LINT_FILTER},-runtime/int 23ASAN_TEST_LINT_FILTER=${COMMON_LINT_FILTER},-runtime/sizeof,-runtime/int,-runtime/printf,-runtime/threadsafe_fn 24ASAN_LIT_TEST_LINT_FILTER=${ASAN_TEST_LINT_FILTER},-whitespace/line_length 25TSAN_RTL_LINT_FILTER=${COMMON_LINT_FILTER} 26TSAN_TEST_LINT_FILTER=${TSAN_RTL_LINT_FILTER},-runtime/threadsafe_fn,-runtime/int 27TSAN_LIT_TEST_LINT_FILTER=${TSAN_TEST_LINT_FILTER},-whitespace/line_length 28MSAN_RTL_LINT_FILTER=${COMMON_LINT_FILTER} 29LSAN_RTL_LINT_FILTER=${COMMON_LINT_FILTER} 30LSAN_LIT_TEST_LINT_FILTER=${LSAN_RTL_LINT_FILTER},-whitespace/line_length 31DFSAN_RTL_LINT_FILTER=${COMMON_LINT_FILTER},-runtime/int,-runtime/printf,-runtime/references,-readability/function 32COMMON_RTL_INC_LINT_FILTER=${COMMON_LINT_FILTER},-runtime/int,-runtime/sizeof,-runtime/printf,-readability/fn_size 33SANITIZER_INCLUDES_LINT_FILTER=${COMMON_LINT_FILTER},-runtime/int 34 35MKTEMP_DIR=$(mktemp -qd /tmp/check_lint.XXXXXXXXXX) 36MKTEMP="mktemp -q ${MKTEMP_DIR}/tmp.XXXXXXXXXX" 37cleanup() { 38 rm -rf $MKTEMP_DIR 39} 40trap cleanup EXIT 41 42cd ${LLVM_CHECKOUT} 43 44EXITSTATUS=0 45ERROR_LOG=$(${MKTEMP}) 46 47run_lint() { 48 FILTER=$1 49 shift 50 TASK_LOG=$(${MKTEMP}) 51 ${CPPLINT} --filter=${FILTER} "$@" 2>$TASK_LOG 52 if [ "$?" != "0" ]; then 53 cat $TASK_LOG | grep -v "Done processing" | grep -v "Total errors found" \ 54 | grep -v "Skipping input" >> $ERROR_LOG 55 fi 56 if [ "${SILENT}" != "1" ]; then 57 cat $TASK_LOG 58 fi 59 ${LITLINT} "$@" 2>>$ERROR_LOG 60} 61 62if [ "${COMPILER_RT}" = "" ]; then 63 COMPILER_RT=projects/compiler-rt 64fi 65LIT_TESTS=${COMPILER_RT}/test 66# Headers 67SANITIZER_INCLUDES=${COMPILER_RT}/include/sanitizer 68run_lint ${SANITIZER_INCLUDES_LINT_FILTER} ${SANITIZER_INCLUDES}/*.h & 69 70# Sanitizer_common 71COMMON_RTL=${COMPILER_RT}/lib/sanitizer_common 72run_lint ${COMMON_RTL_INC_LINT_FILTER} ${COMMON_RTL}/*.cc \ 73 ${COMMON_RTL}/*.h \ 74 ${COMMON_RTL}/tests/*.cc & 75 76# Interception 77INTERCEPTION=${COMPILER_RT}/lib/interception 78run_lint ${ASAN_RTL_LINT_FILTER} ${INTERCEPTION}/*.cc \ 79 ${INTERCEPTION}/*.h & 80 81# ASan 82ASAN_RTL=${COMPILER_RT}/lib/asan 83run_lint ${ASAN_RTL_LINT_FILTER} ${ASAN_RTL}/*.cc \ 84 ${ASAN_RTL}/*.h & 85run_lint ${ASAN_TEST_LINT_FILTER} ${ASAN_RTL}/tests/*.cc \ 86 ${ASAN_RTL}/tests/*.h & 87run_lint ${ASAN_LIT_TEST_LINT_FILTER} ${LIT_TESTS}/asan/*/*.cc & 88 89# TSan 90TSAN_RTL=${COMPILER_RT}/lib/tsan 91run_lint ${TSAN_RTL_LINT_FILTER} ${TSAN_RTL}/rtl/*.cc \ 92 ${TSAN_RTL}/rtl/*.h & 93run_lint ${TSAN_TEST_LINT_FILTER} ${TSAN_RTL}/tests/rtl/*.cc \ 94 ${TSAN_RTL}/tests/rtl/*.h \ 95 ${TSAN_RTL}/tests/unit/*.cc & 96run_lint ${TSAN_LIT_TEST_LINT_FILTER} ${LIT_TESTS}/tsan/*.cc & 97 98# MSan 99MSAN_RTL=${COMPILER_RT}/lib/msan 100run_lint ${MSAN_RTL_LINT_FILTER} ${MSAN_RTL}/*.cc \ 101 ${MSAN_RTL}/*.h & 102 103# LSan 104LSAN_RTL=${COMPILER_RT}/lib/lsan 105run_lint ${LSAN_RTL_LINT_FILTER} ${LSAN_RTL}/*.cc \ 106 ${LSAN_RTL}/*.h & 107run_lint ${LSAN_LIT_TEST_LINT_FILTER} ${LIT_TESTS}/lsan/*/*.cc & 108 109# DFSan 110DFSAN_RTL=${COMPILER_RT}/lib/dfsan 111run_lint ${DFSAN_RTL_LINT_FILTER} ${DFSAN_RTL}/*.cc \ 112 ${DFSAN_RTL}/*.h & 113${DFSAN_RTL}/scripts/check_custom_wrappers.sh >> $ERROR_LOG 114 115# Misc files 116FILES=${COMMON_RTL}/*.inc 117TMPFILES="" 118for FILE in $FILES; do 119 TMPFILE="$(${MKTEMP}).$(basename ${FILE}).cc" 120 cp -f $FILE $TMPFILE 121 run_lint ${COMMON_RTL_INC_LINT_FILTER} $TMPFILE & 122 TMPFILES="$TMPFILES $TMPFILE" 123done 124 125wait 126 127for temp in $TMPFILES; do 128 rm -f $temp 129done 130 131if [ -s $ERROR_LOG ]; then 132 cat $ERROR_LOG 133 exit 1 134fi 135 136exit 0 137