# Auto generated by Edalize


def load_module_from_file(name, python_file):
    import importlib.util

    spec = importlib.util.spec_from_file_location(name, python_file)
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


def load_runner_hooks(python_file=r"{{ vunit_runner_path }}"):
    if len(python_file) > 0:
        return load_module_from_file("vunit_runner_hooks", python_file)
    else:
        return __import__("edalize.vunit_hooks", fromlist=["vunit_hooks"])


runner = load_runner_hooks().VUnitRunner()

# Override this hook to allow custom creation configuration of the VUnit instance:
vu = runner.create()

{% for extlib in add_libraries %}
vu.add_{{ extlib }}()
{% endfor %}

files = {}

{% for library, src_files in libraries.items() %}
lib = vu.add_library("{{ library }}")
files.update(
    {
{% for src_file in src_files if src_file|src_file_filter %}
{% if (src_file|src_file_vhdl_standard_filter) %}
        "{{src_file|src_file_filter}}": lib.add_source_file("{{ src_file|src_file_filter }}", vhdl_standard="{{ src_file|src_file_vhdl_standard_filter }}"),
{% else %}
        "{{src_file|src_file_filter}}": lib.add_source_file("{{ src_file|src_file_filter }}"),
{% endif %}
{% endfor %}
    }
)

# Override this hook to customize the library, e.g. compile-flags etc.
# This allows full access to vunit.ui.Library interface:
runner.handle_library("{{ library }}", lib)

{% endfor %}

# start of core file mapping
{% if core_files %}
core_files = {
{% for core, files in core_files.items() %}
    "{{core}}": [
{% for src_file in files if src_file|src_file_filter %}
        files["{{src_file|src_file_filter}}"],
{% endfor %}
    ],
{% endfor %}
}
{% endif %}
# end of core file mapping

# start of inter core dependencies
{% if core_dependencies %}
{% for core, dependencies in core_dependencies.items() %}
for src_file in core_files["{{core}}"]:
{% if dependencies %}
{% for dependency in dependencies %}
    src_file.add_dependency_on(core_files["{{dependency}}"])
{% endfor %}
{% else %}
    pass
{% endif %}
{% endfor %}
{% endif %}
# end of inter core dependencies

# override this hook to perform final customization and parametrization of VUnit, custom invokation, etc.
runner.main(vu)
