Code refactoring for improved actions handling

parent e05413e6
......@@ -104,37 +104,8 @@ def main():
modules_pool.process_top_module_manifest()
#
# Load global tool object (global_mod.py)
#
if not top_mod.action:
logging.error("`action' manifest variable has to be specified. "
"Otherwise hdlmake doesn't know how to handle the project")
quit()
if top_mod.action == "synthesis":
if not top_mod.syn_tool:
logging.error("`syn_tool' manifest variable has to be specified. "
"Otherwise hdlmake doesn't know how to synthesize the project")
quit()
tool_name = top_mod.syn_tool
elif top_mod.action == "simulation":
if not top_mod.sim_tool:
logging.error("`sim_tool' manifest variable has to be specified. "
"Otherwise hdlmake doesn't know how to simulate the project")
quit()
tool_name = top_mod.sim_tool
logging.debug('import tool module: ' + tool_name)
try:
tool_module = importlib.import_module("hdlmake.tools.%s.%s" % (tool_name, tool_name))
except Exception as e:
logging.error(e)
quit()
global_mod.tool_module = tool_module
#env.top_module = modules_pool.get_top_module()
env.check_env(verbose=False)
#env.check_env(verbose=False)
#env.check_env_wrt_manifest(verbose=False)
......@@ -146,16 +117,13 @@ def main():
if options.command == "check-env":
env.check_env(verbose=True)
quit()
if options.command == "check-manifest":
elif options.command == "check-manifest":
env.check_manifest(modules_pool.get_top_module().manifest, verbose=True)
quit()
if options.command == "manifest-help":
elif options.command == "manifest-help":
ManifestParser().print_help()
quit()
if options.command == "auto":
elif options.command == "auto":
logging.info("Running automatic flow.")
if not top_mod.action:
logging.error("`action' manifest variable has to be specified. "
......@@ -177,18 +145,12 @@ def main():
GenerateSynthesisMakefile,
GenerateRemoteSynthesisMakefile
]
# TODO: I advocate for removing the remote options -- too much pain, too little gain!!
# Why shouldn't we directly use ssh, screen, scp and rsync on a remote HDLMake deployment??
#elif options.command == "make-simulation":
# action = [ GenerateSimulationMakefile ]
#elif options.command == "make-fetch":
# action = [ GenerateFetchMakefile ]
#elif options.command == "make-ise":
# action = [ GenerateSynthesisMakefile ]
#elif options.command == "make-remote":
# action = [ GenerateRemoteSynthesisMakefile ]
elif options.command == "make-simulation":
action = [ GenerateSimulationMakefile ]
elif options.command == "make-fetch":
action = [ GenerateFetchMakefile ]
elif options.command == "make-remote":
action = [ GenerateRemoteSynthesisMakefile ]
elif options.command == "fetch":
action = [ FetchModules ]
elif options.command == "clean":
......@@ -199,10 +161,6 @@ def main():
action = [ ListFiles ]
elif options.command == "merge-cores":
action = [ MergeCores ]
elif options.command == "ise-project":
action = [ GenerateSynthesisProject ]
elif options.command == "quartus-project":
action = [ GenerateSynthesisProject ]
elif options.command == "project":
action = [ GenerateSynthesisProject ]
......
......@@ -23,6 +23,7 @@
import logging
import os
import sys
import importlib
from hdlmake import global_mod
from hdlmake.srcfile import SourceFileFactory
......@@ -45,10 +46,17 @@ class GenerateRemoteSynthesisMakefile(Action):
def run(self):
self._check_all_fetched_or_quit()
self._check_manifest()
tool_object = global_mod.tool_module.ToolControls()
tool_name = self.modules_pool.get_top_module().syn_tool
try:
tool_module = importlib.import_module("hdlmake.tools.%s.%s" % (tool_name, tool_name))
except Exception as e:
logging.error(e)
quit()
tool_object = tool_module.ToolControls()
self._generate_remote_synthesis_makefile(tool_object)
#def _search_tcl_file(self, directory=None):
# # This function is used in _generate_remote_ise_makefile
# if directory is None:
......@@ -80,6 +88,9 @@ class GenerateRemoteSynthesisMakefile(Action):
top_mod = self.modules_pool.get_top_module()
self.env.check_remote_tool(tool_object)
self.env.check_general()
#tcl = self._search_tcl_file()
#if tcl is None:
# self._generate_tcl()
......
......@@ -23,6 +23,7 @@
from __future__ import print_function
import logging
import sys
import importlib
from hdlmake.dep_file import DepFile
import hdlmake.new_dep_solver as dep_solver
......@@ -44,9 +45,14 @@ class GenerateSimulationMakefile(Action):
def run(self):
self._check_all_fetched_or_quit()
self._check_manifest()
tool_object = global_mod.tool_module.ToolControls()
tool_name = self.modules_pool.get_top_module().sim_tool
try:
tool_module = importlib.import_module("hdlmake.tools.%s.%s" % (tool_name, tool_name))
except Exception as e:
logging.error(e)
quit()
tool_object = tool_module.ToolControls()
self._generate_simulation_makefile(tool_object)
logging.info("Simulation makefile generated.")
def _generate_simulation_makefile(self, tool_object):
......@@ -60,6 +66,10 @@ class GenerateSimulationMakefile(Action):
path_key = tool_info['id'] + '_path'
version_key = tool_info['id'] + '_version'
name = tool_info['name']
self.env.check_tool(tool_object)
self.env.check_general()
if self.env[path_key] is None and self.options.force is not True:
logging.error("Can't generate a " + name + " makefile. " + bin_name + " not found.")
......
......@@ -23,6 +23,7 @@
from __future__ import print_function
import logging
import sys
import importlib
from hdlmake import global_mod
......@@ -44,7 +45,13 @@ class GenerateSynthesisMakefile(Action):
def run(self):
self._check_all_fetched_or_quit()
self._check_manifest()
tool_object = global_mod.tool_module.ToolControls()
tool_name = self.modules_pool.get_top_module().syn_tool
try:
tool_module = importlib.import_module("hdlmake.tools.%s.%s" % (tool_name, tool_name))
except Exception as e:
logging.error(e)
quit()
tool_object = tool_module.ToolControls()
self._generate_synthesis_makefile(tool_object)
......
......@@ -24,6 +24,7 @@ from __future__ import print_function
import logging
import sys
import os
import importlib
from hdlmake.srcfile import SourceFileFactory
from hdlmake.dependable_file import DependableFile
......@@ -55,7 +56,13 @@ class GenerateSynthesisProject(Action):
def run(self):
self._check_all_fetched_or_quit()
self._check_manifest()
tool_object = global_mod.tool_module.ToolControls()
tool_name = self.modules_pool.get_top_module().syn_tool
try:
tool_module = importlib.import_module("hdlmake.tools.%s.%s" % (tool_name, tool_name))
except Exception as e:
logging.error(e)
quit()
tool_object = tool_module.ToolControls()
self._generate_synthesis_project(tool_object)
......@@ -143,6 +150,9 @@ end sdb_meta_pkg;""")
ext_value = tool_info['project_ext']
env = self.env
env.check_general()
env.check_tool(tool_object)
if not self.options.force:
if self.env[path_key] is None:
logging.error("Can't generate the " + name + " project. " + name + " not found.")
......
......@@ -70,10 +70,10 @@ class Env(dict):
def check_env(self, verbose=True):
print.set_verbose(verbose)
# Check and determine general environment
self._check_general()
tool_object = global_mod.tool_module.ToolControls()
self._check_tool(tool_object)
self._check_remote_tool(tool_object)
self.check_general()
#tool_object = global_mod.tool_module.ToolControls()
#self._check_tool(tool_object)
#self._check_remote_tool(tool_object)
def _get(self, name):
......@@ -105,7 +105,7 @@ class Env(dict):
return False
def _check_general(self):
def check_general(self):
self["architecture"] = 64 if _64bit_architecture else 32
self["platform"] = sys.platform
print("Architecture: %s" % self["architecture"])
......@@ -120,7 +120,7 @@ class Env(dict):
print("'fetchto' variables in the manifests will be respected when fetching.")
def _check_tool(self, info_class):
def check_tool(self, info_class):
tool_info = info_class.get_keys()
if sys.platform == 'cygwin':
......@@ -150,7 +150,7 @@ class Env(dict):
print("Detected " + name +" version %s" % self[version_key])
def _check_remote_tool(self, info_class):
def check_remote_tool(self, info_class):
tool_info = info_class.get_keys()
remote_path_key = 'rsynth_' + tool_info['id'] + '_path'
......
......@@ -28,6 +28,5 @@ top_module = None
mod_pool = None
sim_tool = None
env = None
tool_module = None
makefile_writer = None
current_path = None
......@@ -90,8 +90,8 @@ def solve(fileset):
continue
if rel.rel_type is DepRelation.INCLUDE: # INCLUDE are already solved by preprocessor
continue
if rel.library() in global_mod.tool_module.ToolControls().get_standard_libraries(): # dont care about standard libs
continue
#if rel.library() in global_mod.tool_module.ToolControls().get_standard_libraries(): # dont care about standard libs
# continue
satisfied_by = set()
for dep_file in fset:
# if dep_file is investigated_file:
......
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