Commit ceaa8d30 authored by Hanchuan Wu's avatar Hanchuan Wu
Browse files

[bin][util][moduleinfo] Rename script of dune-module information

parent 7ea7a7c1
import os
from common import runCommand
from common import callFromPath
from util.common import runCommand
from util.common import callFromPath
# extract information (for the given keys) from a module file
def extractModuleInfos(moduleFile, keys):
results = {}
with open(moduleFile, 'r') as modFile:
......@@ -21,48 +21,70 @@ def extractModuleInfos(moduleFile, keys):
return results
# get info file of a module
def getModuleFile(modulePath):
modFile = os.path.join(modulePath, 'dune.module')
if not os.path.exists(modFile):
raise RuntimeError("Could not find module file")
return modFile
# retrieve single information from a module
def getModuleInfo(modulePath, key):
return extractModuleInfos(getModuleFile(modulePath), [key])[key]
# get the dependencies of a dune module located in the given directory
def getDependencies(modulePath, verbose=False):
def getDependencies(modulePath, verbose=False, includeSelf=False):
modName = getModuleInfo(modulePath, 'Module')
parentPath = os.path.join(modulePath, '../')
duneControlPath = os.path.join(parentPath, 'dune-common/bin/dunecontrol')
if not os.path.exists(duneControlPath):
raise RuntimeError('Could not find dunecontrol, expected it to be in {}'.format(duneControlPath))
raise RuntimeError(
'Could not find dunecontrol, expected it to be in {}'
.format(duneControlPath)
)
run = callFromPath(parentPath)(runCommand)
for line in run('./dune-common/bin/dunecontrol --module={}'.format(modName)).split('\n'):
dcOutput = callFromPath(parentPath)(runCommand)(
'./dune-common/bin/dunecontrol --module={}'.format(modName)
)
if not dcOutput:
raise RuntimeError("Error: call to dunecontrol failed.")
for line in dcOutput.split('\n'):
if "going to build" in line:
line = line.replace('going to build', '').replace('---', '').replace('done', '')
line = line.replace('going to build', '').strip('-')
line = line.strip('\n').strip()
line = line.split(' ')
deps = line
# Now we look for the folders with the modules
if not includeSelf:
deps.remove(modName)
if verbose:
print("Determined the following dependencies: " + ", ".join(deps))
print(" -- Determined the following dependencies: " + ", ".join(deps))
print(" -- Searching the respective directories...")
result = []
for dir in [d for d in os.listdir(parentPath) if os.path.isdir(os.path.join(parentPath, d))]:
try: depModName = getModuleInfo(os.path.join(parentPath, dir), 'Module')
except: print('--- Note: skipping folder "' + dir + '" as it could not be identifed as dune module')
parentFiles = [os.path.join(parentPath, d) for d in os.listdir(parentPath)]
for path in filter(os.path.isdir, parentFiles):
try:
depModName = getModuleInfo(path, 'Module')
except Exception:
if verbose:
print(f" --- skipping folder '{path}' "
"as it could not be identifed as dune module")
else:
if verbose:
print(" --- visited module '{}'".format(depModName))
if depModName in deps:
result.append({'name': depModName, 'folder': dir})
result.append({
'name': depModName,
'folder': os.path.basename(path),
'path': path
})
if len(result) != len(deps):
raise RuntimeError("Could not find the folders of all dependencies")
elif verbose:
print("Found all module folders of the dependencies.")
print(" -- Found all module folders of the dependencies.")
return result
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment