From 0dad9a40a5ca88b5eb3918c2c8e8e3a46b5d2a23 Mon Sep 17 00:00:00 2001 From: paul-gatewood Date: Sun, 19 Nov 2023 14:36:14 -0700 Subject: [PATCH] Common get_file_type function (#401) Add common function for stripping version from file_type --------- Co-authored-by: Paul Gatewood --- edalize/design_compiler.py | 3 ++- edalize/diamond.py | 3 ++- edalize/genus.py | 3 ++- edalize/libero.py | 7 ++++--- edalize/quartus.py | 9 +++------ edalize/radiant.py | 3 ++- edalize/spyglass.py | 3 ++- edalize/utils.py | 12 ++++++++++++ edalize/vunit.py | 6 ++---- 9 files changed, 31 insertions(+), 18 deletions(-) diff --git a/edalize/design_compiler.py b/edalize/design_compiler.py index 43b4bd42b..374e0cda1 100644 --- a/edalize/design_compiler.py +++ b/edalize/design_compiler.py @@ -9,6 +9,7 @@ import subprocess from edalize.edatool import Edatool +from edalize.utils import get_file_type from edalize.yosys import Yosys from importlib import import_module @@ -142,7 +143,7 @@ def src_file_filter(self, f): "SDC": "source", } - _file_type = f.file_type.split("-")[0] + _file_type = get_file_type(f) if _file_type in file_types: cmd = "" cmd += file_types[_file_type] + " " diff --git a/edalize/diamond.py b/edalize/diamond.py index 82e6cc5dd..dc1c12b02 100644 --- a/edalize/diamond.py +++ b/edalize/diamond.py @@ -7,6 +7,7 @@ import sys from edalize.edatool import Edatool +from edalize.utils import get_file_type logger = logging.getLogger(__name__) @@ -128,7 +129,7 @@ def _vhdl_source(f): "tclSource": "source", "SDC": "prj_src add -format SDC", } - _file_type = f.file_type.split("-")[0] + _file_type = get_file_type(f) if _file_type in file_types: return file_types[_file_type] + " " + f.name elif _file_type in ["user", "LPF"]: diff --git a/edalize/genus.py b/edalize/genus.py index cbb130026..8bd757696 100644 --- a/edalize/genus.py +++ b/edalize/genus.py @@ -9,6 +9,7 @@ import subprocess from edalize.edatool import Edatool +from edalize.utils import get_file_type from edalize.yosys import Yosys from importlib import import_module @@ -128,7 +129,7 @@ def src_file_filter(self, f): # Note: we do not add an SDC source here as the constraint files are # referenced inside the MMMC view file on a per corner base } - _file_type = f.file_type.split("-")[0] + _file_type = get_file_type(f) if _file_type in file_types: cmd = "" diff --git a/edalize/libero.py b/edalize/libero.py index e015dde1a..df405a9f4 100644 --- a/edalize/libero.py +++ b/edalize/libero.py @@ -4,6 +4,7 @@ from pathlib import Path from collections import defaultdict from edalize.edatool import Edatool +from edalize.utils import get_file_type logger = logging.getLogger(__name__) @@ -141,7 +142,7 @@ def configure_main(self): verilogFiles = 0 VHDLFiles = 0 for f in src_files: - t = f.file_type.split("-")[0] + t = get_file_type(f) if t == "verilogSource" or t == "systemVerilogSource": verilogFiles += 1 elif t == "vhdlSource": @@ -179,7 +180,7 @@ def src_file_filter(self, f): "FDC": "-net_fdc {", "NDC": "-ndc {", } - _file_type = f.file_type.split("-")[0] + _file_type = get_file_type(f) if _file_type in file_types: # Do not return library files here if f.logical_name: @@ -191,7 +192,7 @@ def tcl_file_filter(self, f): file_types = { "tclSource": "source ", } - _file_type = f.file_type.split("-")[0] + _file_type = get_file_type(f) if _file_type in file_types: return file_types[_file_type] + f.name return "" diff --git a/edalize/quartus.py b/edalize/quartus.py index d20a5073b..f6330ddbf 100644 --- a/edalize/quartus.py +++ b/edalize/quartus.py @@ -11,6 +11,7 @@ import xml.etree.ElementTree as ET from functools import partial from edalize.edatool import Edatool +from edalize.utils import get_file_type logger = logging.getLogger(__name__) @@ -169,15 +170,11 @@ def configure_main(self): "quartus-project.tcl.j2", escaped_name + ".tcl", template_vars ) - # Helper to extract file type - def file_type(self, f): - return f.file_type.split("-")[0] - # Filter for just QSYS files. This verifies that they are compatible # with the identified Quartus version def qsys_file_filter(self, f): name = "" - if self.file_type(f) == "QSYS": + if get_file_type(f) == "QSYS": # Compatibility checks try: qsysTree = ET.parse(os.path.join(self.work_root, f.name)) @@ -242,7 +239,7 @@ def _handle_tcl(f): "tclSource": partial(_handle_tcl), } - _file_type = self.file_type(f) + _file_type = get_file_type(f) if _file_type in file_mapping: return file_mapping[_file_type](f) elif _file_type == "user": diff --git a/edalize/radiant.py b/edalize/radiant.py index 16843648e..d8728b03a 100644 --- a/edalize/radiant.py +++ b/edalize/radiant.py @@ -6,6 +6,7 @@ import os.path from edalize.edatool import Edatool +from edalize.utils import get_file_type logger = logging.getLogger(__name__) @@ -114,7 +115,7 @@ def _work_source(f): "vhdlSource": "prj_add_source ", "PDC": "prj_add_source ", } - _file_type = f.file_type.split("-")[0] + _file_type = get_file_type(f) if _file_type in file_types: return file_types[_file_type] + f.name + _work_source(f) elif _file_type == "tclSource": diff --git a/edalize/spyglass.py b/edalize/spyglass.py index 2166ca7f2..847b6be5f 100644 --- a/edalize/spyglass.py +++ b/edalize/spyglass.py @@ -7,6 +7,7 @@ from collections import OrderedDict from edalize.edatool import Edatool +from edalize.utils import get_file_type logger = logging.getLogger(__name__) @@ -136,7 +137,7 @@ def _vhdl_source(f): "waiver": "read_file -type waiver", "awl": "read_file -type awl", } - _file_type = f.file_type.split("-")[0] + _file_type = get_file_type(f) if _file_type in file_types: return file_types[_file_type] + " " + f.name elif _file_type == "user": diff --git a/edalize/utils.py b/edalize/utils.py index 7a0ce9cb6..4d4c0134b 100644 --- a/edalize/utils.py +++ b/edalize/utils.py @@ -70,3 +70,15 @@ def write(self, outfile): f.write( f"\t$(EDALIZE_LAUNCHER) {env_prefix}{' '.join([str(x) for x in c.command])}\n" ) + + +# Helper function to strip potential version from the end of a file_type (for example, converting +# vhdlSource-2008 -> vhdlSource) +def get_file_type(file_obj): + file_type = file_obj.file_type + + for i, c in enumerate(file_type): + if c == "-": + return file_type[0:i] + + return file_type diff --git a/edalize/vunit.py b/edalize/vunit.py index e57a2e645..f8768ad63 100644 --- a/edalize/vunit.py +++ b/edalize/vunit.py @@ -7,6 +7,7 @@ import logging from collections import OrderedDict from edalize.edatool import Edatool +from edalize.utils import get_file_type logger = logging.getLogger(__name__) @@ -103,16 +104,13 @@ def src_file_vhdl_standard_filter(self, f): return fragments[1] def src_file_filter(self, f): - def _get_file_type(f): - return f.file_type.split("-")[0] - file_mapping = { "verilogSource": lambda f: f.name, "systemVerilogSource": lambda f: f.name, "vhdlSource": lambda f: f.name, } - _file_type = _get_file_type(f) + _file_type = get_file_type(f) if _file_type in file_mapping: return file_mapping[_file_type](f) elif _file_type == "user":