MCPcopy Create free account
hub / github.com/Kitware/VTK / ParseCMakeFile

Method ParseCMakeFile

Utilities/Maintenance/VTKTestsByLanguage.py:75–108  ·  view source on GitHub ↗

Parse the CMakeLists.txt file as best we can by eliminating spurious lines and return two strings that can be searched for programs/scripts. The approach here is to just partition the file into two strings, one containing comments and the other the non-

(self, dir)

Source from the content-addressed store, hash-verified

73 'python': 'Python'}
74
75 def ParseCMakeFile(self, dir):
76 '''
77 Parse the CMakeLists.txt file as best we can by eliminating spurious
78 lines and return two strings that can be searched for
79 programs/scripts.
80
81 The approach here is to just partition the file into two strings,
82 one containing comments and the other the non-comment lines.
83
84 :param: dir - the directory
85 :return: a pair of strings containing the enabled programs/scripts and
86 commented out programs/scripts.
87 '''
88 filePath = os.path.abspath(os.path.join(dir, 'CMakeLists.txt'))
89 if not os.path.exists(filePath):
90 return None, None
91 fh = open(filePath, 'rb')
92 nonComments = []
93 comments = []
94 for line in fh:
95 # convert bytes to a string.
96 line = line.strip().decode()
97 if not line:
98 continue
99 if line[0] == '#':
100 if len(line) > 1:
101 comments.append(line[1:])
102 continue
103 if line:
104 nonComments.append(line)
105 # Remove duplicates.
106 nonComments = set(nonComments)
107 comments = set(comments)
108 return '\n'.join(nonComments), '\n'.join(comments)
109# return '\n'.join(map(str, nonComments)), '\n'.join(map(str, comments))
110
111 def AddValue(self, fn, key, v):

Callers 1

WalkPathsMethod · 0.95

Calls 4

existsMethod · 0.80
setFunction · 0.50
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected