Commit 43d55c33 authored by Tristan Gingold's avatar Tristan Gingold

Merge branch '92-quit-functions-should-not-be-called-outside-of-try-except-blocks' into 'master'

Resolve "quit functions should not be called outside of try/except blocks"

Closes #92

See merge request !4
parents 7c97452f 2ff181e5
......@@ -38,7 +38,7 @@ def set_logging_level(options):
"""Set the log level and config (A.K.A. log verbosity)"""
numeric_level = getattr(logging, options.log.upper(), None)
if not isinstance(numeric_level, int):
sys.exit('Invalid log level: %s' % options.log)
raise Exception('Invalid log level: %s' % options.log)
if not shell.check_windows() and options.logfile == None:
logging.basicConfig(
......@@ -92,8 +92,7 @@ class Action(list):
self.config["syn_top"] = self.config["top_module"]
self.top_entity = self.config.get("syn_top")
else:
logging.error("Unknown requested action: %s", action)
quit(1)
raise Exception("Unknown requested action: %s", action)
def new_module(self, parent, url, source, fetchto):
"""Add new module to the pool.
......@@ -118,11 +117,10 @@ class Action(list):
def _check_manifest_variable_is_set(self, name):
"""Method to check if a specific manifest variable is set"""
if getattr(self.top_module, name) is None:
logging.error(
raise Exception(
"Variable %s must be set in the manifest "
"to perform current action (%s)",
name, self.__class__.__name__)
sys.exit("\nExiting")
def _check_manifest_variable_value(self, name, value):
"""Method to check if a manifest variable is set to a specific value"""
......@@ -132,10 +130,9 @@ class Action(list):
variable_match = True
if variable_match is False:
logging.error(
raise Exception(
"Variable %s must be set in the manifest and equal to '%s'.",
name, value)
sys.exit("Exiting")
def build_complete_file_set(self):
"""Build file set with all the files listed in the complete pool"""
......
......@@ -51,12 +51,11 @@ class ActionCore(Action):
"""Check if every module in the pool is fetched"""
if not len([m for m in self if not m.isfetched]) == 0:
logging.error(
raise Exception(
"Fetching should be done before continuing.\n"
"The following modules remains unfetched:\n"
"%s",
"\n".join([str(m) for m in self if not m.isfetched]))
quit(1)
def makefile(self):
"""Write the Makefile for the current design"""
self._check_all_fetched()
......@@ -84,8 +83,7 @@ class ActionCore(Action):
elif module.source is LOCAL:
result = self.local_backend.fetch(module)
if result is False:
logging.error("Unable to fetch module %s", str(module.url))
sys.exit("Exiting")
raise Exception("Unable to fetch module %s", str(module.url))
module.parse_manifest()
new_modules.extend(module.local)
new_modules.extend(module.svn)
......
......@@ -44,8 +44,7 @@ class ActionTree(Action):
import networkx as nx
from networkx.readwrite import json_graph
except ImportError as error_import:
logging.error(error_import)
quit(1)
raise Exception(error_import)
if self.options.mode == 'dfs':
hierarchy = nx.dfs_tree(hierarchy, top_id)
elif self.options.mode == 'bfs':
......@@ -61,8 +60,7 @@ class ActionTree(Action):
try:
import networkx as nx
except ImportError as error_import:
logging.error(error_import)
quit(1)
raise Exception(error_import)
unfetched_modules = False
hierarchy = nx.DiGraph()
......@@ -116,8 +114,7 @@ class ActionTree(Action):
top_level_entity)
else:
logging.error('Unknown tree mode: %s', self.options.mode)
quit(1)
raise Exception('Unknown tree mode: %s', self.options.mode)
if unfetched_modules:
logging.warning("Some of the modules have not been fetched!")
......
......@@ -308,15 +308,13 @@ types:[<type 'int'>]
for line in printed.split('\n'):
print("> " + line)
except SyntaxError as error_syntax:
logging.error("Invalid syntax in the manifest file " +
self.config_file + ":\n" + str(error_syntax))
logging.error(content)
quit(1)
raise Exception("Invalid syntax in the manifest file " +
self.config_file + ":\n" + str(error_syntax) +
content)
except SystemExit as error_exit:
logging.error("Exit requested by the manifest file " +
self.config_file + ":\n" + str(error_exit))
logging.error(content)
quit(1)
raise Exception("Exit requested by the manifest file " +
self.config_file + ":\n" + str(error_exit) +
content)
except:
logging.error("Encountered unexpected error while parsing " +
self.config_file)
......
......@@ -276,11 +276,10 @@ class ManifestParser(ConfigParser):
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(
raise Exception(
"Both manifest.py and Manifest.py" +
"found in the module directory: %s",
path)
quit(1)
for filename in dir_files:
if filename == "manifest.py" or filename == "Manifest.py":
if not os.path.isdir(filename):
......@@ -296,8 +295,7 @@ class ManifestParser(ConfigParser):
return None
manifest = _search_for_manifest(path)
if manifest is None:
logging.error("No manifest found in path: %s", path)
quit(1)
raise Exception("No manifest found in path: %s", path)
else:
logging.debug("Parse manifest in: %s", manifest)
return self.add_config_file(manifest)
......
......@@ -100,9 +100,8 @@ class ModuleContent(ModuleCore):
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 + ")")
quit(1)
raise Exception("Found an absolute path (" + path +
") in a manifest(" + self.path + ")")
path = path_mod.rel2abs(path, self.path)
local_mods.append(self.pool.new_module(parent=self,
url=path,
......
......@@ -75,10 +75,9 @@ class ModuleConfig(object):
self.url, self.branch, self.revision = url, None, None
if not os.path.exists(url):
logging.error(
raise Exception(
"Path to the local module doesn't exist:\n" + url
+ "\nThis module was instantiated in: " + str(self.parent))
quit(1)
self.path = path_mod.relpath(url)
self.isfetched = True
......@@ -92,10 +91,9 @@ class ModuleConfig(object):
return False
filepath = os.path.join(self.path, filepath)
if not os.path.exists(filepath):
logging.error(
raise Exception(
"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):
......
......@@ -166,10 +166,9 @@ PARSE START: %s
try:
opt_map = manifest_parser.parse(extra_context=extra_context)
except NameError as name_error:
logging.error(
raise Exception(
"Error while parsing {0}:\n{1}: {2}.".format(
self.path, type(name_error), name_error))
quit(1)
self.manifest_dict = opt_map
else:
self.manifest_dict = {}
......
......@@ -436,7 +436,6 @@ def create_source_file(path, module, library=None,
elif extension in MICROSEMI_FILE_DICT:
new_file = MICROSEMI_FILE_DICT[extension](path=path, module=module)
else:
logging.error("Cannot create source file %s, "
"unknown file extension %s", path, extension)
quit(1)
raise Exception("Cannot create source file %s, "
"unknown file extension %s", path, extension)
return new_file
......@@ -139,10 +139,9 @@ $(TCL_CLOSE)'''
syn_family = FAMILY_NAMES.get(
self.manifest_dict["syn_device"][0:4].upper())
if syn_family is None:
logging.error(
raise Exception(
"syn_family is not defined in Manifest.py"
" and can not be guessed!")
quit(-1)
self.manifest_dict["syn_family"] = syn_family
super(ToolISE, self)._makefile_syn_top()
......
......@@ -75,8 +75,7 @@ class ToolISim(ToolSim):
xilinx_dir = str(os.path.join(
self.manifest_dict["sim_path"], "..", ".."))
else:
logging.error("Cannot calculate xilinx tools base directory")
quit(1)
raise Exception("Cannot calculate xilinx tools base directory")
hdl_language = 'vhdl' # 'verilog'
if shell.check_windows():
os_prefix = 'nt'
......
......@@ -14,11 +14,9 @@ from hdlmake.srcfile import VerilogFile, VHDLFile, SVFile
def _check_simulation_manifest(manifest_dict):
"""Check if the simulation keys are provided by the top manifest"""
if not manifest_dict["sim_top"]:
logging.error("sim_top variable must be set in the top manifest.")
sys.exit("Exiting")
raise Exception("sim_top variable must be set in the top manifest.")
if not manifest_dict["sim_tool"]:
logging.error("sim_tool variable must be set in the top manifest.")
sys.exit("Exiting")
raise Exception("sim_tool variable must be set in the top manifest.")
class ToolSim(ToolMakefile):
......
......@@ -14,21 +14,17 @@ from hdlmake.srcfile import VerilogFile, SVFile
def _check_synthesis_manifest(manifest_dict):
"""Check the manifest contains all the keys for a synthesis project"""
if not manifest_dict["syn_tool"]:
logging.error(
raise Exception(
"syn_tool variable must be set in the top manifest.")
sys.exit("Exiting")
if not manifest_dict["syn_device"]:
logging.error(
raise Exception(
"syn_device variable must be set in the top manifest.")
sys.exit("Exiting")
if not manifest_dict["syn_grade"]:
logging.error(
raise Exception(
"syn_grade variable must be set in the top manifest.")
sys.exit("Exiting")
if not manifest_dict["syn_package"]:
logging.error(
raise Exception(
"syn_package variable must be set in the top manifest.")
sys.exit("Exiting")
if not manifest_dict["syn_top"]:
logging.error(
"syn_top variable must be set in the top manifest.")
......
......@@ -24,9 +24,8 @@ def load_syn_tool(tool_name):
logging.debug("Synthesis tool to be used found: %s", tool_name)
return available_tools[tool_name]()
else:
logging.error("Unknown synthesis tool: %s", tool_name)
logging.error(" Supported synthesis tools are %s", available_tools.keys())
quit(1)
raise Exception("Unknown synthesis tool: %s" + tool_name
+ " Supported synthesis tools are %s" + available_tools.keys())
def load_sim_tool(tool_name):
......@@ -50,6 +49,5 @@ def load_sim_tool(tool_name):
logging.debug("Simulation tool to be used found: %s", tool_name)
return available_tools[tool_name]()
else:
logging.error("Unknown simulation tool: %s", tool_name)
logging.error(" Supported simulation tools are %s", available_tools.keys())
quit(1)
raise Exception("Unknown simulation tool: %s" + tool_name
+ " Supported simulation tools are %s" + available_tools.keys())
......@@ -135,9 +135,8 @@ class ToolQuartus(ToolSyn):
"Auto-guessed syn_family to be %s (%s => %s)",
family, device, key)
if family is None:
logging.error("Could not auto-guess device family, please "
"specify in Manifest.py using syn_family!")
sys.exit("\nExiting")
raise Exception("Could not auto-guess device family, please "
"specify in Manifest.py using syn_family!")
return family
family_string = __get_family_string(
......@@ -202,9 +201,8 @@ class ToolQuartus(ToolSyn):
'value': '$(TOP_MODULE)'}))
for user_property in self.manifest_dict.get("syn_properties", []):
if not isinstance(user_property, dict):
logging.error("Quartus property should be defined as dict: "
+ str(user_property))
quit(1)
raise Exception("Quartus property should be defined as dict: "
+ str(user_property))
command_list.append(self._emit_property(self.SET_GLOBAL_ASSIGNMENT,
user_property))
for inc in self.manifest_dict.get("include_dirs", []):
......@@ -221,10 +219,9 @@ class ToolQuartus(ToolSyn):
path = shell.tclpath(path_mod.compose(
self.manifest_dict["quartus_preflow"], os.getcwd()))
if not os.path.exists(path):
logging.error("quartus_preflow file listed in "
+ os.getcwd() + " doesn't exist: "
+ path + ".\nExiting.")
quit(1)
raise Exception("quartus_preflow file listed in "
+ os.getcwd() + " doesn't exist: "
+ path + ".\nExiting.")
preflow = '"' + 'quartus_sh:' + path + '"'
command_list.append(self._emit_property(self.SET_GLOBAL_ASSIGNMENT,
{'name': 'PRE_FLOW_SCRIPT_FILE',
......@@ -234,10 +231,9 @@ class ToolQuartus(ToolSyn):
self.manifest_dict["quartus_postmodule"],
os.getcwd()))
if not os.path.exists(path):
logging.error("quartus_postmodule file listed in "
+ os.getcwd() + " doesn't exist: "
+ path + ".\nExiting.")
quit(1)
raise Exception("quartus_postmodule file listed in "
+ os.getcwd() + " doesn't exist: "
+ path + ".\nExiting.")
postmodule = '"' + 'quartus_sh:' + path + '"'
command_list.append(self._emit_property(self.SET_GLOBAL_ASSIGNMENT,
{'name': 'POST_MODULE_SCRIPT_FILE',
......@@ -246,10 +242,9 @@ class ToolQuartus(ToolSyn):
path = shell.tclpath(path_mod.compose(
self.manifest_dict["quartus_postflow"], os.getcwd()))
if not os.path.exists(path):
logging.error("quartus_postflow file listed in "
+ os.getcwd() + " doesn't exist: "
+ path + ".\nExiting.")
quit(1)
raise Exception("quartus_postflow file listed in "
+ os.getcwd() + " doesn't exist: "
+ path + ".\nExiting.")
postflow = '"' + 'quartus_sh:' + path + '"'
command_list.append(self._emit_property(self.SET_GLOBAL_ASSIGNMENT,
{'name': 'POST_FLOW_SCRIPT_FILE',
......
......@@ -119,10 +119,9 @@ class VerilogPreprocessor(object):
probable_file = os.path.join(searchdir, filename)
if os.path.isfile(probable_file):
return os.path.abspath(probable_file)
logging.error("Can't find %s for %s in any of the include "
"directories: %s", filename, self.vlog_file.file_path,
', '.join(self.vlog_file.include_dirs))
sys.exit("\nExiting")
raise Exception("Can't find %s for %s in any of the include "
"directories: %s", filename, self.vlog_file.file_path,
', '.join(self.vlog_file.include_dirs))
def _parse_macro_def(self, macro):
"""Parse the provided 'macro' and, if it's not a reserved keyword,
......@@ -135,8 +134,7 @@ class VerilogPreprocessor(object):
else:
params = []
if name in self.vpp_keywords:
logging.error("Attempt to `define a reserved preprocessor keyword")
quit(1)
raise Exception("Attempt to `define a reserved preprocessor keyword")
mdef = self.VLDefine(name, params, expansion)
self.vpp_macros.append(mdef)
return mdef
......
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