Skip to content

Commit

Permalink
add 'vc_list.json' and method 'ui.use_verification_components'
Browse files Browse the repository at this point in the history
  • Loading branch information
1138-4EB committed Jun 11, 2019
1 parent 65779ff commit 1949add
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 11 deletions.
93 changes: 82 additions & 11 deletions vunit/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,19 @@
import traceback
import logging
import json
import os
from os.path import exists, abspath, join, basename, splitext, normpath, dirname
from os import mkdir, makedirs, environ, popen
from os.path import (
abspath,
basename,
dirname,
exists,
isabs,
isdir,
isfile,
join,
normpath,
splitext,
)
from glob import glob
from fnmatch import fnmatch
from vunit.database import PickledDataBase, DataBase
Expand Down Expand Up @@ -887,7 +898,7 @@ def _create_simulator_if(self):
exit(1)

if not exists(self._simulator_output_path):
os.makedirs(self._simulator_output_path)
makedirs(self._simulator_output_path)

return self._simulator_class.from_args(args=self._args,
output_path=self._simulator_output_path)
Expand Down Expand Up @@ -1011,7 +1022,7 @@ def _create_output_path(self, clean):
if clean:
ostools.renew_path(self._output_path)
elif not exists(self._output_path):
os.makedirs(self._output_path)
makedirs(self._output_path)

ostools.renew_path(self._preprocessed_path)

Expand Down Expand Up @@ -1080,12 +1091,6 @@ def add_random(self):
"""
self._builtins.add("random")

def add_verification_components(self):
"""
Add verification component library
"""
self._builtins.add("verification_components")

def add_osvvm(self):
"""
Add osvvm library
Expand All @@ -1098,6 +1103,72 @@ def add_json4vhdl(self):
"""
self._builtins.add("json4vhdl")

def add_verification_components(self, location=None):
"""
Add verification component library
:param location: path of the optional directory to contain third-party VCs.
:returns: a dict containing the 'third_party' location and the known/supported VCs.
"""
self._builtins.add("verification_components")
root = join(dirname(__file__), 'vhdl', 'verification_components')

cfg = {'third_party': location or join(root, 'third_party')}
cfg.update(json.loads(open(join(root, 'vc_list.json')).read()))
return cfg

def use_verification_components(self, cfg, vc_list):
"""
Use verification components named in 'vc_list' and defined in 'cfg'
:param cfg: the configuration object returned by 'add_verification_components'.
:param vc_list: a list containing the names of the VCs which are to be used.
"""

wh_loc = cfg['third_party']
if not isdir(wh_loc):
print('Creating directory ' + wh_loc)
mkdir(wh_loc)

def add_vc(key, cfg):
"""
Add the sources of a known VC to this project
:param key: name of the VC to be added.
:para cfg: configuration object returned by 'add_verification_components'.
"""
item = cfg[key]
loc = item['path'] if isabs(item['path']) else join(wh_loc, item['path'])
if not isdir(loc):
print('VC <' + key + '> not available locally.')
print(popen(' '.join([
'git',
'clone',
item['remote'],
loc
])).read())

vc_cfg_file = join(loc, 'vunit_cfg.json')
if not isfile(vc_cfg_file):
print('File <' + vc_cfg_file + '> not found.')
exit(1)
vc_cfg = json.loads(open(vc_cfg_file).read())

for name, _ in vc_cfg['depends'].items():
# TODO Check 'val', which tells the minimum and/or maximum required version
if name == 'VUnit':
continue
add_vc(name, cfg)

self.add_library(vc_cfg['lib'], allow_duplicate=True).add_source_files(join(loc, 'src', '*.vhd'))

for key in vc_list:
if key not in cfg:
print('VC <' + key + '> not defined. Please add it to the configuration first.')
exit(1)
else:
add_vc(key, cfg)

def get_compile_order(self, source_files=None):
"""
Get the compile order of all or specific source files and
Expand Down Expand Up @@ -1994,7 +2065,7 @@ def select_vhdl_standard(vhdl_standard=None):
if vhdl_standard is not None:
check_vhdl_standard(vhdl_standard, from_str="From class initialization")
else:
vhdl_standard = os.environ.get('VUNIT_VHDL_STANDARD', '2008')
vhdl_standard = environ.get('VUNIT_VHDL_STANDARD', '2008')
check_vhdl_standard(vhdl_standard, from_str="VUNIT_VHDL_STANDARD environment variable")

return vhdl_standard
Expand Down
10 changes: 10 additions & 0 deletions vunit/vhdl/verification_components/vc_list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"AXI": {
"path": "vc_axi",
"remote": "https://github.com/VUnit/vc_axi"
},
"UART": {
"path": "vc_uart",
"remote": "https://github.com/VUnit/vc_uart"
}
}

0 comments on commit 1949add

Please sign in to comment.