Refactoring Module, focus on ModuleContent

parent 58884d63
import os
"""This provides the stuff related with the HDLMake module,
from files to required submodules"""
import logging
from .core import ModuleCore
from hdlmake import fetch
from hdlmake.util import path as path_mod
class ModuleContent(ModuleCore):
"""Class providing the HDLMake module content"""
def __init__(self):
self.top_entity = None
# Manifest Files Properties
......@@ -13,22 +16,25 @@ class ModuleContent(ModuleCore):
self.local = []
self.git = []
self.svn = []
self.fetch_pre_cmd = None
self.fetch_post_cmd = None
super(ModuleContent, self).__init__()
def process_manifest(self):
"""Process the content section of the manifest_dic"""
self._process_manifest_files()
self._process_manifest_modules()
super(ModuleContent, self).process_manifest()
def _process_manifest_files(self):
from hdlmake.srcfile import (TCLFile, VerilogFile, VHDLFile,
SourceFileSet)
"""Process the files instantiated by the HDLMake module"""
from hdlmake.srcfile import SourceFileSet
# HDL files provided by the module
if self.manifest_dict["files"] == []:
self.files = SourceFileSet()
try:
logging.debug("No files in the manifest %s",
self.manifest.path)
logging.debug("No files in the manifest at %s",
self.path)
except AttributeError:
pass
else:
......@@ -38,14 +44,10 @@ class ModuleContent(ModuleCore):
self.path, str(self.manifest_dict["files"]))
paths = self._make_list_of_paths(self.manifest_dict["files"])
self.files = self._create_file_list_from_paths(paths=paths)
for f in self.files:
if isinstance(f, VerilogFile):
f.vsim_opt = self.vsim_opt
elif isinstance(f, VHDLFile):
f.vcom_opt = self.vcom_opt
def _process_manifest_modules(self):
"""Process the submodules required by the HDLMake module"""
if self.manifest_dict["fetchto"] is not None:
fetchto = path_mod.rel2abs(self.manifest_dict["fetchto"],
self.path)
......
"""Provides the core functionality for the HDLMake module"""
import os
import sys
import logging
from hdlmake import fetch
......@@ -68,6 +69,38 @@ class ModuleConfig(object):
self.isfetched = True
def _check_filepath(self, filepath):
"""Check the provided filepath against several conditions"""
if filepath:
if path_mod.is_abs_path(filepath):
logging.warning(
"Specified path seems to be an absolute path: " +
filepath + "\nOmitting.")
return False
filepath = os.path.join(self.path, filepath)
if not os.path.exists(filepath):
logging.error(
"Path specified in manifest in %s doesn't exist: %s",
self.path, filepath)
sys.exit("Exiting")
filepath = path_mod.rel2abs(filepath, self.path)
if os.path.isdir(filepath):
logging.warning(
"Path specified in manifest %s is a directory: %s",
self.path, filepath)
return True
def _make_list_of_paths(self, list_of_paths):
"""Get a list with only the valid absolute paths from the provided"""
paths = []
for filepath in list_of_paths:
if self._check_filepath(filepath):
paths.append(path_mod.rel2abs(filepath, self.path))
return paths
class ModuleCore(ModuleConfig):
"""This is the class providing the module core functionality"""
......@@ -116,3 +149,26 @@ class ModuleCore(ModuleConfig):
self.action = self.manifest_dict["action"].lower()
def _create_file_list_from_paths(self, paths):
"""
Build a Source File Set containing the files indicated by the
provided list of paths
"""
from hdlmake.srcfile import SourceFileFactory, SourceFileSet
sff = SourceFileFactory()
srcs = SourceFileSet()
for path_aux in paths:
if os.path.isdir(path_aux):
dir_ = os.listdir(path_aux)
for f_dir in dir_:
f_dir = os.path.join(self.path, path_aux, f_dir)
if not os.path.isdir(f_dir):
srcs.add(sff.new(path=f_dir,
module=self,
library=self.library))
else:
srcs.add(sff.new(path=path_aux,
module=self,
library=self.library))
return srcs
......@@ -29,11 +29,9 @@ specific parent modules providing specific methods and attributes.
from __future__ import print_function
import os
import sys
import logging
from hdlmake.manifest_parser import ManifestParser
from hdlmake.util import path as path_mod
from hdlmake.module import (ModuleSynthesis,
ModuleSimulation, ModuleContent, ModuleAltera)
......@@ -98,6 +96,19 @@ class Module(ModuleSynthesis,
"""
logging.debug("Process manifest at: " + os.path.dirname(self.path))
super(Module, self).process_manifest()
self._set_simulation_options()
def _set_simulation_options(self):
"""This set the simulation option for all the files in the Module"""
from hdlmake.srcfile import VerilogFile, VHDLFile
for file_aux in self.files:
if isinstance(file_aux, VerilogFile):
file_aux.vsim_opt = self.vsim_opt
file_aux.include_dirs = self.include_dirs
elif isinstance(file_aux, VHDLFile):
file_aux.vcom_opt = self.vcom_opt
file_aux.include_dirs = self.include_dirs
def parse_manifest(self):
......@@ -156,66 +167,3 @@ class Module(ModuleSynthesis,
module_aux.parse_manifest()
def _make_list_of_paths(self, list_of_paths):
"""Get a list with only the valid absolute paths from the provided"""
paths = []
for filepath in list_of_paths:
if self._check_filepath(filepath):
paths.append(path_mod.rel2abs(filepath, self.path))
return paths
def _check_filepath(self, filepath):
"""Check the provided filepath against several conditions"""
if filepath:
if path_mod.is_abs_path(filepath):
logging.warning(
"Specified path seems to be an absolute path: " +
filepath + "\nOmitting.")
return False
filepath = os.path.join(self.path, filepath)
if not os.path.exists(filepath):
logging.error(
"Path specified in manifest in %s doesn't exist: %s",
self.path, filepath)
sys.exit("Exiting")
filepath = path_mod.rel2abs(filepath, self.path)
if os.path.isdir(filepath):
logging.warning(
"Path specified in manifest %s is a directory: %s",
self.path, filepath)
return True
def _create_file_list_from_paths(self, paths):
"""
Build a Source File Set containing the files indicated by the
provided list of paths
"""
from hdlmake.srcfile import SourceFileFactory, SourceFileSet
sff = SourceFileFactory()
srcs = SourceFileSet()
for path_aux in paths:
if os.path.isdir(path_aux):
dir_ = os.listdir(path_aux)
for f_dir in dir_:
f_dir = os.path.join(self.path, path_aux, f_dir)
if not os.path.isdir(f_dir):
srcs.add(sff.new(path=f_dir,
module=self,
library=self.library,
vcom_opt=self.vcom_opt,
vlog_opt=self.vlog_opt,
include_dirs=self.include_dirs))
else:
srcs.add(sff.new(path=path_aux,
module=self,
library=self.library,
vcom_opt=self.vcom_opt,
vlog_opt=self.vlog_opt,
include_dirs=self.include_dirs))
return srcs
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