Commit a2c8a6df authored by Tristan Gingold's avatar Tristan Gingold

extract sourcefileset.py from srcfile.py

parent 16656b90
......@@ -31,7 +31,8 @@ import sys
from ..tools.makefile_writer import load_syn_tool, load_sim_tool
from ..util import shell
from ..sourcefiles import new_dep_solver as dep_solver
from ..sourcefiles.srcfile import SourceFileSet, VHDLFile, VerilogFile, SVFile
from ..sourcefiles.srcfile import VHDLFile, VerilogFile, SVFile
from ..sourcefiles.sourcefileset import SourceFileSet
from ..module.module import Module, ModuleArgs
class Action(object):
......
......@@ -181,7 +181,8 @@ class Module(object):
Build a Source File Set containing the files indicated by the
provided list of paths
"""
from ..sourcefiles.srcfile import create_source_file, SourceFileSet
from ..sourcefiles.srcfile import create_source_file
from ..sourcefiles.sourcefileset import SourceFileSet
srcs = SourceFileSet()
# Check if this is the top module and grab the include_dirs
if self.parent is None:
......@@ -209,7 +210,7 @@ class Module(object):
def _process_manifest_files(self):
"""Process the files instantiated by the HDLMake module"""
from ..sourcefiles.srcfile import SourceFileSet
from ..sourcefiles.sourcefileset import SourceFileSet
# HDL files provided by the module
if "files" not in self.manifest_dict:
self.files = SourceFileSet()
......
......@@ -45,7 +45,7 @@ class DepParser(object):
def solve(fileset, standard_libs=None):
"""Function that Parses and Solves the provided HDL fileset. Note
that it doesn't return a new fileset, but modifies the original one"""
from .srcfile import SourceFileSet
from .sourcefileset import SourceFileSet
from .dep_file import DepRelation
assert isinstance(fileset, SourceFileSet)
fset = fileset.filter(DepFile)
......@@ -125,7 +125,7 @@ def make_dependency_sorted_list(fileset):
def make_dependency_set(fileset, top_level_entity, extra_modules=None):
"""Create the set of all files required to build the named
top_level_entity."""
from ..sourcefiles.srcfile import SourceFileSet
from ..sourcefiles.sourcefileset import SourceFileSet
from ..sourcefiles.dep_file import DepRelation
assert isinstance(fileset, SourceFileSet)
fset = fileset.filter(DepFile)
......
# -*- coding: utf-8 -*-
#
# Copyright (c) 2019 CERN
#
# This file is part of Hdlmake.
#
# Hdlmake is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hdlmake is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hdlmake. If not, see <http://www.gnu.org/licenses/>.
#
import logging
class SourceFileSet(set):
"""Class providing a extension of the 'set' object that includes
methods that allow for an easier management of a collection of HDL
source files"""
def __init__(self):
super(SourceFileSet, self).__init__()
self = []
def __str__(self):
return str([str(f) for f in self])
def add(self, files):
"""Add a set of files to the source fileset instance"""
if isinstance(files, str):
raise RuntimeError("Expected object, not a string")
elif files is None:
logging.debug("Got None as a file.\n Ommiting")
else:
try:
for file_aux in files:
super(SourceFileSet, self).add(file_aux)
except TypeError: # single file, not a list
super(SourceFileSet, self).add(files)
def filter(self, filetype):
"""Method that filters and returns all of the HDL source files
contained in the instance SourceFileSet matching the provided type"""
out = SourceFileSet()
for file_aux in self:
if isinstance(file_aux, filetype):
out.add(file_aux)
return out
def sort(self):
"""Return a sorted list of the fileset. This is useful to have always
the same output"""
return sorted(self, key=(lambda x: x.file_path))
......@@ -322,46 +322,6 @@ ALTERA_FILE_DICT = {
'gdf': GDFFile}
class SourceFileSet(set):
"""Class providing a extension of the 'set' object that includes
methods that allow for an easier management of a collection of HDL
source files"""
def __init__(self):
super(SourceFileSet, self).__init__()
self = []
def __str__(self):
return str([str(f) for f in self])
def add(self, files):
"""Add a set of files to the source fileset instance"""
if isinstance(files, str):
raise RuntimeError("Expected object, not a string")
elif files is None:
logging.debug("Got None as a file.\n Ommiting")
else:
try:
for file_aux in files:
super(SourceFileSet, self).add(file_aux)
except TypeError: # single file, not a list
super(SourceFileSet, self).add(files)
def filter(self, filetype):
"""Method that filters and returns all of the HDL source files
contained in the instance SourceFileSet matching the provided type"""
out = SourceFileSet()
for file_aux in self:
if isinstance(file_aux, filetype):
out.add(file_aux)
return out
def sort(self):
"""Return a sorted list of the fileset. This is useful to have always
the same output"""
return sorted(self, key=(lambda x: x.file_path))
def create_source_file(path, module, library=None,
include_dirs=None, is_include=False):
"""Function that analyzes the given arguments and returns a new HDL source
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment