Added wait option to debbuger
This commit is contained in:
parent
594953ea68
commit
1fd19e757a
4 changed files with 40 additions and 19 deletions
|
@ -15,8 +15,8 @@ class Scope:
|
||||||
registry: model.Registry
|
registry: model.Registry
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def use(args: cli.Args) -> "Scope":
|
def use(args: cli.Args, props: model.Props = {}) -> "Scope":
|
||||||
registry = model.Registry.use(args)
|
registry = model.Registry.use(args, props)
|
||||||
return Scope(registry)
|
return Scope(registry)
|
||||||
|
|
||||||
def key(self) -> str:
|
def key(self) -> str:
|
||||||
|
@ -32,9 +32,9 @@ class TargetScope(Scope):
|
||||||
target: model.Target
|
target: model.Target
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def use(args: cli.Args) -> "TargetScope":
|
def use(args: cli.Args, props: model.Props = {}) -> "TargetScope":
|
||||||
registry = model.Registry.use(args)
|
registry = model.Registry.use(args, props)
|
||||||
target = model.Target.use(args)
|
target = model.Target.use(args, props)
|
||||||
return TargetScope(registry, target)
|
return TargetScope(registry, target)
|
||||||
|
|
||||||
def key(self) -> str:
|
def key(self) -> str:
|
||||||
|
@ -151,7 +151,7 @@ def compile(
|
||||||
res: list[str] = []
|
res: list[str] = []
|
||||||
for src in srcs:
|
for src in srcs:
|
||||||
rel = Path(src).relative_to(scope.component.dirname())
|
rel = Path(src).relative_to(scope.component.dirname())
|
||||||
dest = buildpath(scope, path="__obj__") / rel.with_suffix(".o")
|
dest = buildpath(scope, path="__obj__") / rel.with_suffix(rel.suffix + ".o")
|
||||||
t = scope.target.tools[rule]
|
t = scope.target.tools[rule]
|
||||||
w.build(str(dest), rule, inputs=src, order_only=t.files)
|
w.build(str(dest), rule, inputs=src, order_only=t.files)
|
||||||
res.append(str(dest))
|
res.append(str(dest))
|
||||||
|
@ -353,12 +353,12 @@ def _(args: cli.Args):
|
||||||
|
|
||||||
@cli.command("r", "builder/run", "Run a component")
|
@cli.command("r", "builder/run", "Run a component")
|
||||||
def runCmd(args: cli.Args):
|
def runCmd(args: cli.Args):
|
||||||
scope = TargetScope.use(args)
|
|
||||||
debug = args.consumeOpt("debug", False) is True
|
debug = args.consumeOpt("debug", False) is True
|
||||||
|
wait = args.consumeOpt("wait", False) is True
|
||||||
debugger = args.consumeOpt("debugger", "lldb")
|
debugger = args.consumeOpt("debugger", "lldb")
|
||||||
|
|
||||||
componentSpec = args.consumeArg() or "__main__"
|
componentSpec = args.consumeArg() or "__main__"
|
||||||
componentSpec = "__main__" if componentSpec == "--" else componentSpec
|
scope = TargetScope.use(args, {"debug": debug})
|
||||||
|
|
||||||
component = scope.registry.lookup(
|
component = scope.registry.lookup(
|
||||||
componentSpec, model.Component, includeProvides=True
|
componentSpec, model.Component, includeProvides=True
|
||||||
)
|
)
|
||||||
|
@ -373,13 +373,25 @@ def runCmd(args: cli.Args):
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
if debugger == "lldb":
|
if debugger == "lldb":
|
||||||
shell.exec("lldb", "-o", "run", str(product.path), *args.args)
|
shell.exec(
|
||||||
|
"lldb",
|
||||||
|
*(("-o", "b main") if wait else ()),
|
||||||
|
*("-o", "run"),
|
||||||
|
str(product.path),
|
||||||
|
*args.extra,
|
||||||
|
)
|
||||||
elif debugger == "gdb":
|
elif debugger == "gdb":
|
||||||
shell.exec("gdb", "-ex", "run", str(product.path), *args.args)
|
shell.exec(
|
||||||
|
"gdb",
|
||||||
|
*(("-ex", "b main") if wait else ()),
|
||||||
|
*("-ex", "run"),
|
||||||
|
str(product.path),
|
||||||
|
*args.extra,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(f"Unknown debugger {debugger}")
|
raise RuntimeError(f"Unknown debugger {debugger}")
|
||||||
else:
|
else:
|
||||||
shell.exec(str(product.path), *args.args)
|
shell.exec(str(product.path), *args.extra)
|
||||||
|
|
||||||
|
|
||||||
@cli.command("t", "builder/test", "Run all test targets")
|
@cli.command("t", "builder/test", "Run all test targets")
|
||||||
|
|
|
@ -16,10 +16,12 @@ _logger = logging.getLogger(__name__)
|
||||||
class Args:
|
class Args:
|
||||||
opts: dict[str, Value]
|
opts: dict[str, Value]
|
||||||
args: list[str]
|
args: list[str]
|
||||||
|
extra: list[str]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.opts = {}
|
self.opts = {}
|
||||||
self.args = []
|
self.args = []
|
||||||
|
self.extra = []
|
||||||
|
|
||||||
def consumePrefix(self, prefix: str) -> dict[str, Value]:
|
def consumePrefix(self, prefix: str) -> dict[str, Value]:
|
||||||
result: dict[str, Value] = {}
|
result: dict[str, Value] = {}
|
||||||
|
@ -56,13 +58,17 @@ class Args:
|
||||||
def parse(args: list[str]) -> Args:
|
def parse(args: list[str]) -> Args:
|
||||||
result = Args()
|
result = Args()
|
||||||
|
|
||||||
for arg in args:
|
for i in range(len(args)):
|
||||||
|
arg = args[i]
|
||||||
if arg.startswith("--") and not arg == "--":
|
if arg.startswith("--") and not arg == "--":
|
||||||
if "=" in arg:
|
if "=" in arg:
|
||||||
key, value = arg[2:].split("=", 1)
|
key, value = arg[2:].split("=", 1)
|
||||||
result.opts[key] = value
|
result.opts[key] = value
|
||||||
else:
|
else:
|
||||||
result.opts[arg[2:]] = True
|
result.opts[arg[2:]] = True
|
||||||
|
elif arg == "--":
|
||||||
|
result.extra += args[i + 1 :]
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
result.args.append(arg)
|
result.args.append(arg)
|
||||||
|
|
||||||
|
|
|
@ -287,8 +287,8 @@ class Target(Manifest):
|
||||||
return os.path.join(const.BUILD_DIR, f"{self.id}{postfix}")
|
return os.path.join(const.BUILD_DIR, f"{self.id}{postfix}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def use(args: cli.Args) -> "Target":
|
def use(args: cli.Args, props: Props = {}) -> "Target":
|
||||||
registry = Registry.use(args)
|
registry = Registry.use(args, props)
|
||||||
targetSpec = str(args.consumeOpt("target", "host-" + shell.uname().machine))
|
targetSpec = str(args.consumeOpt("target", "host-" + shell.uname().machine))
|
||||||
return registry.ensure(targetSpec, Target)
|
return registry.ensure(targetSpec, Target)
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ class Registry(DataClassJsonMixin):
|
||||||
return m
|
return m
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def use(args: cli.Args) -> "Registry":
|
def use(args: cli.Args, props: Props = {}) -> "Registry":
|
||||||
global _registry
|
global _registry
|
||||||
|
|
||||||
if _registry is not None:
|
if _registry is not None:
|
||||||
|
@ -546,8 +546,7 @@ class Registry(DataClassJsonMixin):
|
||||||
mixins = str(args.consumeOpt("mixins", "")).split(",")
|
mixins = str(args.consumeOpt("mixins", "")).split(",")
|
||||||
if mixins == [""]:
|
if mixins == [""]:
|
||||||
mixins = []
|
mixins = []
|
||||||
props = cast(dict[str, str], args.consumePrefix("prop:"))
|
props |= cast(dict[str, str], args.consumePrefix("prop:"))
|
||||||
|
|
||||||
_registry = Registry.load(project, mixins, props)
|
_registry = Registry.load(project, mixins, props)
|
||||||
return _registry
|
return _registry
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,11 @@ def podExecCmd(args: cli.Args):
|
||||||
if not name.startswith(podPrefix):
|
if not name.startswith(podPrefix):
|
||||||
name = f"{podPrefix}{name}"
|
name = f"{podPrefix}{name}"
|
||||||
|
|
||||||
|
cmd = args.consumeArg()
|
||||||
|
if cmd is None:
|
||||||
|
raise RuntimeError("Missing command to execute")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
shell.exec("docker", "exec", "-it", name, *args.args)
|
shell.exec("docker", "exec", "-it", name, cmd, *args.extra)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise RuntimeError(f"Pod '{name[len(podPrefix):]}' does not exist")
|
raise RuntimeError(f"Pod '{name[len(podPrefix):]}' does not exist")
|
||||||
|
|
Loading…
Add table
Reference in a new issue