(self, target)
Find all module and submodule made available in a Fortran code file.
Find all module and submodule made available in a Fortran code file.
Find all module and submodule made available in a Fortran code file .
def scan_fortran_module_outputs(self, target):
        """
        Find all module and submodule made available in a Fortran code file.
        """
        if self.use_dyndeps_for_fortran():
            return
        compiler = None
        # TODO other compilers
        for lang, c in self.environment.coredata.compilers.host.items():
            if lang == 'fortran':
                compiler = c
                break
        if compiler is None:
            self.fortran_deps[target.get_basename()] = {}
            return

        modre = re.compile(FORTRAN_MODULE_PAT, re.IGNORECASE)
        submodre = re.compile(FORTRAN_SUBMOD_PAT, re.IGNORECASE)
        module_files = {}
        submodule_files = {}
        for s in target.get_sources():
            # FIXME, does not work for Fortran sources generated by
            # custom_target() and generator() as those are run after
            # the configuration (configure_file() is OK)
            if not compiler.can_compile(s):
                continue
            filename = s.absolute_path(self.environment.get_source_dir(),
                                       self.environment.get_build_dir())
            # Fortran keywords must be ASCII.
            with open(filename, encoding='ascii', errors='ignore') as f:
                for line in f:
                    modmatch = modre.match(line)
                    if modmatch is not None:
                        modname = modmatch.group(1).lower()
                        if modname in module_files:
                            raise InvalidArguments(
                                f'Namespace collision: module {modname} defined in '
                                'two files {module_files[modname]} and {s}.')
                        module_files[modname] = s
                    else:
                        submodmatch = submodre.match(line)
                        if submodmatch is not None:
                            # '_' is arbitrarily used to distinguish submod from mod.
                            parents = submodmatch.group(1).lower().split(':')
                            submodname = parents[0] + '_' + submodmatch.group(2).lower()

                            if submodname in submodule_files:
                                raise InvalidArguments(
                                    'Namespace collision: submodule {submodname} defined in '
                                    'two files {submodule_files[submodname]} and {s}.')
                            submodule_files[submodname] = s

        self.fortran_deps[target.get_basename()] = {**module_files, **submodule_files}
def scan_fortran_module_outputs ( self , target ) : if self . use_dyndeps_for_fortran ( ) : return compiler = None # TODO other compilers for lang , c in self . environment . coredata . compilers . host . items ( ) : if lang == 'fortran' : compiler = c break if compiler is None : self . fortran_deps [ target . get_basename ( ) ] = { } return modre = re . compile ( FORTRAN_MODULE_PAT , re . IGNORECASE ) submodre = re . compile ( FORTRAN_SUBMOD_PAT , re . IGNORECASE ) module_files = { } submodule_files = { } for s in target . get_sources ( ) : # FIXME, does not work for Fortran sources generated by # custom_target() and generator() as those are run after # the configuration (configure_file() is OK) if not compiler . can_compile ( s ) : continue filename = s . absolute_path ( self . environment . get_source_dir ( ) , self . environment . get_build_dir ( ) ) # Fortran keywords must be ASCII. with open ( filename , encoding = 'ascii' , errors = 'ignore' ) as f : for line in f : modmatch = modre . match ( line ) if modmatch is not None : modname = modmatch . group ( 1 ) . lower ( ) if modname in module_files : raise InvalidArguments ( f'Namespace collision: module {modname} defined in ' 'two files {module_files[modname]} and {s}.' ) module_files [ modname ] = s else : submodmatch = submodre . match ( line ) if submodmatch is not None : # '_' is arbitrarily used to distinguish submod from mod. parents = submodmatch . group ( 1 ) . lower ( ) . split ( ':' ) submodname = parents [ 0 ] + '_' + submodmatch . group ( 2 ) . lower ( ) if submodname in submodule_files : raise InvalidArguments ( 'Namespace collision: submodule {submodname} defined in ' 'two files {submodule_files[submodname]} and {s}.' ) submodule_files [ submodname ] = s self . fortran_deps [ target . get_basename ( ) ] = { * * module_files , * * submodule_files }