Skip to content

Commit e779ab7

Browse files
committed
fix bug on module-dependency creation with preprocessing conditionals
1 parent 770f887 commit e779ab7

6 files changed

+29
-28
lines changed

src/main/python/fobis/ParsedFile.py

+25-24
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,42 @@ def sort_dependencies(self):
297297
self.pfile_dep_all.sort(key=operator.attrgetter('order'), reverse=True)
298298
return
299299

300-
def parse(self, inc, preprocessor='cpp'):
300+
def parse(self, inc, preprocessor='cpp', preproc=''):
301301
"""
302302
Parse the file creating its the dependencies list and the list of modules names that self eventually contains.
303303
304304
Parameters
305305
----------
306306
inc : list
307307
list of extensions of included files
308+
preprocessor : str
309+
preprocessor name
310+
preproc : str
311+
preprocessor flags
308312
"""
309313
self.module_names = []
310314
self.submodule_names = []
311315
self.dependencies = []
312-
ffile = openReader(self.name)
313-
for line in ffile:
316+
317+
if self.extension in ['.INC', '.F', '.FOR', '.FPP', '.F77', '.F90', '.F95', '.F03', '.F08']:
318+
preprocessor_exist = False
319+
for path in os.environ["PATH"].split(os.pathsep):
320+
preprocessor_exist = os.path.exists(os.path.join(path, preprocessor))
321+
if preprocessor_exist:
322+
break
323+
if preprocessor_exist:
324+
if preprocessor == 'cpp':
325+
preprocessor += ' -C -w '
326+
elif preprocessor == 'fpp':
327+
preprocessor += ' -w '
328+
source = str(check_output(preprocessor + ' ' + preproc + ' ' + self.name, shell=True, stderr=STDOUT, encoding='UTF-8'))
329+
source = source.replace('\\n', '\n')
330+
else:
331+
source = str(openReader(self.name).read())
332+
else:
333+
source = str(openReader(self.name).read())
334+
335+
for line in source.split('\n'):
314336
matching = re.match(__regex_program__, line)
315337
if matching:
316338
self.program = True
@@ -335,30 +357,9 @@ def parse(self, inc, preprocessor='cpp'):
335357
if not re.match(__regex_mpifh__, line):
336358
dep = Dependency(dtype="include", name=matching.group('name'))
337359
self.dependencies.append(dep)
338-
ffile.close()
339360

340361
if self.module:
341362
self.doctest = Doctest()
342-
343-
if self.extension in ['.INC', '.F', '.FOR', '.FPP', '.F77', '.F90', '.F95', '.F03', '.F08']:
344-
preprocessor_exist = False
345-
for path in os.environ["PATH"].split(os.pathsep):
346-
preprocessor_exist = os.path.exists(os.path.join(path, preprocessor))
347-
if preprocessor_exist:
348-
break
349-
if preprocessor_exist:
350-
if preprocessor == 'cpp':
351-
preprocessor += ' -C -w '
352-
elif preprocessor == 'fpp':
353-
preprocessor += ' -w '
354-
source = str(check_output(preprocessor + self.name, shell=True, stderr=STDOUT, encoding='UTF-8'))
355-
source = source.replace('\\n', '\n')
356-
else:
357-
source = str(openReader(self.name).read())
358-
359-
else:
360-
source = str(openReader(self.name).read())
361-
362363
self.doctest.parse(source=source)
363364
self.doctest.make_volatile_programs()
364365

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/main/python/fobis/fobis.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ def parse_files(configuration, src_dir=None, is_doctest=False):
258258
all(exc not in os.path.dirname(filename) for exc in configuration.cliargs.exclude_dirs)):
259259
pfile = ParsedFile(name=os.path.join(src_dir, filename), is_doctest=is_doctest)
260260
if is_doctest:
261-
pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor)
261+
pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor, preproc=configuration.cliargs.preproc)
262262
else:
263-
pfile.parse(inc=configuration.cliargs.inc)
263+
pfile.parse(inc=configuration.cliargs.inc, preproc=configuration.cliargs.preproc)
264264
pfiles.append(pfile)
265265
else:
266266
for root, _, files in os.walk(src_dir):
@@ -271,9 +271,9 @@ def parse_files(configuration, src_dir=None, is_doctest=False):
271271
filen = os.path.join(root, filename)
272272
pfile = ParsedFile(name=filen, is_doctest=is_doctest)
273273
if is_doctest:
274-
pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor)
274+
pfile.parse(inc=configuration.cliargs.inc, preprocessor=configuration.cliargs.doctests_preprocessor, preproc=configuration.cliargs.preproc)
275275
else:
276-
pfile.parse(inc=configuration.cliargs.inc)
276+
pfile.parse(inc=configuration.cliargs.inc, preproc=configuration.cliargs.preproc)
277277
pfiles.append(pfile)
278278
return pfiles
279279

0 commit comments

Comments
 (0)