diff --git a/Jenkinsfile b/Jenkinsfile index 3d806100..02d5032a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -59,8 +59,10 @@ pipeline echo "run static analysis" sh 'cmake . -Bbuilddir-static -G"Unix Makefiles" -DPROJECT_CONFIG_PATH=ci/testing_config -DENABLE_STATIC_CHECKS=1 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON' sh 'cmake --build builddir-static 2> builddir-static/clang-report.txt' - sh 'if [ ! -s builddir-static/clang-report.txt ]; then echo "Good, all tests have been passed w/o findings" > builddir-static/clang-report.txt; fi;' + sh 'if [ ! -s builddir-static/clang-report.txt ]; then echo "Good, all tests have been passed w/o findings" > builddir-static/clang-final-report.txt; fi;' sh 'cat builddir-static/clang-report.txt | python ci/thirdparty/clangTidyToJunit/clang-tidy-to-junit.py `pwd` > builddir-static/clang-report.xml' + sh 'cat ./core/.clang-tidy >> builddir-static/clang-final-report.txt' + sh 'python ./ci/clang-tidy-report-script.py ./builddir-static/clang-report.txt ./core/.clang-tidy >> ./builddir-static/clang-final-report.txt' } } } diff --git a/ci/clang-tidy-report-script.py b/ci/clang-tidy-report-script.py new file mode 100644 index 00000000..90bf327e --- /dev/null +++ b/ci/clang-tidy-report-script.py @@ -0,0 +1,141 @@ +import re +from io import StringIO +import sys + + + +############### read specific string from file +def readClangConfig(): + stringLineToMatch = "LineThreshold" + + stringBranchToMatch = "BranchThreshold" + + stringNestingToMatch = "NestingThreshold" + + stringValueToMatch = " value:" + + global resultL + global resultB + global resultN + #### here we gave the function the third position of sys arguments when you should put the file path of .clang-tidy cofig. + with open(sys.argv[2],"r") as f: + + while True: + line1 = f.readline() + line2 = f.readline() + + if stringLineToMatch in line1 and stringValueToMatch in line2: + elementsLineThres= line2.split(" value: '", 1) + matchedEndLine = "'" + if matchedEndLine in line2: + new2 = elementsLineThres[1].split(matchedEndLine,1) + resultL=new2[0].strip() + # print(resultL) + + if stringBranchToMatch in line1 and stringValueToMatch in line2: + elementsBranchThres= line2.split(" value: '", 1) + matchedEndBranch = "'" + if matchedEndBranch in line2: + new2 = elementsBranchThres[1].split(matchedEndBranch,1) + resultB=new2[0].strip() + #print(resultB) + + if stringNestingToMatch in line1 and stringValueToMatch in line2: + elementsNestingThres= line2.split(" value: '", 1) + matchedEndNesting = "'" + if matchedEndNesting in line2: + new2 = elementsNestingThres[1].split(matchedEndNesting,1) + resultN=new2[0].strip() + #print(resultN) + if not line2: break + + +################## read from file the line then find the specific string of warning functions to write all the result line to another file +def readFileAndFindWarningFunctions(): + + ##get the name of the warning functions by this string + WarningFunctions = "warning: function" + matchedLineF = '' + ##get the notes of the warning functions by this string + NoteOfTheFunctionsThresholds ="note:" + + result = [] + result2 = [] + result3 = [] + result4 = [] + + listResult = [] + + matchedline='' + matchednesting='' + matchedbranch='' + + ffinal ='' + flag2 =False + i = 1 + re = '' + + ##### this to call the method which get the specific string from .clang-tidy config + readClangConfig() + ##### then apply it here global variables in the below string for the final report + listResult.append('--------------------------------------------------------------------------------' + +'\nClang Tidy Reporting for Kiso functions.. \n' + +'The functions exceed recommended size/complexity thresholds [readability-function-size]:\n' + + 'Thresholds: LineThresholods > '+resultL+' | BranchThresholds > '+resultB+' | NestingThresholds > '+resultN+'\n' + + '--------------------------------------------------------------------------------') + + #### here when you run your python script file path and with the .txt file path + #### this sys.argv[1] give you the .txt file path from the command you will run with the python script file path + with open(sys.argv[1],"r") as f: + for line in f: + if WarningFunctions in line: + matchedLineF = line + elementsNameOfFunctions= matchedLineF.split('warning: ', 1) + + if len(WarningFunctions)<2: + print("there are no warning functions") + else: + new = elementsNameOfFunctions[1].split('exceeds',1) + result=new[0].strip() + re = 'Function ' + str(i) + listResult.append('\n') + listResult.append(re) + listResult.append('------------') + listResult.append(result+':') + flag2 =True + i = i+1 + elif NoteOfTheFunctionsThresholds in line: + matchedLineF = line + elementsNameOfFunctions = matchedLineF.split('note:',1) + if len(NoteOfTheFunctionsThresholds)<2: + listResult.append("there are no notes for this warning function exceed recommended size/complexity thresholds [readability-function-size].") + #print("there are no notes for warning functions") + else: + matchedline ='including whitespace and comments (threshold '+resultL+')' + matchednesting ='starts here (threshold '+resultN+')' + matchedbranch=' (threshold '+resultB+')' + if matchedline in matchedLineF: + new2 = elementsNameOfFunctions[1].split(matchedline,1) + result2=new2[0].strip() + listResult.append(result2) + + if matchedbranch in matchedLineF: + new4 = elementsNameOfFunctions[1].split(matchedbranch,1) + result4=new4[0].strip() + listResult.append(result4) + + if matchednesting in matchedLineF and flag2== True: + new3 = elementsNameOfFunctions[1].split(matchednesting,1) + result3=new3[0].strip() + listResult.append(result3) + flag2= False + + + ffinal = '\n'.join(listResult) + print(ffinal+'\n') + + +#### here it will call the function will do the final report + +readFileAndFindWarningFunctions() + diff --git a/core/.clang-tidy b/core/.clang-tidy index 4e69c612..8c1da9dd 100644 --- a/core/.clang-tidy +++ b/core/.clang-tidy @@ -3,11 +3,11 @@ Checks: '-*, readability-*, clang-analyzer-*, misc-*' CheckOptions: - key: readability-function-size.LineThreshold - value: '120' + value: '20' - key: readability-function-size.BranchThreshold - value: '15' + value: '5' - key: readability-function-size.NestingThreshold - value: '7' + value: '3' - key: readability-function-size.ParameterThreshold value: '8' - key: readability-function-size.StatementThreshold