Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VUnit python interface: adding files to a Library #274

Closed
Aaron-Hartwig opened this issue Sep 6, 2017 · 5 comments
Closed

VUnit python interface: adding files to a Library #274

Aaron-Hartwig opened this issue Sep 6, 2017 · 5 comments

Comments

@Aaron-Hartwig
Copy link
Contributor

Aaron-Hartwig commented Sep 6, 2017

Problem

The vunit.ui.VUnit.library method returns new instances of a library. I understand that this is just an interface into the underlying vunit.project.Library class, but this becomes an issue when trying to access previously added libraries on an instance of VUnit programatically. For a bit more context, I am setting up a larger test suite using the pattern @LarsAsplund lays out on SO. When doing this I need to "get" Libraries I may have previously created and added files to so I can add additional files. The problem seems to be with how vunit.ui.Library.add_source_file interfaces with the underlying project.

Reproduction

from vunit import VUnit
from os.path import dirname, abspath, join

# create the file we try to add
open('file.vhd', 'a').close()

proj_root = dirname(abspath(__file__))
vu = VUnit.from_argv()

try:
    test_lib = vu.library('Test')
except KeyError:
    print('Test Library does not exist, creating it now.')
    test_lib = vu.add_library('Test')

test_lib_2 = vu.library('Test')

print('Test Library returned after initial creation       : {0} - {1}'.format(test_lib.name, test_lib))
print('Test Library returned after "getting" it from VUnit: {0} - {1}'.format(test_lib_2.name, test_lib_2))

test_lib.add_source_file(join(proj_root, 'file.vhd'))
test_lib_2.add_source_file(join(proj_root, 'file.vhd'))

# Cannot access file because we it got added to the same library twice.
for file in test_lib.get_source_files('file.vhd'):
    print('Name: {0} - Library: {1}', file.name, file.library)
test_lib.get_source_file('file.vhd')
@Aaron-Hartwig Aaron-Hartwig changed the title VUnit python interface: "getting" a Library VUnit python interface: adding files to a Library Sep 6, 2017
@Aaron-Hartwig
Copy link
Contributor Author

Aaron-Hartwig commented Sep 6, 2017

Looks like the file gets added to the underlying source files again, even if it does not get added to the library again. Is this desired behavior?

self._source_files_in_order.append(source_file)

If not, I would propose a check similar to that in vunit.project.Library.add_source_file

@kraigher
Copy link
Collaborator

kraigher commented Sep 6, 2017

Sure it results in a invalid state. At least a warning is emitted. Maybe the warning should be raising an exception instead.

@kraigher
Copy link
Collaborator

kraigher commented Sep 6, 2017

Now an exception is raised instead when adding a duplicate file.

@Aaron-Hartwig
Copy link
Contributor Author

@kraigher Looking at it from the user's perspective, I would rather log that VUnit saw a duplicate file attempted to be added and then not add it rather than raise an exception. If an exception is raised, then the user still has to handle the exception anyway (which was my workaround to this issue in the first place). I discovered the invalid state because I was dynamically added libraries (and files to those libraries) to test suites without knowing what was added previously. To me, one of the advantages of VUnit was that it handled the case of me trying to add files that already existed in a library elegantly (log a warning, ignore file).

@kraigher
Copy link
Collaborator

kraigher commented Sep 6, 2017

I prefer the exception for two reasons:

  1. Would it not be a goal of the user to run the run.py file without warnings anyway?
  2. If allowing the program to continue after adding a duplicate file we must define the behavior.
    In the case of verilog if a previously added file already has other defines or include_paths set it could be a conflict.

nathanaelhuffman pushed a commit to nathanaelhuffman/vunit that referenced this issue Jul 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants