Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:32:00

0001 __author__="Aurelija"
0002 __date__ ="$2010-08-06 14.27.51$"
0003 
0004 import os
0005 from Utilities.ReleaseScripts.commentSkipper.commentSkipper import filter as comment
0006 from Utilities.ReleaseScripts.cmsCodeRules.cppFunctionSkipper import filterFiles as function
0007 ordering = ['1', '2', '3', '4', '5', '6']
0008 
0009 # default values for directories
0010 
0011 checkPath = os.getcwd()
0012 picklePath = os.getcwd()
0013 txtPath = os.getcwd()
0014 htmlPath = os.getcwd()
0015 
0016 # exception for directories and files 
0017 
0018 exceptPaths = []
0019 
0020 # --------------------------------------------------------------------------------
0021 # configuration info for each rule ...
0022 
0023 rulesNames = []
0024 Configuration = {}
0025 
0026 # --------------------------------------------------------------------------------
0027 
0028 # configuration for rule 1
0029 
0030 ruleName = '1'
0031 rulesNames.append(ruleName)
0032 Configuration[ruleName] = {}
0033 
0034 Configuration[ruleName]['description'] = 'Search for "using namespace" or "using std::" in header files'
0035 Configuration[ruleName]['filesToMatch'] = ['*.h']
0036 Configuration[ruleName]['exceptPaths'] = ['HeterogeneousCore/CUDAUtilities/interface/cudaCompat.h']
0037 Configuration[ruleName]['skip']  = [comment, function]
0038 Configuration[ruleName]['filter'] = '(\susing|\Ausing)\s+(namespace|std::)' #should be regular expression
0039 Configuration[ruleName]['exceptFilter'] = []
0040 
0041 # --------------------------------------------------------------------------------
0042 
0043 # configuration for rule 2
0044 
0045 ruleName = '2'
0046 rulesNames.append(ruleName)
0047 Configuration[ruleName] = {}
0048 
0049 Configuration[ruleName]['description'] = 'Search for CXXFLAGS flags that are set to -g or -O0 in BuildFile'
0050 Configuration[ruleName]['filesToMatch'] = ['BuildFile', 'BuildFile.xml']
0051 Configuration[ruleName]['exceptPaths'] = []
0052 Configuration[ruleName]['skip']  = [comment]
0053 Configuration[ruleName]['filter'] = '\s(CXXFLAGS|CPPFLAGS)(\+|=|\w|\"|\'|-|\s)*(-g|-O0)(\s|\'|\")' #should be regular expression
0054 Configuration[ruleName]['exceptFilter'] = []
0055 
0056 # --------------------------------------------------------------------------------
0057 
0058 # configuration for rule 3
0059 
0060 ruleName = '3'
0061 rulesNames.append(ruleName)
0062 Configuration[ruleName] = {}
0063 
0064 Configuration[ruleName]['description'] = 'Search for "catch(...)" statements in *.cc, *.cxx files'
0065 Configuration[ruleName]['filesToMatch'] = ['*.cc', '*.cxx']
0066 Configuration[ruleName]['exceptPaths'] = ['FWCore/*', 'EventFilter/*', '*/*/test/*', '*/*/bin/*']
0067 Configuration[ruleName]['skip']  = [comment]
0068 Configuration[ruleName]['filter'] = 'catch\s*\(\s*\.\.\.\s*\)' #should be regular expression
0069 Configuration[ruleName]['exceptFilter'] = []
0070 # --------------------------------------------------------------------------------
0071 
0072 # configuration for rule 4
0073 
0074 ruleName = '4'
0075 rulesNames.append(ruleName)
0076 Configuration[ruleName] = {}
0077 
0078 Configuration[ruleName]['description'] = 'Search for "copyright" declaration in *.c, *.cc, *.cxx, *.h files'
0079 Configuration[ruleName]['filesToMatch'] = ['*.h', '*.c', '*.cc', '*.cxx']
0080 Configuration[ruleName]['exceptPaths'] = [
0081                                            'FWCore/Utilities/interface/math_private.h',
0082                                            'FWCore/Utilities/interface/md5.h',
0083                                            'FWCore/Utilities/interface/tinyxml.h',
0084                                            'FWCore/Utilities/src/md5.c',
0085                                            'FWCore/Utilities/src/tinyxml.cc',
0086                                            'FWCore/Utilities/src/tinyxmlerror.cc',
0087                                            'FWCore/Utilities/src/tinyxmlparser.cc',
0088                                            'DataFormats/Common/interface/Trie.h',
0089                                            'DataFormats/Math/interface/sse_mathfun.h',
0090                                            'EventFilter/Processor/src/procUtils.cc',
0091                        'CondCore/ORA/src/GenMD5.cc',
0092                                            'PhysicsTools/JetMCUtils/interface/combination.h',
0093                                          ] #could be file name, dir, fileName:line. But path should be only from that directory in which we are searching
0094 Configuration[ruleName]['skip']  = []
0095 Configuration[ruleName]['filter'] = '(\A|\W)(c|C)(o|O)(p|P)(y|Y)(r|R)(i|I)(g|G)(h|H)(t|T)\W(\+|=|\w|\"|\'|-|\s)*(\((c|C)\)|\d{4})' #should be regular expression
0096 Configuration[ruleName]['exceptFilter'] = []
0097 
0098 # --------------------------------------------------------------------------------
0099 
0100 # configuration for rule 5
0101 
0102 ruleName = '5'
0103 rulesNames.append(ruleName)
0104 Configuration[ruleName] = {}
0105 
0106 Configuration[ruleName]['description'] = 'Search for "pragma" statement in *.c, *.cc, *.cxx, *.h files'
0107 Configuration[ruleName]['filesToMatch'] = ['*.h', '*.c', '*.cc', '*.cxx']
0108 Configuration[ruleName]['exceptPaths'] = ['*/*LinkDef.h',
0109                                           'FWCore/Utilities/interface/tinyxml.h',
0110                                           'Utilities/StorageFactory/src/LocalFileSystem.cc:.*:#\s*pragma\s+GCC\s+diagnostic\s+ignored',
0111                                           'RecoVertex/BeamSpotProducer/test/scripts/BSVectorDict.h',
0112                                           'FWCore/Utilities/*/*:.*:#\s*pragma\s+GCC\s+visibility\s+(push\\(default\\)|pop)\s*$',
0113                                           'CondFormats/JetMETObjects/interface/Linkdef.h',
0114                                           'DataFormats/GeometryVector/interface/Basic3DVectorLD.h',
0115                                           'DataFormats/Scalers/interface/ScalersRaw.h',
0116                                           'FWCore/MessageService/plugins/Module.cc',
0117                                           'GeneratorInterface/RivetInterface/plugins/tinyxml.h',
0118                                           'PerfTools/Callgrind/plugins/CallgrindAnalyzer.cc',
0119                                           'PerfTools/Callgrind/src/ProfilerService.cc',
0120                                           'RecoTracker/TkDetLayers/src/BladeShapeBuilderFromDet.h',
0121                                           'RecoTracker/TkDetLayers/src/BoundDiskSector.h',
0122                                           'RecoTracker/TkDetLayers/src/CompatibleDetToGroupAdder.h',
0123                                           'RecoTracker/TkDetLayers/src/CompositeTECPetal.h',
0124                                           'RecoTracker/TkDetLayers/src/CompositeTECWedge.h',
0125                                           'RecoTracker/TkDetLayers/src/DetGroupMerger.h',
0126                                           'RecoTracker/TkDetLayers/src/DiskSectorBounds.h',
0127                                           'RecoTracker/TkDetLayers/src/ForwardDiskSectorBuilderFromDet.h',
0128                                           'RecoTracker/TkDetLayers/src/ForwardDiskSectorBuilderFromWedges.h',
0129                                           'RecoTracker/TkDetLayers/src/GlobalDetRodRangeZPhi.h',
0130                                           'RecoTracker/TkDetLayers/src/LayerCrossingSide.h',
0131                                           'RecoTracker/TkDetLayers/src/PixelBarrelLayerBuilder.h',
0132                                           'RecoTracker/TkDetLayers/src/PixelBarrelLayer.h',
0133                                           'RecoTracker/TkDetLayers/src/PixelBladeBuilder.h',
0134                                           'RecoTracker/TkDetLayers/src/PixelBlade.h',
0135                                           'RecoTracker/TkDetLayers/src/PixelForwardLayerBuilder.h',
0136                                           'RecoTracker/TkDetLayers/src/PixelForwardLayer.h',
0137                                           'RecoTracker/TkDetLayers/src/PixelForwardLayerPhase1.h',
0138                                           'RecoTracker/TkDetLayers/src/PixelRodBuilder.h',
0139                                           'RecoTracker/TkDetLayers/src/PixelRod.h',
0140                                           'RecoTracker/TkDetLayers/src/SimpleTECWedge.h',
0141                                           'RecoTracker/TkDetLayers/src/SubLayerCrossings.h',
0142                                           'RecoTracker/TkDetLayers/src/TECLayerBuilder.h',
0143                                           'RecoTracker/TkDetLayers/src/TECLayer.h',
0144                                           'RecoTracker/TkDetLayers/src/TECPetalBuilder.h',
0145                                           'RecoTracker/TkDetLayers/src/TECPetal.h',
0146                                           'RecoTracker/TkDetLayers/src/TECWedgeBuilder.h',
0147                                           'RecoTracker/TkDetLayers/src/TECWedge.h',
0148                                           'RecoTracker/TkDetLayers/src/TIBLayerBuilder.h',
0149                                           'RecoTracker/TkDetLayers/src/TIBLayer.h',
0150                                           'RecoTracker/TkDetLayers/src/TIBRingBuilder.h',
0151                                           'RecoTracker/TkDetLayers/src/TIBRing.h',
0152                                           'RecoTracker/TkDetLayers/src/TIDLayerBuilder.h',
0153                                           'RecoTracker/TkDetLayers/src/TIDLayer.h',
0154                                           'RecoTracker/TkDetLayers/src/TIDRingBuilder.h',
0155                                           'RecoTracker/TkDetLayers/src/TkDetUtil.h',
0156                                           'RecoTracker/TkDetLayers/src/TkGeomDetCompatibilityChecker.h',
0157                                           'RecoTracker/TkDetLayers/src/TOBLayerBuilder.h',
0158                                           'RecoTracker/TkDetLayers/src/TOBLayer.h',
0159                                           'RecoTracker/TkDetLayers/src/TOBRodBuilder.h',
0160                                           'RecoTracker/TkDetLayers/src/TOBRod.h',
0161                                           'RecoTracker/TkDetLayers/src/TIDRing.h',
0162                                          ]#could be file name, dir, fileName:line. Path should be only from that directory in which we are searching
0163 Configuration[ruleName]['skip']  = [comment]
0164 Configuration[ruleName]['filter'] = '#\s*pragma\s' #should be regular expression
0165 Configuration[ruleName]['exceptFilter'] = []
0166 # --------------------------------------------------------------------------------
0167 # configuration for rule 6
0168 
0169 ruleName = '6'
0170 rulesNames.append(ruleName)
0171 Configuration[ruleName] = {}
0172 
0173 Configuration[ruleName]['description'] = 'Search for "flags" statements in BuildFile'
0174 Configuration[ruleName]['filesToMatch'] = ['BuildFile', 'BuildFile.xml']
0175 Configuration[ruleName]['exceptPaths'] = ['Utilities/RFIOAdaptor/*BuildFile.xml:.*:NO_LIB_CHECKING=',  #could be file name, dir, fileName:line, fileName:lineNORegEx:LineRegEx:. Path should be only from that directory in  which we are searching
0176                       'Utilities/RFIOAdaptor/*BuildFile.xml:.*:_FILE_OFFSET_BITS=',
0177                       'Utilities/DCacheAdaptor/*BuildFile.xml:.*:_FILE_OFFSET_BITS=',
0178                       'Utilities/XrdAdaptor/*BuildFile.xml:.*:_FILE_OFFSET_BITS=',
0179                       'Utilities/StorageFactory/*BuildFile.xml:.*:_FILE_OFFSET_BITS=',
0180                                           'Utilities/LStoreAdaptor/BuildFile.xml:.*:_FILE_OFFSET_BITS=',
0181                       'DQM/CSCMonitorModule/*BuildFile.xml:.*:="DQMGLOBAL"',
0182                       'DQMServices/Core/*BuildFile.xml:.*:="-DWITHOUT_CMS_FRAMEWORK=0"',
0183                                           'L1Trigger/CSCTrackFinder/BuildFile.xml:.*:ADD_SUBDIR=',
0184                                           'MagneticField/Interpolation/BuildFile.xml:.*:="-Wno-format"',
0185                                           'MagneticField/Interpolation/test/BuildFile.xml:.*:="-Wno-format"',
0186                                           'GeneratorInterface/Pythia6Interface/plugins/BuildFile.xml:.*:LDFLAGS="\$\(PYTHIA6_BASE\)/lib/pydata.o"',
0187                      ]
0188 Configuration[ruleName]['skip']  = [comment]
0189 Configuration[ruleName]['filter'] = '<\s*(f|F)(l|L)(a|A)(g|G)(s|S)\s+' #should be regular expression
0190 Configuration[ruleName]['exceptFilter'] = ['EDM_PLUGIN','RIVET_PLUGIN', 'GENREFLEX_ARGS', 'TEST_RUNNER_ARGS', 'INSTALL_SCRIPTS', 'NO_TESTRUN', 'NO_EXPORT']
0191 # --------------------------------------------------------------------------------
0192 
0193 rulesDescription  = "Rule number    Description\n"
0194 rulesDescription += "----------------------------------------------------------------------------------------\n"
0195 for key, value in Configuration.items():
0196     rulesDescription += "     %s         %s\n" %(key, value['description'])
0197 
0198 # --------------------------------------------------------------------------------
0199 helpMsg  = "-----------------------------------------------------------HELP-----------------------------------------------------------\n"
0200 helpMsg += "cmsCodeRulesChecker.py [-h] [-html] [-s [DIRECTORY]] [-S [DIRECTORY]] [-p] [-r ruleNumber[,ruleNumber[, ...]]] [-d DIRECTORY]\n\n"
0201 helpMsg += "-r     Specifies rule or rules to be checked. After this parameter should\n       be at least one rule given.\n"
0202 helpMsg += "-d     Specifies that rules should be checked in DIRECTORY. Default \n       directory - current directory\n"
0203 helpMsg += "-S     Specifies to save results in python pickle files. Directory specifies\n       where to store these files. Default directory - current directory\n"
0204 helpMsg += "-s     Specifies to save results in .txt files. Directory specifies where to\n       store these files. Default directory - current directory\n"
0205 helpMsg += "-p     Specifies to print results into a screen\n"
0206 helpMsg += "-h     Prints help message\n"
0207 helpMsg += "-html  Reads pickle files and creates cmsCRPage.html\n\n"
0208 helpMsg += "By default cmsCodeRulesChecker.py checks all rules in current directory and prints results into screen.\n\n"
0209 helpMsg += rulesDescription