From f5f9784ab754891675c83a4ca70a21df5d656c74 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Thu, 8 Jan 2015 22:44:35 +0100 Subject: Introduce a new analysis tool to detect which macros are defined in each build. See the usage() for more information. Change-Id: I712ef4d6bd21eccefa18cec144e35b8161ca5b3a --- utils/analysis/check_defines.sh | 196 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100755 utils/analysis/check_defines.sh diff --git a/utils/analysis/check_defines.sh b/utils/analysis/check_defines.sh new file mode 100755 index 0000000000..c58c060586 --- /dev/null +++ b/utils/analysis/check_defines.sh @@ -0,0 +1,196 @@ +#/bin/bash + +TMPDIR="./tmp-check-defines" +SEARCH_DIRS="apps/ firmware/ uisimulator/" + +function usage() +{ + echo "Usage: $0 [...]" + echo "" + echo "This tool tries to detect which macros are defined in each build," + echo "it uses the www repository build list to find the targets to build." + echo "By default it ignores wps and sim builds, feel free to hack the code," + echo "if you want to change this. The tool can not only detect which macros" + echo "get define but also print the values and try to pretty print it." + echo "" + echo "If the define name is suffixed with @ or ~, the tool will also print its value" + echo "Furthermore, if a regex follows the @, the tool will try to list all defines" + echo "matching this regex to pretty print the output" + echo "If the define name is suffixed with ~, the tool will try to list all definitions" + echo "of the macro and compare the right hand side value with the actual value" + echo "to pretty print the value" + echo "" + echo "IMPORTANT: the tools needs to be ran from the root directory of the" + echo " repository" + echo "" + echo "Examples:" + echo "$0 ../www/buildserver/builds HAVE_USBSTACK " + echo "$0 ../www/buildserver/builds 'CONFIG_LCD@LCD_[[:alnum:]_]*'" + echo "$0 ../www/buildserver/builds CONFIG_CPU~" + exit 1 +} + +# pattern_check define file +function pattern_check() +{ + cat >>"$2" <>"$2" <>"$3" <>"$2" <> $2 +cat >>"$2" < "$TMPLFILE" < /dev/null`; then + continue + fi + # format of each line: compiler:x:name:title:file:hint:command + NAME=`echo "$line" | awk 'BEGIN { FS=":" } { print $3 }'` + CMD=`echo "$line" | awk 'BEGIN { FS=":" } { print $7 }'` + # remove temporary directory + rm -rf "$TMPDIR" + # create temporary directory and cd into it + mkdir "$TMPDIR" + cd "$TMPDIR" + # create a fake generated file + TESTFILE=mytest + cp "../$TMPLFILE" "$TESTFILE.c" + # the command extract is of the form + # ../tools/configure && make + # extract the part before && and replace the whole thing with: + # ../tools/configure && make $TESTFILE.o + CFGCMD=`echo "$CMD" | awk '{ i=index($0, "&&"); print(substr($0,1,i-1)); }'` + # try to run configure + # it might error if the target compiler is not installed for example + if eval $CFGCMD &>/dev/null; then + # pretend dependencies were generated (because it's very long) + touch make.dep + # try to build our test file + OUTPUT=out.txt + ERROR=err.txt + if ! make $TESTFILE.o >$OUTPUT 2>$ERROR; then + # print make error + echo "$NAME: " + else + # print defines + echo "$NAME:" `cat "$ERROR" | awk 'BEGIN { list="" } + { if(match($0,/cafebabe-([[:alnum:]_]+)/,arr) != 0) list = list " " arr[1]; + if(match($0,/@([^@]*)@/,arr)) list = list "=" arr[1]; } + END { print(list); }'` + fi + else + # print config error + echo "$NAME: " + fi + # cd back to root + cd .. +done < "$BUILD_FILE" + +# remove everything +rm -rf "$TMPDIR" +rm -f "$TMPLFILE" \ No newline at end of file -- cgit v1.2.3