Warning, /FWCore/ParameterSet/scripts/edmConfigIncludeChecker is written in an unsupported language. File is not indexed.
0001 #!/usr/bin/env python3
0002
0003 # Check needed by Martin Gruenewald for HLT studies
0004 # This isn't intended to be an example for nice coding... ;-)
0005 #
0006 # for questions: benedikt.hegner@cern.ch
0007
0008 from builtins import object
0009 import os.path
0010 import sys
0011 from os import environ
0012 import copy
0013
0014 class IncludeChecker(object):
0015
0016 def __init__(self):
0017 self.includedFileNames = []
0018 self.doneIncludes = []
0019 self.problematicIncludes = []
0020 self.missingIncludes = []
0021 self.traceback = []
0022 # read in the paths used by CMSSW
0023 try:
0024 paths = environ['CMSSW_SEARCH_PATH']
0025 self.localpath = environ['CMSSW_BASE']+'/src'
0026 except KeyError:
0027 raise RuntimeError("The environment variable 'CMSSW_SEARCH_PATH' must be set for include to work")
0028 self.lpaths = paths.split(':')
0029
0030
0031 def formatTraceback(self, traceback):
0032 tb = ""
0033 tr = copy.copy(traceback)
0034 tr.reverse()
0035 for item in tr:
0036 tb += " %s\n" %item
0037 return tb
0038
0039
0040 # return includes defined in a single file
0041 def getIncludesFromFile(self, filename, currentFile):
0042 includes = []
0043 f = None
0044 # look for the file in the CMSSW_SEARCH_PATH
0045 for path in self.lpaths:
0046 path +='/'+filename
0047 if os.path.exists(path):
0048 f=path
0049 break
0050 if f is None:
0051 if os.path.exists(filename):
0052 f = filename
0053 else:
0054 self.missingIncludes.append(filename + "\n Traceback:\n" +self.formatTraceback(self.traceback))
0055 return includes, ""
0056 # here now the part where we check if this include is problematic
0057 # what means problematic here?
0058 # -> there is the right directory in the local area but the file is fetched from another place
0059 parts = filename.split("/")
0060 if len(parts) > 2:
0061 directoryPart = ""
0062 for part in parts[:-1]:
0063 directoryPart += "/" +part
0064 if os.path.exists(self.localpath+directoryPart) and f != self.localpath+"/"+filename:
0065 self.problematicIncludes.append(filename + "\n Traceback:\n" +self.formatTraceback(self.traceback))
0066
0067 # now continue and parse the other includes
0068 theFile = open(f, "r")
0069 self.includedFileNames.append(f)
0070 cStyleCommentsCounter = 0
0071 for line in theFile:
0072 if "/*" in line: cStyleCommentsCounter += 1
0073 if "*/" in line: cStyleCommentsCounter -= 1
0074 if ("include " in line or " from " in line) and not ("#" in line or "//" in line or "/*" in line or "*/" in line or (cStyleCommentsCounter!=0) ):
0075 includeCandidate = line.split('"')[1]
0076 if includeCandidate not in self.doneIncludes:
0077 includes.append(includeCandidate)
0078 theFile.close
0079 return includes, f
0080
0081
0082 # here the real recursive include process
0083 def getIncludesFromList(self, filelist,currentFile):
0084 self.traceback.append(currentFile)
0085 for filename in filelist:
0086 includes, fullPathToFile = self.getIncludesFromFile(filename, currentFile)
0087 self.doneIncludes.append(filename)
0088 self.getIncludesFromList(includes,fullPathToFile)
0089 self.traceback.pop()
0090
0091
0092 def check(self, filename):
0093 includes, fullPathToFile = self.getIncludesFromFile(filename, "toplevel")
0094 self.getIncludesFromList(includes, fullPathToFile)
0095
0096
0097 def printResult(self):
0098 print("Included files:")
0099 print("---------------")
0100 for item in self.includedFileNames:
0101 print(" ", item)
0102
0103 if len(self.problematicIncludes) != 0:
0104 print("\nProblematic files:")
0105 print("------------------")
0106 for item in self.problematicIncludes:
0107 print(" ", item)
0108 else:
0109 print("\nHaven't found any problematic files")
0110
0111 if len(self.missingIncludes) != 0:
0112 print("\nMissing files:")
0113 print("--------------")
0114 for item in self.missingIncludes:
0115 print(" ", item)
0116
0117
0118
0119 ##########################
0120 if __name__ == "__main__":
0121
0122 args = sys.argv
0123 if 2 == len(args):
0124 filename = args[1]
0125 checker = IncludeChecker()
0126 checker.check(filename)
0127 checker.printResult()
0128 else:
0129 print("Please specify a file to check")