Skip to content

Commit bd01414

Browse files
author
Tarun Prabhu
committed
More robust regexes and other code.
1 parent b06ab42 commit bd01414

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

Fortran/gfortran/utils/update-test-config.py

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,26 @@ def __str__(self):
4949

5050
# Checks if the line has a compile annotation.
5151
# FIXME: Add match for target
52-
re_compile = re.compile('[{][ ]*dg-do[ ]*compile[ ]*(.*)[}]')
52+
re_compile = re.compile('[{][ ]*dg-do[ ]*compile[ ]*(.*)[ ]*[}]')
5353

5454
# Checks if the line has a link annotation.
55-
re_link = re.compile('[{][ ]*dg-do[ ]*link[ ]+(.*)[}]')
55+
re_link = re.compile('[{][ ]*dg-do[ ]*link[ ]+(.*)[ ]*[}]')
5656

5757
# Checks if the line has a run annotation or lto-run annotation.
5858
# FIXME: Add match for target
59-
re_run = re.compile('[{][ ]*dg-(lto-)?do[ ]*run[ ]+(.*)[}]')
59+
re_run = re.compile('[{][ ]*dg-(lto-)?do[ ]*run[ ]+(.*)[ ]*[}]')
6060

6161
# Checks if the line has an additional-sources annotation.
62-
re_sources = re.compile('[{][ ]*dg-additional-sources[ ]*["]?([^"])["]?[ ]*[}]')
62+
re_sources = re.compile('[{][ ]*dg-additional-sources[ ]*(.+)[ ]*[}]')
6363

6464
# Checks if the line has a dg-compile-aux-modules annotation.
65-
re_aux_modules = re.compile(
66-
'[{][ ]*dg-compile-aux-modules[ ]*["]?([^"])["]?[}]'
67-
)
65+
re_aux_modules = re.compile('[{][ ]*dg-compile-aux-modules[ ]*(.+)[ ]*[}]')
6866

6967
# Checks if the line has an options or additional-options annotation. The
7068
# option may have an optional target.
7169
re_options = re.compile(
72-
'[{][ ]*dg-(additional-)?options[ ]*["]?([^\"]*)["]?[ ]*[}][ ]*([{][ ]*target[ ]*(.+)?[ ][}])?'
70+
'[{][ ]*dg-(additional-)?options[ ]*(.+)[ ]*[}][ ]*'
71+
'([{][ ]*target[ ]*(.+)?[ ]*[}])?'
7372
)
7473

7574
# Checks if the line has a shouldfail annotation.
@@ -122,6 +121,18 @@ def get_subdirs(gfortran):
122121
subdirs.extend([os.path.join(root, d) for d in dirs])
123122
return subdirs
124123

124+
# Strip any leading and trailing whitespace from the string as well as any
125+
# optional quotes around the string. Then split the string on whitespace and
126+
# return the resulting list.
127+
# str -> list[str]
128+
def qsplit(s):
129+
s = s.strip()
130+
if s.startswith('"'):
131+
s = s[1:]
132+
if s.endswith('"'):
133+
s = s[:-1]
134+
return s.split()
135+
125136
# Try to match the line with the regex. If the line matches, add the match
126137
# object to the MOUT list and return True. Otherwise, leave the MOUT list
127138
# unchanged and return False.
@@ -152,19 +163,18 @@ def main():
152163
for filename in files:
153164
for l in get_lines(filename):
154165
mout = []
155-
if try_match(re_sources, l, mout):
156-
m = mout[0]
157-
d = os.path.dirname(filename)
158-
for src in m[1].split():
159-
dependencies.add(os.path.join(d, src))
160-
print(dependencies)
161-
return 0
166+
if try_match(re_sources, l, mout) or \
167+
try_match(re_aux_modules, l, mout):
168+
for m in mout:
169+
for src in qsplit(m[1]):
170+
dependencies.add(src)
162171

163172
tests = []
164173
for f in files:
165-
if f in dependencies:
166-
continue
167174
filename = os.path.basename(f)
175+
if filename in dependencies:
176+
continue
177+
168178
kind = None
169179
sources = [filename]
170180
options = []
@@ -190,35 +200,28 @@ def main():
190200
elif try_match(re_sources, l, mout) or \
191201
try_match(re_aux_modules, l, mout):
192202
m = mout[0]
193-
sources.extend(m[1].split())
203+
sources.extend(qsplit(m[1]))
194204
elif try_match(re_options, l, mout):
195205
m = mout[0]
196-
options.extend(m[2].split())
206+
options.extend(qsplit(m[2]))
197207
# TODO: Handle the optional target.
208+
209+
fmt = ' WARNING: {} without action annotation: {}'
198210
if kind:
199211
test = Test(kind, sources, options, targets, expect_error)
200212
tests.append(test)
201213
elif len(sources) > 1:
202-
print(
203-
' WARNING: Additional sources without action annotation:',
204-
filename
205-
)
214+
print(fmt.format('Additional sources', filename))
206215
elif len(options) > 1:
207-
print(
208-
' WARNING: Compile options without action annotation:',
209-
filename
210-
)
216+
print(fmt.format('Compile options', filename))
211217
elif expect_error:
212-
print(
213-
' WARNING: Expect error set without action annotation',
214-
filename
215-
)
218+
print(fmt.format('Expect error', filename))
216219
else:
217220
pass
218221
# print(' WARNING: No action annotation:', filename)
219222
for t in tests:
220-
print(str(t))
221-
# print(' ', len(tests))
223+
print(' ', str(t))
224+
print(' ', len(tests))
222225

223226
if __name__ == '__main__':
224227
exit(main())

0 commit comments

Comments
 (0)