Commit 1d55f716 authored by Tristan Gingold's avatar Tristan Gingold

dep_file.py: split rels set into requires/provides.

parent f7cfce26
...@@ -146,27 +146,28 @@ class DepFile(File): ...@@ -146,27 +146,28 @@ class DepFile(File):
def __init__(self, path, module): def __init__(self, path, module):
assert isinstance(path, six.string_types) assert isinstance(path, six.string_types)
File.__init__(self, path=path, module=module) File.__init__(self, path=path, module=module)
self.rels = set() self.provides = set()
self.depends_on = set() self.requires = set()
self.depends_on = set() # Set of files this file depends on.
self.dep_level = None self.dep_level = None
self.is_parsed = False self.is_parsed = False
def add_require(self, rel): def add_require(self, rel):
"""Add dependency :param rel:""" """Add dependency :param rel:"""
assert rel.direction == DepRelation.USE assert rel.direction == DepRelation.USE
self.rels.add(rel) self.requires.add(rel)
def add_provide(self, rel): def add_provide(self, rel):
"""Add provide :param rel:""" """Add provide :param rel:"""
assert rel.direction == DepRelation.PROVIDE assert rel.direction == DepRelation.PROVIDE
self.rels.add(rel) self.provides.add(rel)
def satisfies(self, rel_b): def satisfies(self, rel_b):
"""Check if any of the file object relations match any of the relations """Check if any of the file object relations match any of the relations
listed in the parameter (rel_b)""" listed in the parameter (rel_b)"""
assert isinstance(rel_b, DepRelation) assert isinstance(rel_b, DepRelation)
# self._parse_if_needed() # self._parse_if_needed()
return any([x.satisfies(rel_b) for x in self.rels]) return any([x.satisfies(rel_b) for x in self.provides])
def get_dep_level(self): def get_dep_level(self):
"""Get the dependency level for the file instance, so we can order """Get the dependency level for the file instance, so we can order
......
...@@ -64,42 +64,41 @@ def solve(fileset, standard_libs=None): ...@@ -64,42 +64,41 @@ def solve(fileset, standard_libs=None):
not_satisfied = 0 not_satisfied = 0
for investigated_file in fset: for investigated_file in fset:
# logging.info("INVESTIGATED FILE: %s" % investigated_file) # logging.info("INVESTIGATED FILE: %s" % investigated_file)
# print(investigated_file.rels) for rel in investigated_file.requires:
for rel in investigated_file.rels:
# logging.info("- relation: %s" % rel) # logging.info("- relation: %s" % rel)
# logging.info("- direction: %s" % rel.direction) # logging.info("- direction: %s" % rel.direction)
# Only analyze USE relations, we are looking for dependencies # Only analyze USE relations, we are looking for dependencies
if rel.direction == DepRelation.USE: assert rel.direction == DepRelation.USE
satisfied_by = set() satisfied_by = set()
for dep_file in fset: for dep_file in fset:
if dep_file.satisfies(rel): if dep_file.satisfies(rel):
if dep_file is not investigated_file: if dep_file is not investigated_file:
investigated_file.depends_on.add(dep_file) investigated_file.depends_on.add(dep_file)
satisfied_by.add(dep_file) satisfied_by.add(dep_file)
if len(satisfied_by) > 1: if len(satisfied_by) > 1:
logging.warning( logging.warning(
"Relation %s satisfied by multiple (%d) files:\n %s", "Relation %s satisfied by multiple (%d) files:\n %s",
str(rel), str(rel),
len(satisfied_by), len(satisfied_by),
'\n '.join([file_aux.path for '\n '.join([file_aux.path for
file_aux in list(satisfied_by)])) file_aux in list(satisfied_by)]))
elif len(satisfied_by) == 0: elif len(satisfied_by) == 0:
# if relation is a USE PACKAGE, check against # if relation is a USE PACKAGE, check against
# the standard libs provided by the tool HDL compiler # the standard libs provided by the tool HDL compiler
required_lib = rel.obj_name.split('.')[0] required_lib = rel.obj_name.split('.')[0]
if (not standard_libs is None and if (not standard_libs is None and
required_lib in standard_libs and required_lib in standard_libs and
rel.direction is DepRelation.USE and rel.direction is DepRelation.USE and
rel.rel_type is DepRelation.PACKAGE): rel.rel_type is DepRelation.PACKAGE):
logging.debug("Not satisfied relation %s in %s will " logging.debug("Not satisfied relation %s in %s will "
"be covered by the target compiler " "be covered by the target compiler "
"standard libs.", "standard libs.",
str(rel), investigated_file.name) str(rel), investigated_file.name)
else: else:
logging.warning("Relation %s in %s not satisfied by " logging.warning("Relation %s in %s not satisfied by "
"any source file", "any source file",
str(rel), investigated_file.name) str(rel), investigated_file.name)
not_satisfied += 1 not_satisfied += 1
logging.debug("SOLVE END") logging.debug("SOLVE END")
if not_satisfied != 0: if not_satisfied != 0:
logging.warning( logging.warning(
...@@ -141,7 +140,7 @@ def make_dependency_set(fileset, top_level_entity, extra_modules=None): ...@@ -141,7 +140,7 @@ def make_dependency_set(fileset, top_level_entity, extra_modules=None):
entity_rel_vlog = DepRelation( entity_rel_vlog = DepRelation(
"%s.%s" % "%s.%s" %
("work", entity_name), DepRelation.PROVIDE, DepRelation.MODULE) ("work", entity_name), DepRelation.PROVIDE, DepRelation.MODULE)
for rel in test_file.rels: for rel in test_file.provides:
if (rel == entity_rel_vhdl) or (rel == entity_rel_vlog): if (rel == entity_rel_vhdl) or (rel == entity_rel_vlog):
return True return True
return False return False
......
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