Commit 2a8dacc0 authored by Raphael Defosseux's avatar Raphael Defosseux

CI: better code guideline analysis

-- check if C file has a GNU GPL license
-- check if C file has s suspect license
-- check if C header is having correct circular dependency protection (with Laurent Thomas's help)
Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent 454139ac
...@@ -62,6 +62,30 @@ then ...@@ -62,6 +62,30 @@ then
NB_FILES_TO_FORMAT=`astyle --dry-run --options=ci-scripts/astyle-options.txt --recursive *.c *.h | grep -c Formatted ` NB_FILES_TO_FORMAT=`astyle --dry-run --options=ci-scripts/astyle-options.txt --recursive *.c *.h | grep -c Formatted `
echo "Nb Files that do NOT follow OAI rules: $NB_FILES_TO_FORMAT" echo "Nb Files that do NOT follow OAI rules: $NB_FILES_TO_FORMAT"
echo $NB_FILES_TO_FORMAT > ./oai_rules_result.txt echo $NB_FILES_TO_FORMAT > ./oai_rules_result.txt
# Testing Circular Dependencies protection
awk '/#[ \t]*ifndef/ { gsub("^.*ifndef *",""); if (names[$1]!="") print "files with same {define ", FILENAME, names[$1]; names[$1]=FILENAME } /#[ \t]*define/ { gsub("^.*define *",""); if(names[$1]!=FILENAME) print "error in declaration", FILENAME, $1, names[$1]; nextfile }' `find openair* common targets executables -name *.h |grep -v LFDS` > header-files-w-incorrect-define.txt
# Testing if explicit GNU GPL license banner
egrep -irl --exclude-dir=.git --include=*.cpp --include=*.c --include=*.h "General Public License" . > files-w-gnu-gpl-license-banner.txt
# Looking at exotic/suspect banner
LIST_OF_FILES_W_BANNER=`egrep -irl --exclude-dir=.git --include=*.cpp --include=*.c --include=*.h "Copyright|copyleft" .`
if [ -f ./files-w-suspect-banner.txt ]; then rm -f ./files-w-suspect-banner.txt; fi
for FILE in $LIST_OF_FILES_W_BANNER
do
IS_NFAPI=`echo $FILE | egrep -c "nfapi/open-nFAPI|nfapi/oai_integration/vendor_ext"`
IS_OAI_LICENCE_PRESENT=`egrep -c "OAI Public License" $FILE`
IS_BSD_LICENCE_PRESENT=`egrep -c "the terms of the BSD Licence" $FILE`
IS_EXCEPTION=`echo $FILE | egrep -c "common/utils/collection/tree.h|common/utils/collection/queue.h|common/utils/itti_analyzer/common/queue.h|openair3/UTILS/tree.h|openair3/UTILS/queue.h"`
if [ $IS_OAI_LICENCE_PRESENT -eq 0 ] && [ $IS_BSD_LICENCE_PRESENT -eq 0 ]
then
if [ $IS_NFAPI -eq 0 ] && [ $IS_EXCEPTION -eq 0 ]
then
echo $FILE >> ./files-w-suspect-banner.txt
fi
fi
done
exit 0 exit 0
fi fi
...@@ -131,8 +155,25 @@ if [ -f oai_rules_result_list.txt ] ...@@ -131,8 +155,25 @@ if [ -f oai_rules_result_list.txt ]
then then
rm -f oai_rules_result_list.txt rm -f oai_rules_result_list.txt
fi fi
if [ -f header-files-w-incorrect-define.txt ]
then
rm -f header-files-w-incorrect-define.txt
fi
if [ -f files-w-gnu-gpl-license-banner.txt ]
then
rm -f files-w-gnu-gpl-license-banner.txt
fi
if [ -f files-w-suspect-banner.txt ]
then
rm -f files-w-suspect-banner.txt
fi
awk '/#[ \t]*ifndef/ { gsub("^.*ifndef *",""); if (names[$1]!="") print "files with same {define ", FILENAME, names[$1]; names[$1]=FILENAME } /#[ \t]*define/ { gsub("^.*define *",""); if(names[$1]!=FILENAME) print "error in declaration", FILENAME, $1, names[$1]; nextfile }' `find openair* common targets executables -name *.h |grep -v LFDS` > header-files-w-incorrect-define-tmp.txt
for FULLFILE in $MODIFIED_FILES for FULLFILE in $MODIFIED_FILES
do do
# sometimes, we remove files
if [ ! -f $FULLFILE ]; then continue; fi
filename=$(basename -- "$FULLFILE") filename=$(basename -- "$FULLFILE")
EXT="${filename##*.}" EXT="${filename##*.}"
if [ $EXT = "c" ] || [ $EXT = "h" ] || [ $EXT = "cpp" ] || [ $EXT = "hpp" ] if [ $EXT = "c" ] || [ $EXT = "h" ] || [ $EXT = "cpp" ] || [ $EXT = "hpp" ]
...@@ -144,8 +185,32 @@ do ...@@ -144,8 +185,32 @@ do
echo $FULLFILE echo $FULLFILE
echo $FULLFILE >> ./oai_rules_result_list.txt echo $FULLFILE >> ./oai_rules_result_list.txt
fi fi
# Testing if explicit GNU GPL license banner
egrep -i "General Public License" $FULLFILE >> files-w-gnu-gpl-license-banner.txt
# Looking at exotic/suspect banner
IS_BANNER=`egrep -i -c "Copyright|copyleft" $FULLFILE`
if [ $IS_BANNER -ne 0 ]
then
IS_NFAPI=`echo $FULLFILE | egrep -c "nfapi/open-nFAPI|nfapi/oai_integration/vendor_ext"`
IS_OAI_LICENCE_PRESENT=`egrep -c "OAI Public License" $FULLFILE`
IS_BSD_LICENCE_PRESENT=`egrep -c "the terms of the BSD Licence" $FULLFILE`
IS_EXCEPTION=`echo $FILE | egrep -c "common/utils/collection/tree.h|common/utils/collection/queue.h|common/utils/itti_analyzer/common/queue.h|openair3/UTILS/tree.h|openair3/UTILS/queue.h"`
if [ $IS_OAI_LICENCE_PRESENT -eq 0 ] && [ $IS_BSD_LICENCE_PRESENT -eq 0 ]
then
if [ $IS_NFAPI -eq 0 ] && [ $IS_EXCEPTION -eq 0 ]
then
echo $FILE >> ./files-w-suspect-banner.txt
fi
fi
fi
fi
# Testing Circular Dependencies protection
if [ $EXT = "h" ] || [ $EXT = "hpp" ]
then
grep $FULLFILE header-files-w-incorrect-define-tmp.txt >> header-files-w-incorrect-define.txt
fi fi
done done
rm -f header-files-w-incorrect-define-tmp.txt
echo "" echo ""
echo " ----------------------------------------------------------" echo " ----------------------------------------------------------"
echo "Nb Files that do NOT follow OAI rules: $NB_TO_FORMAT" echo "Nb Files that do NOT follow OAI rules: $NB_TO_FORMAT"
......
...@@ -492,6 +492,77 @@ function report_build { ...@@ -492,6 +492,77 @@ function report_build {
awk '{print " <tr><td>"$1"</td></tr>"}' ./oai_rules_result_list.txt >> ./build_results.html awk '{print " <tr><td>"$1"</td></tr>"}' ./oai_rules_result_list.txt >> ./build_results.html
echo " </table>" >> ./build_results.html echo " </table>" >> ./build_results.html
echo " </div>" >> ./build_results.html echo " </div>" >> ./build_results.html
echo " <br>" >> ./build_results.html
fi
if [ -f ./header-files-w-incorrect-define.txt ]
then
NB_FILES_IN_ERROR=`wc -l ./header-files-w-incorrect-define.txt | sed -e "s@ .*@@"`
if [ $NB_FILES_IN_ERROR -eq 0 ]
then
echo " <div class=\"alert alert-success\">" >> ./build_results.html
if [ $MR_TRIG -eq 1 ]; then echo " <strong>No Issue for CIRCULAR DEPENDENCY PROTECTION in modified files</strong>" >> ./build_results.html; fi
if [ $PU_TRIG -eq 1 ]; then echo " <strong>No Issue for CIRCULAR DEPENDENCY PROTECTION in the whole repository</strong>" >> ./build_results.html; fi
echo " </div>" >> ./build_results.html
else
echo " <div class=\"alert alert-warning\">" >> ./build_results.html
if [ $MR_TRIG -eq 1 ]; then echo " <strong>${NB_FILES_IN_ERROR} modified files MAY NOT HAVE CIRCULAR DEPENDENCY PROTECTION</strong>" >> ./build_results.html; fi
if [ $PU_TRIG -eq 1 ]; then echo " <strong>${NB_FILES_IN_ERROR} files in repository MAY NOT HAVE CIRCULAR DEPENDENCY PROTECTION in the whole repository</strong>" >> ./build_results.html; fi
echo " </div>" >> ./build_results.html
echo " <button data-toggle=\"collapse\" data-target=\"#oai-circular-details\">More details on circular dependency protection check</button>" >> ./build_results.html
echo " <div id=\"oai-circular-details\" class=\"collapse\">" >> ./build_results.html
echo " <table border = 1>" >> ./build_results.html
echo " <tr>" >> ./build_results.html
echo " <th bgcolor = \"lightcyan\" >Potential Issue</th>" >> ./build_results.html
echo " <th bgcolor = \"lightcyan\" >Impacted File</th>" >> ./build_results.html
echo " <th bgcolor = \"lightcyan\" >Incorrect Macro</th>" >> ./build_results.html
echo " </tr>" >> ./build_results.html
awk '{if($0 ~/error in/){print " <tr><td>error in declaration</td><td>"$4"</td><td>"$5"</td></tr>"};if($0 ~/files with same/){print " <tr><td>files with same #define</td><td>"$5"</td><td>"$6"</td></tr>"}}' ./header-files-w-incorrect-define.txt >> ./build_results.html
echo " </table>" >> ./build_results.html
echo " </div>" >> ./build_results.html
echo " <br>" >> ./build_results.html
fi
fi
if [ -f ./files-w-gnu-gpl-license-banner.txt ]
then
NB_FILES_IN_ERROR=`wc -l ./files-w-gnu-gpl-license-banner.txt | sed -e "s@ .*@@"`
if [ $NB_FILES_IN_ERROR -ne 0 ]
then
echo " <div class=\"alert alert-danger\">" >> ./build_results.html
if [ $MR_TRIG -eq 1 ]; then echo " <strong>${NB_FILES_IN_ERROR} modified files HAVE a GNU GPL license banner</strong>" >> ./build_results.html; fi
if [ $PU_TRIG -eq 1 ]; then echo " <strong>${NB_FILES_IN_ERROR} files in repository HAVE a GNU GPL license banner</strong>" >> ./build_results.html; fi
echo " </div>" >> ./build_results.html
echo " <button data-toggle=\"collapse\" data-target=\"#oai-license-gpl\">More details on GNU GPL license banner issue</button>" >> ./build_results.html
echo " <div id=\"oai-license-gpl\" class=\"collapse\">" >> ./build_results.html
echo " <table border = 1>" >> ./build_results.html
echo " <tr>" >> ./build_results.html
echo " <th bgcolor = \"lightcyan\" >Filename</th>" >> ./build_results.html
echo " </tr>" >> ./build_results.html
awk '{print " <tr><td>"$1"</td></tr>"}' ./files-w-gnu-gpl-license-banner.txt >> ./build_results.html
echo " </table>" >> ./build_results.html
echo " </div>" >> ./build_results.html
echo " <br>" >> ./build_results.html
fi
fi
if [ -f ./files-w-suspect-banner.txt ]
then
NB_FILES_IN_ERROR=`wc -l ./files-w-suspect-banner.txt | sed -e "s@ .*@@"`
if [ $NB_FILES_IN_ERROR -ne 0 ]
then
echo " <div class=\"alert alert-warning\">" >> ./build_results.html
if [ $MR_TRIG -eq 1 ]; then echo " <strong>${NB_FILES_IN_ERROR} modified files HAVE a suspect license banner</strong>" >> ./build_results.html; fi
if [ $PU_TRIG -eq 1 ]; then echo " <strong>${NB_FILES_IN_ERROR} files in repository HAVE a suspect license banner</strong>" >> ./build_results.html; fi
echo " </div>" >> ./build_results.html
echo " <button data-toggle=\"collapse\" data-target=\"#oai-license-suspect\">More details on suspect banner files</button>" >> ./build_results.html
echo " <div id=\"oai-license-suspect\" class=\"collapse\">" >> ./build_results.html
echo " <table border = 1>" >> ./build_results.html
echo " <tr>" >> ./build_results.html
echo " <th bgcolor = \"lightcyan\" >Filename</th>" >> ./build_results.html
echo " </tr>" >> ./build_results.html
awk '{print " <tr><td>"$1"</td></tr>"}' ././files-w-suspect-banner.txt >> ./build_results.html
echo " </table>" >> ./build_results.html
echo " </div>" >> ./build_results.html
echo " <br>" >> ./build_results.html
fi
fi fi
fi fi
......
Markdown is supported
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