Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}
Expand Down
141 changes: 141 additions & 0 deletions ci/clang-tidy-report-script.py
Original file line number Diff line number Diff line change
@@ -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()

6 changes: 3 additions & 3 deletions core/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down