On progress refactoring: just a working checkpoint

parent d8eed83f
......@@ -87,7 +87,7 @@ def main():
# Check if our top_module has been successfully assigned and
# contains a Manifest.py (ModulePool class)
if modules_pool.get_top_module().manifest is None:
if not modules_pool.get_top_module().isparsed:
logging.info("No manifest found. At least an empty one is needed")
logging.info("To see some help, type hdlmake --help")
sys.exit("Exiting")
......
......@@ -21,6 +21,7 @@
#
import os
import logging
from .util import path as path_mod
from .util.configparser import ConfigParser
......@@ -131,8 +132,14 @@ class ManifestParser(ConfigParser):
self.add_option('sim_only_files', default=[], help="List of files that are used only in simulation", type=[])
self.add_type('sim_only_files', type='')
def add_manifest(self, manifest):
return self.add_config_file(manifest.path)
def add_manifest(self, path):
manifest = self._search_for_manifest(path)
if manifest is None:
logging.error("No manifest found in path: %s", path)
quit()
else:
logging.debug("Parse manifest in: %s", manifest.path)
return self.add_config_file(manifest.path)
def print_help(self):
self.help()
......@@ -159,3 +166,27 @@ class ManifestParser(ConfigParser):
f.close()
self.package = ret
def _search_for_manifest(self, path):
"""
Look for manifest in the given folder
"""
logging.debug("Looking for manifest in " + path)
dir_files = os.listdir(path)
if "manifest.py" in dir_files and "Manifest.py" in dir_files:
logging.error(
"Both manifest.py and Manifest.py" +
"found in the module directory: %s",
self.path)
sys.exit("\nExiting")
for filename in dir_files:
if filename == "manifest.py" or filename == "Manifest.py":
if not os.path.isdir(filename):
logging.debug("Found manifest for module %s: %s",
path, filename)
path_aux = os.path.join(path, filename)
manifest = Manifest(path=os.path.abspath(path_aux))
return manifest
return None
......@@ -15,22 +15,27 @@ class ModuleContent(ModulePlugin):
super(ModuleContent, self).__init__()
def process_manifest(self):
self._process_manifest_fetch()
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
from hdlmake.srcfile import (TCLFile, VerilogFile, VHDLFile,
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 %s",
self.manifest.path)
except AttributeError:
pass
else:
self.manifest_dict["files"] = ModulePlugin.flatten_list(self.manifest_dict["files"])
logging.debug("Files in %s: %s" % (self.path, str(self.manifest_dict["files"])))
self.manifest_dict["files"] = ModulePlugin.flatten_list(
self.manifest_dict["files"])
logging.debug("Files in %s: %s",
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:
......@@ -39,10 +44,11 @@ class ModuleContent(ModulePlugin):
elif isinstance(f, VHDLFile):
f.vcom_opt = self.vcom_opt
def _process_manifest_modules(self):
def _process_manifest_fetch(self):
# Fetch configuration
if self.manifest_dict["fetchto"] is not None:
fetchto = path_mod.rel2abs(self.manifest_dict["fetchto"], self.path)
fetchto = path_mod.rel2abs(self.manifest_dict["fetchto"],
self.path)
self.fetchto = fetchto
else:
fetchto = self.fetchto
......@@ -50,14 +56,17 @@ class ModuleContent(ModulePlugin):
self.fetch_pre_cmd = self.manifest_dict["fetch_pre_cmd"]
self.fetch_post_cmd = self.manifest_dict["fetch_post_cmd"]
def _process_manifest_modules(self):
fetchto = self.fetchto
# Process required modules
if "local" in self.manifest_dict["modules"]:
local_paths = ModulePlugin.flatten_list(self.manifest_dict["modules"]["local"])
local_paths = ModulePlugin.flatten_list(
self.manifest_dict["modules"]["local"])
local_mods = []
for path in local_paths:
if path_mod.is_abs_path(path):
logging.error("Found an absolute path (" + path + ") in a manifest"
"(" + self.path + ")")
logging.error("Found an absolute path (" + path +
") in a manifest(" + self.path + ")")
quit()
path = path_mod.rel2abs(path, self.path)
local_mods.append(self.pool.new_module(parent=self,
......@@ -69,7 +78,8 @@ class ModuleContent(ModulePlugin):
self.local = []
if "svn" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["svn"] = ModulePlugin.flatten_list(self.manifest_dict["modules"]["svn"])
self.manifest_dict["modules"]["svn"] = ModulePlugin.flatten_list(
self.manifest_dict["modules"]["svn"])
svn_mods = []
for url in self.manifest_dict["modules"]["svn"]:
svn_mods.append(self.pool.new_module(parent=self,
......@@ -81,7 +91,8 @@ class ModuleContent(ModulePlugin):
self.svn = []
if "git" in self.manifest_dict["modules"]:
self.manifest_dict["modules"]["git"] = ModulePlugin.flatten_list(self.manifest_dict["modules"]["git"])
self.manifest_dict["modules"]["git"] = ModulePlugin.flatten_list(
self.manifest_dict["modules"]["git"])
git_mods = []
for url in self.manifest_dict["modules"]["git"]:
git_mods.append(self.pool.new_module(parent=self,
......@@ -92,7 +103,8 @@ class ModuleContent(ModulePlugin):
else:
self.git = []
# TODO: Git submodules are temporarly disabled until the expected behavior is depicted
# Git submodules are temporarly disabled!
# -- we need to clearly define the expected behavior
# git_submodule_dict = fetch.Git.get_git_submodules(self)
# git_toplevel = fetch.Git.get_git_toplevel(self)
# for submodule_key in git_submodule_dict.keys():
......@@ -102,9 +114,9 @@ class ModuleContent(ModulePlugin):
# path = os.path.normpath(path)
# fetchto = os.path.sep.join(path.split(os.path.sep)[:-1])
# self.git_submodules.append(self.pool.new_module(parent=self,
# url=url,
# fetchto=fetchto,
# source=fetch.GITSUBMODULE))
# url=url,
# fetchto=fetchto,
# source=fetch.GITSUBMODULE))
......@@ -4,7 +4,6 @@ import os
import logging
from .plugin import ModulePlugin
from hdlmake.util import path as path_mod
from hdlmake import fetch
class ModuleCore(ModulePlugin):
......@@ -19,31 +18,6 @@ class ModuleCore(ModulePlugin):
# Manifest Force tool Property
self.force_tool = None
# Origin attributes
self.isfetched = False
# raw_url is the full url, including: branch, revision, commit, tag
self.raw_url = None
# url is stripped down web url, not including any other parameter
self.url = None
self.parent = None
self.source = None
self.branch = None
self.path = None
self.fetchto = None
self.revision = None
def __str__(self):
return self.raw_url
@property
def basename(self):
"""Get the basename for a module instance"""
if self.source == fetch.SVN:
return path_mod.svn_basename(self.url)
else:
return path_mod.url_basename(self.url)
def process_manifest(self):
"""Method that process the core manifest section"""
......@@ -73,42 +47,3 @@ class ModuleCore(ModulePlugin):
self.action = self.manifest_dict["action"].lower()
def _set_origin(self, parent, url, source, fetchto):
"""Calculate and initialize the origin attributes: path, source..."""
self.source = source
self.parent = parent
self.fetchto = fetchto
self.raw_url = url
if source != fetch.LOCAL:
self.url, self.branch, self.revision = path_mod.url_parse(url)
if (
os.path.exists(
os.path.abspath(
os.path.join(fetchto, self.basename)
)
) and
os.listdir(
os.path.abspath(os.path.join(fetchto, self.basename))
)
):
self.path = os.path.abspath(
os.path.join(fetchto, self.basename))
self.isfetched = True
logging.debug("Module %s (parent: %s) is fetched.",
url, parent.path)
else:
self.path = None
self.isfetched = False
logging.debug("Module %s (parent: %s) is NOT fetched.",
url, parent.path)
else:
self.url, self.branch, self.revision = url, None, None
if not os.path.exists(url):
logging.error(
"Path to the local module doesn't exist:\n" + url
+ "\nThis module was instantiated in: " + str(parent))
quit()
self.path = url
self.isfetched = True
......@@ -34,6 +34,7 @@ import logging
from hdlmake.manifest_parser import Manifest, ManifestParser
from hdlmake.util import path as path_mod
from hdlmake import fetch
from hdlmake.module import (ModuleCore, ModuleSynthesis,
ModuleSimulation, ModuleContent, ModuleAltera)
......@@ -63,7 +64,47 @@ class Module(ModuleCore, ModuleSynthesis,
self.isparsed = False
self.top_entity = None
self._set_origin(parent, url, source, fetchto)
"""Calculate and initialize the origin attributes: path, source..."""
self.source = source
self.parent = parent
self.fetchto = fetchto
self.raw_url = url
if source != fetch.LOCAL:
self.url, self.branch, self.revision = path_mod.url_parse(url)
if (
os.path.exists(
os.path.abspath(
os.path.join(fetchto, self.basename)
)
) and
os.listdir(
os.path.abspath(os.path.join(fetchto, self.basename))
)
):
self.path = os.path.abspath(
os.path.join(fetchto, self.basename))
self.isfetched = True
logging.debug("Module %s (parent: %s) is fetched.",
url, parent.path)
else:
self.path = None
self.isfetched = False
logging.debug("Module %s (parent: %s) is NOT fetched.",
url, parent.path)
else:
self.url, self.branch, self.revision = url, None, None
if not os.path.exists(url):
logging.error(
"Path to the local module doesn't exist:\n" + url
+ "\nThis module was instantiated in: " + str(parent))
quit()
self.path = url
self.isfetched = True
def __str__(self):
return self.raw_url
@property
......@@ -71,6 +112,16 @@ class Module(ModuleCore, ModuleSynthesis,
"""Get the path where the module instance resides"""
return os.path.dirname(self.path)
@property
def basename(self):
"""Get the basename for a module instance"""
if self.source == fetch.SVN:
return path_mod.svn_basename(self.url)
else:
return path_mod.url_basename(self.url)
def submodules(self):
"""Get a list with all the submodules this module instance requires"""
def __nonull(submodule_list):
......@@ -82,28 +133,6 @@ class Module(ModuleCore, ModuleSynthesis,
return __nonull(self.local) + __nonull(self.git) \
+ __nonull(self.svn) + __nonull(self.git_submodules)
def _search_for_manifest(self):
"""
Look for manifest in the given folder
"""
logging.debug("Looking for manifest in " + self.path)
dir_files = os.listdir(self.path)
if "manifest.py" in dir_files and "Manifest.py" in dir_files:
logging.error(
"Both manifest.py and Manifest.py" +
"found in the module directory: %s",
self.path)
sys.exit("\nExiting")
for filename in dir_files:
if filename == "manifest.py" or filename == "Manifest.py":
if not os.path.isdir(filename):
logging.debug("Found manifest for module %s: %s",
self.path, filename)
path_aux = os.path.join(self.path, filename)
manifest = Manifest(path=os.path.abspath(path_aux))
return manifest
return None
def remove_dir_from_disk(self):
"""Delete the module dir if it is already fetched and available"""
......@@ -151,8 +180,8 @@ class Module(ModuleCore, ModuleSynthesis,
return
if self.isparsed is True or self.isfetched is False:
return
if self.manifest is None:
self.manifest = self._search_for_manifest()
#if self.manifest is None:
# self.manifest = manifest_parser.search_for_manifest()
if self.path is None:
raise RuntimeError()
......@@ -162,22 +191,17 @@ class Module(ModuleCore, ModuleSynthesis,
#manifest_parser.add_arbitrary_code(
# self.pool.top_module.options.arbitrary_code)
if self.manifest is None:
logging.debug("No manifest found in module "+str(self))
else:
logging.debug("Parse manifest in: %s", self.path)
manifest_parser.add_manifest(self.manifest)
#if self.manifest is Non:
# logging.debug("No manifest found in module "+str(self))
#else:
# logging.debug("Parse manifest in: %s", self.path)
manifest_parser.add_manifest(self.path)
if self.parent is None:
extra_context = {}
else:
extra_context = dict(self.top_module.manifest_dict)
del extra_context["modules"]
del extra_context["files"]
del extra_context["include_dirs"]
del extra_context["sim_only_files"]
del extra_context["incl_makefiles"]
del extra_context["library"]
extra_context["__manifest"] = self.path
# The parse method is where the most of the parser action takes place!
......@@ -262,3 +286,6 @@ class Module(ModuleCore, ModuleSynthesis,
vlog_opt=self.vlog_opt,
include_dirs=self.include_dirs))
return srcs
......@@ -44,7 +44,6 @@ class ModulePool(list):
def __init__(self, *args):
list.__init__(self, *args)
self.top_module = None
self.global_fetch = os.getenv("HDLMAKE_COREDIR")
self._deps_solved = False
self.env = None
......@@ -90,11 +89,6 @@ class ModulePool(list):
if url in [m.raw_url for m in self]:
return [m for m in self if m.raw_url == url][0]
else:
# if there is global fetch parameter (HDLMAKE_COREDIR env variable)
# screw module's particular fetchto
if self.global_fetch:
fetchto = self.global_fetch
new_module = Module(parent=parent,
url=url, source=source,
fetchto=fetchto)
......
......@@ -234,7 +234,15 @@ class ConfigParser(object):
return [o.name for o in self.options if o is not None]
def parse(self, verbose=False, extra_context=None):
assert isinstance(extra_context, dict) or extra_context is None
# These hdlmake keys wont be inherited
key_purge_list = ["modules", "files", "include_dirs", "sim_only_files",
"inc_makefiles", "library"]
for key_to_be_deleted in key_purge_list:
extra_context.pop(key_to_be_deleted, None)
options = {}
ret = {}
......
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