Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _get_potential_debuggers(): # noqa


def _warn_meaningless_option(context, option):
if hasattr(context.options, "list_debuggers"):
if hasattr(context.options, "list-debuggers"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have thought list-debuggers isn't a valid variable name, I'm confused how this works?

return

context.logger.warning(
Expand Down
38 changes: 4 additions & 34 deletions cross-project-tests/debuginfo-tests/dexter/dex/tools/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,6 @@ def _output_bug_report_message(context):
)


def get_tools_directory():
"""Returns directory path where DExTer tool imports can be
found.
"""
tools_directory = os.path.join(get_root_directory(), "tools")
assert os.path.isdir(tools_directory), tools_directory
return tools_directory


def get_tool_names():
"""Returns a list of expected DExTer Tools"""
return [
"help",
"list-debuggers",
"no-tool-",
"run-debugger-internal-",
"test",
"view",
]


def _set_auto_highlights(context):
"""Flag some strings for auto-highlighting."""
context.o.auto_reds.extend(
Expand Down Expand Up @@ -118,6 +97,7 @@ def _is_valid_tool_name(tool_name):
"""check tool name matches a tool directory within the dexter tools
directory.
"""
from . import get_tool_names
valid_tools = get_tool_names()
if tool_name not in valid_tools:
raise Error(
Expand All @@ -127,17 +107,6 @@ def _is_valid_tool_name(tool_name):
)


def _import_tool_module(tool_name):
"""Imports the python module at the tool directory specificed by
tool_name.
"""
# format tool argument to reflect tool directory form.
tool_name = tool_name.replace("-", "_")

tools_directory = get_tools_directory()
return load_module(tool_name, tools_directory)


def tool_main(context, tool, args):
with Timer(tool.name):
options, defaults = tool.parse_command_line(args)
Expand Down Expand Up @@ -190,6 +159,7 @@ def __init__(self):


def main() -> ReturnCode:
from . import get_tools
context = Context()
with PrettyOutput() as context.o:
context.logger = Logger(context.o)
Expand All @@ -200,8 +170,8 @@ def main() -> ReturnCode:
options, args = _get_options_and_args(context)
# raises 'Error' if command line tool is invalid.
tool_name = _get_tool_name(options)
module = _import_tool_module(tool_name)
return tool_main(context, module.Tool(context), args)
T = get_tools()[tool_name]
return tool_main(context, T(context), args)
except Error as e:
context.logger.error(str(e))
try:
Expand Down
28 changes: 27 additions & 1 deletion cross-project-tests/debuginfo-tests/dexter/dex/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

from dex.tools.Main import Context, get_tool_names, get_tools_directory, main, tool_main
from dex.tools.Main import Context, main, tool_main
from dex.tools.TestToolBase import TestToolBase
from dex.tools.ToolBase import ToolBase

def get_tool_names():
"""Returns a list of expected DExTer Tools"""
return ["help", "list-debuggers", "no-tool-", "run-debugger-internal-", "test", "view"]

def get_tools():
"""Returns a dictionary of expected DExTer Tools"""
return _the_tools


from .help import Tool as help_tool
from .list_debuggers import Tool as list_debuggers_tool
from .no_tool_ import Tool as no_tool_tool
from .run_debugger_internal_ import Tool as run_debugger_internal_tool
from .test import Tool as test_tool
from .view import Tool as view_tool

_the_tools = {
"help" : help_tool,
"list-debuggers" : list_debuggers_tool,
"no_tool_" : no_tool_tool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no-tool- (hyphens instead of underscores) for consistency?

Note this is currently out of sync with the get_tool_names spelling. Perhaps get_tool_names should return list(_the_tools.keys())?

"run-debugger-internal-" : run_debugger_internal_tool,
"test" : test_tool,
"view" : view_tool
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import textwrap

from dex.tools import ToolBase, get_tool_names, get_tools_directory, tool_main
from dex.tools import ToolBase, get_tool_names, get_tools, tool_main
from dex.utils.Imports import load_module
from dex.utils.ReturnCode import ReturnCode

Expand Down Expand Up @@ -36,10 +36,8 @@ def handle_options(self, defaults):
@property
def _default_text(self):
s = "\n<b>The following subtools are available:</>\n\n"
tools_directory = get_tools_directory()
for tool_name in sorted(self._visible_tool_names):
internal_name = tool_name.replace("-", "_")
tool_doc = load_module(internal_name, tools_directory).Tool.__doc__
tool_doc = get_tools()[tool_name].__doc__
tool_doc = tool_doc.strip() if tool_doc else ""
tool_doc = textwrap.fill(" ".join(tool_doc.split()), 80)
s += "<g>{}</>\n{}\n\n".format(tool_name, tool_doc)
Expand All @@ -50,7 +48,5 @@ def go(self) -> ReturnCode:
self.context.o.auto(self._default_text)
return ReturnCode.OK

tool_name = self.context.options.tool.replace("-", "_")
tools_directory = get_tools_directory()
module = load_module(tool_name, tools_directory)
return tool_main(self.context, module.Tool(self.context), ["--help"])
T = get_tools()[tool_name]
return tool_main(self.context, T(self.context), ["--help"])

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading