Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_library_add(caplog):
import tempfile
from fusesoc.main import add_library
from fusesoc.coremanager import CoreManager
from fusesoc.librarymanager import LibraryManager
tcf = tempfile.NamedTemporaryFile(mode="w+")
clone_target = tempfile.mkdtemp(prefix='library_add_')
library_root = tempfile.mkdtemp(prefix='library_add_')
conf = Config(file=tcf)
conf.library_root = library_root
cm = CoreManager(conf)
args = Namespace()
args.name = 'fusesoc-cores'
args.location = clone_target
args.config = tcf
args.no_auto_sync = False
vars(args)['sync-uri'] = sync_uri
add_library(cm, args)
expected = """[library.fusesoc-cores]
location = {}
sync-uri = https://github.com/fusesoc/fusesoc-cores
sync-type = git
auto-sync = true""".format(os.path.abspath(clone_target))
def _get_core(name, has_system=False):
core = None
try:
core = CoreManager().get_core(Vlnv(name))
except RuntimeError as e:
pr_err(str(e))
exit(1)
except DependencyError as e:
pr_err("'" + name + "' or any of its dependencies requires '" + e.value + "', but this core was not found")
exit(1)
if has_system and not core.backend:
pr_err("Unable to find .system file for '{}'".format(name))
exit(1)
return core
def list_cores(args):
cores = CoreManager().get_cores()
print("\nAvailable cores:\n")
if not cores:
cores_root = CoreManager().get_cores_root()
if cores_root:
pr_err("No cores found in "+':'.join(cores_root))
else:
pr_err("cores_root is not defined")
exit(1)
maxlen = max(map(len,cores.keys()))
print('Core'.ljust(maxlen) + ' Cache status')
print("="*80)
for name in sorted(cores.keys()):
core = cores[name]
print(name.ljust(maxlen) + ' : ' + core.cache_status())
def sim(args):
core = _get_core(args.system)
if args.sim:
sim_name = args.sim[0]
elif core.simulators:
sim_name = core.simulators[0]
else:
pr_err("No simulator was found in '"+ args.system + "' core description")
logger.error("No simulator was found in '"+ args.system + "' core description")
exit(1)
try:
CoreManager().tool = sim_name
sim = _import('simulator', sim_name)(core, export=True)
except DependencyError as e:
pr_err("'" + args.system + "' or any of its dependencies requires '" + e.value + "', but this core was not found")
exit(1)
except ImportError:
pr_err("Unknown simulator '{}'".format(sim_name))
exit(1)
except RuntimeError as e:
pr_err(str(e))
exit(1)
if (args.testbench):
sim.toplevel = args.testbench[0]
else:
sim.toplevel = sim.system.simulator['toplevel']
if not args.keep or not os.path.exists(sim.work_root):
try:
def __init__(self, system):
config = Config()
self.system = system
self.build_root = os.path.join(config.build_root, self.system.sanitized_name)
self.src_root = os.path.join(self.build_root, 'src')
self.cm = CoreManager()
self.cores = self.cm.get_depends(self.system.name)
self.env = os.environ.copy()
self.env['BUILD_ROOT'] = os.path.abspath(self.build_root)
self.plusarg = {}
self.vlogparam = {}
self.generic = {}
self.cmdlinearg = {}
def update(args):
for root in CoreManager().get_cores_root():
if os.path.exists(root):
args = ['-C', root,
'config', '--get', 'remote.origin.url']
repo_root = ""
try:
repo_root = subprocess.check_output(['git'] + args).decode("utf-8")
if repo_root.strip() in [repo[1] for repo in REPOS]:
pr_info("Updating '{}'".format(root))
args = ['-C', root, 'pull']
Launcher('git', args).run()
except subprocess.CalledProcessError:
pass
def init_coremanager(config, args_cores_root):
logger.debug("Initializing core manager")
cm = CoreManager(config)
args_libs = [Library(acr, acr) for acr in args_cores_root]
#Add libraries from config file, env var and command-line
for library in config.libraries + args_libs:
try:
cm.add_library(library)
except (RuntimeError, IOError) as e:
_s = "Failed to register library '{}'"
logger.warning(_s.format(str(e)))
return cm