Commit 87f1a590 authored by Wei-Cheng Wu's avatar Wei-Cheng Wu
Browse files

Add WHITELIST to cannotate-cc

parent 7f6b4d2f
......@@ -9,26 +9,27 @@
# Environment variables:
# - env CRIT: state which coverage criteria to use. Default: all
# - env ORIG_CC: the original compiler to involve after annotation. Default: gcc
# - env SKIPS: the files directly sent to ORIG_CC without annotation
# - env WHITELIST: the files to perform cannotate, overwrites SKIPLIST
# - env SKIPLIST: the files directly sent to ORIG_CC without annotation
##
set -e
if [ -z $CRIT ]; then
export CRIT="ABS,AOR,COR,ROR,MCC"
export CRIT="ABS,AOR,COR,ROR,MCC"
fi
if [ -z $ORIG_CC ]; then
export ORIG_CC=gcc
export ORIG_CC=gcc
fi
# A list of file not annotating, directly pass to orig-compiler
SKIPS="$SKIPS conftest.c"
SKIPLIST="$SKIPLIST conftest.c"
FLAGS="-I/usr/include/ -I/usr/local/include/"
CFILES=
if [[ ! -z $DEBUG ]]; then
DEBUG=0
DEBUG=0
fi
RED='\033[1;31m'
......@@ -46,84 +47,101 @@ NC='\033[0m'
# $1 file
#
cannotate_file() {
file=$1
cp $file ${file}.tmp.orig
file=$1
cp $file ${file}.tmp.orig
# Perform side-effect if haven't run before
if ! $(grep -Fq "/*** Processed by Side-Effect Tool ***/" $file); then
echo -e "${GREEN}-> Running ${BGREEN}Side-effect${NC} on $file..."
# Perform clang-tidy first
if [ $DEBUG ]; then
set -x
clang-tidy -fix\
-checks="readability-braces-around-statements"\
-fix-errors\
$file -- $FLAGS > /dev/null
else
clang-tidy -fix\
-checks="readability-braces-around-statements"\
-fix-errors\
$file -- $FLAGS > /dev/null 2>&1
fi
# Then side-effect
side-effect $file -o ${file}.tmp.sf -- $FLAGS > /dev/null
cp ${file}.tmp.sf ${file}
set +x
fi
# Perform side-effect if haven't run before
if ! $(grep -Fq "/*** Processed by Side-Effect Tool ***/" $file); then
echo -e "${GREEN}-> Running ${BGREEN}Side-effect${NC} on $file..."
# Perform clang-tidy first
if [ $DEBUG ]; then
set -x
clang-tidy -fix\
-checks="readability-braces-around-statements"\
-fix-errors\
$file -- $FLAGS > /dev/null
else
clang-tidy -fix\
-checks="readability-braces-around-statements"\
-fix-errors\
$file -- $FLAGS > /dev/null 2>&1
fi
# Then side-effect
side-effect $file -o ${file}.tmp.sf -- $FLAGS > /dev/null
cp ${file}.tmp.sf ${file}
set +x
fi
# Perform cannotate if haven't run before
if ! $(grep -Fq "/*** Processed by CAnnotate ***/" $file); then
echo -e "${GREEN}-> Running ${BGREEN}CAnnotate${NC} on $file..."
[ $DEBUG ] && set -x
cannotate $file --crit="$CRIT" -o ${file}.tmp.ca -- $FLAGS > /dev/null
cp ${file}.tmp.ca ${file}
set +x
fi
# Perform cannotate if haven't run before
if ! $(grep -Fq "/*** Processed by CAnnotate ***/" $file); then
echo -e "${GREEN}-> Running ${BGREEN}CAnnotate${NC} on $file..."
[ $DEBUG ] && set -x
cannotate $file --crit="$CRIT" -o ${file}.tmp.ca -- $FLAGS > /dev/null
cp ${file}.tmp.ca ${file}
set +x
fi
echo -e "${GREEN}-> Finishing annotating${NC} ${file} with ${BLUE}CRIT='${CRIT}'.${NC}"
}
# Function: check_docannotate()
# Check if we are annotating a file with WHITELIST or SKIPLIST
#
# GLOBALS:
# WHITELIST, SKIPLIST, INCLUDES, FLAGS, GREEN, BLUE, NC
# ARGUMENTS:
# $1 file
#
check_do_cannotate() {
cfile=$1
f_cfile="$(cd $(dirname $cfile) && pwd)/$(basename $cfile)"
if [ -n "$WHITELIST" ]; then
for wfile in ${WHITELIST[@]}; do
if [[ "$f_cfile" == *"$wfile"* ]]; then
return 0
fi
done
return 1
else
for skipfile in ${SKIPLIST[@]}; do
if [[ "$f_cfile" == *"$skipfile"* ]]; then
[ $DEBUG ] && echo -e "${GREEN}Skipping${NC} $cfile..."
return 1
fi
done
fi
}
# Extracting arguments
orig_args=$@
while [[ $# > 0 ]] ;do
case "$1" in
-o)
if [ ! -z "$OUTPUT" ]; then
echo -e "${RED}error:${NC} output filename specified twice"
exit 1
fi
OUTPUT="$1 $2"
shift
;;
-E)
echo -e "${RED}error:${NC} Please don't use -E with cannotate-cc"
exit 1
;;
*.c)
CFILES="$CFILES $1"
;;
*)
FLAGS="$FLAGS $1"
;;
esac
shift
case "$1" in
-o)
if [ ! -z "$OUTPUT" ]; then
echo -e "${RED}error:${NC} output filename specified twice"
exit 1
fi
OUTPUT="$1 $2"
shift
;;
-E)
echo -e "${RED}error:${NC} Please don't use -E with cannotate-cc"
exit 1
;;
*.c)
CFILES="$CFILES $1"
;;
*)
FLAGS="$FLAGS $1"
;;
esac
shift
done
# Annotating each C file
for cfile in ${CFILES[@]}; do
skip=0
for skipfile in ${SKIPS[@]}; do
if [[ $cfile == $skipfile ]]; then
skip=1
break
fi
done
if [[ $skip -eq 1 ]]; then
[ $DEBUG ] && echo -e "${GREEN}Skipping${NC} $cfile..."
continue
fi
cannotate_file $cfile
check_do_cannotate $cfile && cannotate_file $cfile
done
# After annotation, hand it back to the original compiler
echo -e "${GREEN}-> Finishing annotating${NC} ${CFILES} with ${BLUE}CRIT='${CRIT}'.${NC}"
set -x
$ORIG_CC $orig_args
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment