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