@@ -41,7 +41,6 @@ def __init__(self,
4141 self ._vhdl_parser = vhdl_parser
4242 self ._verilog_parser = verilog_parser
4343 self ._libraries = {}
44- self ._source_files = {}
4544 self ._source_files_in_order = []
4645 self ._depend_on_components = depend_on_components
4746 self ._depend_on_package_body = depend_on_package_body
@@ -91,8 +90,9 @@ def add_source_file(self, file_name, library_name, file_type='vhdl', include_dir
9190 else :
9291 raise ValueError (file_type )
9392
94- self ._source_files [file_name ] = source_file
95- self ._source_files_in_order .append (file_name )
93+ library .add_source_file (source_file )
94+ self ._source_files_in_order .append (source_file )
95+ return source_file
9696
9797 @staticmethod
9898 def _find_primary_secondary_design_unit_dependencies (source_file ):
@@ -153,7 +153,7 @@ def _find_other_design_unit_dependencies(self, source_file): # pylint: disable=
153153
154154 if name in architectures :
155155 file_name = architectures [name ]
156- yield self . _source_files [ file_name ]
156+ yield library . get_source_file ( file_name )
157157 else :
158158 LOGGER .warning ("%s: failed to find architecture '%s' of entity '%s.%s'" ,
159159 source_file .name , name , library .name , primary_unit .name )
@@ -277,7 +277,7 @@ def comparison_key(source_file):
277277
278278 return sorted (affected_files , key = comparison_key )
279279
280- def get_dependencies_in_compile_order (self , target ):
280+ def get_dependencies_in_compile_order (self , target , library = None ):
281281 """
282282 Get a list of dependencies of target, if target is specified.
283283 Otherwise, get a list of all files in the project.
@@ -287,9 +287,18 @@ def get_dependencies_in_compile_order(self, target):
287287 if target is None :
288288 return self .get_files_in_compile_order (incremental = False )
289289
290- target_file = self ._source_files [target ]
290+ target_files = []
291+ for library in self ._libraries .values ():
292+ try :
293+ target_files .append (library .get_source_file (target ))
294+ except KeyError :
295+ pass
296+
297+ if len (target_files ) == 0 :
298+ raise KeyError (target )
299+
291300 dependency_graph = self ._create_dependency_graph ()
292- affected_files = dependency_graph .get_dependencies (set ([ target_file ] ))
301+ affected_files = dependency_graph .get_dependencies (set (target_files ))
293302 compile_order = dependency_graph .toposort ()
294303
295304 def comparison_key (source_file ):
@@ -302,13 +311,7 @@ def get_source_files_in_order(self):
302311 """
303312 Get a list of source files in the order they were added to the project
304313 """
305- return [self ._source_files [file_name ] for file_name in self ._source_files_in_order ]
306-
307- def get_source_file (self , file_name ):
308- """
309- Get source file object by file name
310- """
311- return self ._source_files [file_name ]
314+ return [source_file for source_file in self ._source_files_in_order ]
312315
313316 def get_libraries (self ):
314317 return self ._libraries .values ()
@@ -379,6 +382,8 @@ def __init__(self, name, directory, is_external=False):
379382 self .name = name
380383 self .directory = directory
381384
385+ self ._source_files = {}
386+
382387 # VHDL specific
383388 # Entity objects
384389 self ._entities = {}
@@ -395,6 +400,21 @@ def __init__(self, name, directory, is_external=False):
395400
396401 self ._is_external = is_external
397402
403+ def add_source_file (self , source_file ):
404+ """
405+ Add source file to library unless it exists
406+ """
407+ if source_file .name not in self ._source_files :
408+ self ._source_files [source_file .name ] = source_file
409+ else :
410+ LOGGER .warning ("%s already added to library %s" , source_file .name , self .name )
411+
412+ def get_source_file (self , file_name ):
413+ """
414+ Get source file with file name or raise KeyError
415+ """
416+ return self ._source_files [file_name ]
417+
398418 @property
399419 def is_external (self ):
400420 """
@@ -518,12 +538,15 @@ def __init__(self, name, library, file_type):
518538
519539 def __eq__ (self , other ):
520540 if isinstance (other , type (self )):
521- return self .name == other .name
541+ return ( self .name , self . library . name ) == ( other .name , other . library . name )
522542 else :
523543 return False
524544
525545 def __hash__ (self ):
526- return hash (self .name )
546+ return hash ((self .name , self .library .name ))
547+
548+ def __repr__ (self ):
549+ return "SourceFile(%s, %s)" % (self .name , self .library .name )
527550
528551 @property
529552 def content_hash (self ):
0 commit comments