Fortran.py (scons-4.2.0) | : | Fortran.py (SCons-4.3.0) | ||
---|---|---|---|---|
skipping to change at line 30 | skipping to change at line 30 | |||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |||
"""Dependency scanner for Fortran code.""" | """Dependency scanner for Fortran code.""" | |||
import re | import re | |||
import SCons.Node | import SCons.Node | |||
import SCons.Node.FS | import SCons.Node.FS | |||
import SCons.Scanner | ||||
import SCons.Util | import SCons.Util | |||
import SCons.Warnings | import SCons.Warnings | |||
from . import Classic, Current, FindPathDirs | ||||
class F90Scanner(SCons.Scanner.Classic): | class F90Scanner(Classic): | |||
""" | """ | |||
A Classic Scanner subclass for Fortran source files which takes | A Classic Scanner subclass for Fortran source files which takes | |||
into account both USE and INCLUDE statements. This scanner will | into account both USE and INCLUDE statements. This scanner will | |||
work for both F77 and F90 (and beyond) compilers. | work for both F77 and F90 (and beyond) compilers. | |||
Currently, this scanner assumes that the include files do not contain | Currently, this scanner assumes that the include files do not contain | |||
USE statements. To enable the ability to deal with USE statements | USE statements. To enable the ability to deal with USE statements | |||
in include files, add logic right after the module names are found | in include files, add logic right after the module names are found | |||
to loop over each include file, search for and locate each USE | to loop over each include file, search for and locate each USE | |||
statement, and append each module name to the list of dependencies. | statement, and append each module name to the list of dependencies. | |||
Caching the search results in a common dictionary somewhere so that | Caching the search results in a common dictionary somewhere so that | |||
the same include file is not searched multiple times would be a | the same include file is not searched multiple times would be a | |||
smart thing to do. | smart thing to do. | |||
""" | """ | |||
def __init__(self, name, suffixes, path_variable, | def __init__(self, name, suffixes, path_variable, | |||
use_regex, incl_regex, def_regex, *args, **kw): | use_regex, incl_regex, def_regex, *args, **kwargs): | |||
self.cre_use = re.compile(use_regex, re.M) | self.cre_use = re.compile(use_regex, re.M) | |||
self.cre_incl = re.compile(incl_regex, re.M) | self.cre_incl = re.compile(incl_regex, re.M) | |||
self.cre_def = re.compile(def_regex, re.M) | self.cre_def = re.compile(def_regex, re.M) | |||
def _scan(node, env, path, self=self): | def _scan(node, env, path, self=self): | |||
node = node.rfile() | node = node.rfile() | |||
if not node.exists(): | if not node.exists(): | |||
return [] | return [] | |||
return self.scan(node, env, path) | return self.scan(node, env, path) | |||
kw['function'] = _scan | kwargs['function'] = _scan | |||
kw['path_function'] = SCons.Scanner.FindPathDirs(path_variable) | kwargs['path_function'] = FindPathDirs(path_variable) | |||
kw['recursive'] = 1 | kwargs['recursive'] = 1 | |||
kw['skeys'] = suffixes | kwargs['skeys'] = suffixes | |||
kw['name'] = name | kwargs['name'] = name | |||
SCons.Scanner.Current.__init__(self, *args, **kw) | # bypasses the parent Classic initializer | |||
Current.__init__(self, *args, **kwargs) | ||||
def scan(self, node, env, path=()): | def scan(self, node, env, path=()): | |||
# cache the includes list in node so we only scan it once: | # cache the includes list in node so we only scan it once: | |||
if node.includes is not None: | if node.includes is not None: | |||
mods_and_includes = node.includes | mods_and_includes = node.includes | |||
else: | else: | |||
# retrieve all included filenames | # retrieve all included filenames | |||
includes = self.cre_incl.findall(node.get_text_contents()) | includes = self.cre_incl.findall(node.get_text_contents()) | |||
# retrieve all USE'd module names | # retrieve all USE'd module names | |||
End of changes. 6 change blocks. | ||||
9 lines changed or deleted | 10 lines changed or added |