Skip to content

Commit

Permalink
Added multi-folder support for source files
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Hovy committed Aug 10, 2017
1 parent 35dd559 commit 1ccceee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class FromAssemblerCallGraphBuilder(CallGraphBuilder):

def __init__(self, baseDirs, specialModuleFiles = {}):
assertType(specialModuleFiles, 'specialModuleFiles', dict)

if isinstance(baseDirs, str):
baseDirs = [baseDirs]
assertTypeAll(baseDirs, 'baseDirs', str)

for baseDir in baseDirs:
if not os.path.isdir(baseDir):
raise IOError("Not a directory: " + baseDir);
Expand Down
29 changes: 16 additions & 13 deletions source.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,12 +1533,17 @@ def __removeStringsFromStatement(statement):
return cleanStatement

class SourceFiles(object):
def __init__(self, baseDir, specialModuleFiles={}):
def __init__(self, baseDirs, specialModuleFiles={}):
assertType(specialModuleFiles, 'specialModuleFiles', dict)
if not os.path.isdir(baseDir):
raise IOError("Not a directory: " + baseDir)

self.__baseDir = baseDir
if isinstance(baseDirs, str):
baseDirs = [baseDirs]
assertTypeAll(baseDirs, 'baseDirs', str)
for baseDir in baseDirs:
if not os.path.isdir(baseDir):
raise IOError("Not a directory: " + baseDir);

self.__baseDirs = baseDirs
self.__filesByPath = dict()
self.__filesByModules = dict()
self.setSpecialModuleFiles(specialModuleFiles)
Expand All @@ -1555,9 +1560,6 @@ def setSpecialModuleFiles(self, specialModuleFiles):

self.__filesByModules = dict() # Clear Module Cache

def getBaseDir(self):
return self.__baseDir

def existsSubroutine(self, subroutineName):
assertType(subroutineName, 'subroutineName', SubroutineName)

Expand Down Expand Up @@ -1621,8 +1623,8 @@ def getRelativePath(self, sourceFile):
assertType(sourceFile, 'sourceFile', SourceFile)

path = sourceFile.getPath()
if path.startswith(self.__baseDir):
path = path[len(self.__baseDir):].lstrip('/')
if path.startswith(self.__baseDirs):
path = path[len(self.__baseDirs):].lstrip('/')
return path

def __getModuleFileName(self, moduleName):
Expand All @@ -1632,10 +1634,11 @@ def __getModuleFileName(self, moduleName):
return moduleName + '.f90'

def __findFile(self, fileName):
for root, _, files in os.walk(self.__baseDir):
for name in files:
if name.replace('.F90', '.f90') == fileName.replace('.F90', '.f90'):
return os.path.join(root, name)
for baseDir in self.__baseDirs:
for root, _, files in os.walk(baseDir):
for name in files:
if name.replace('.F90', '.f90') == fileName.replace('.F90', '.f90'):
return os.path.join(root, name)
return None

def clearCache(self):
Expand Down

0 comments on commit 1ccceee

Please sign in to comment.