runCmd will start __main__ by default.

This commit is contained in:
Sleepy Monax 2023-11-14 21:39:43 +01:00
parent 16e321d82f
commit bbe2d1d387
4 changed files with 26 additions and 8 deletions

View file

@ -170,7 +170,6 @@ def gen(out: TextIO, target: model.Target, registry: model.Registry):
w.variable("cdefs", " ".join(aggregateCdefs(target))) w.variable("cdefs", " ".join(aggregateCdefs(target)))
w.newline() w.newline()
w.rule("cp", "cp $in $out")
for i in target.tools: for i in target.tools:
tool = target.tools[i] tool = target.tools[i]
rule = rules.rules[i] rule = rules.rules[i]
@ -251,11 +250,8 @@ def runCmd(args: cli.Args):
target = model.Target.use(args) target = model.Target.use(args)
debug = args.consumeOpt("debug", False) is True debug = args.consumeOpt("debug", False) is True
componentSpec = args.consumeArg() componentSpec = args.consumeArg() or "__main__"
if componentSpec is None: component = registry.lookup(componentSpec, model.Component, includeProvides=True)
raise RuntimeError("No component specified")
component = registry.lookup(componentSpec, model.Component)
if component is None: if component is None:
raise RuntimeError(f"Component {componentSpec} not found") raise RuntimeError(f"Component {componentSpec} not found")

View file

@ -123,7 +123,10 @@ def helpCmd(args: Args):
print() print()
vt100.title("Commands") vt100.title("Commands")
for cmd in sorted(commands, key=lambda c: c.shortName or c.longName): for cmd in sorted(commands, key=lambda c: c.longName):
if cmd.longName.startswith("_"):
continue
pluginText = "" pluginText = ""
if cmd.isPlugin: if cmd.isPlugin:
pluginText = f"{vt100.CYAN}(plugin){vt100.RESET}" pluginText = f"{vt100.CYAN}(plugin){vt100.RESET}"

View file

@ -6,6 +6,7 @@ from enum import Enum
from typing import Any, Generator, Optional, Type, cast from typing import Any, Generator, Optional, Type, cast
from pathlib import Path from pathlib import Path
from dataclasses_json import DataClassJsonMixin from dataclasses_json import DataClassJsonMixin
import dataclasses
from dataclasses import dataclass, field from dataclasses import dataclass, field
from cutekit import const, shell from cutekit import const, shell
@ -243,6 +244,10 @@ class Tool(DataClassJsonMixin):
Tools = dict[str, Tool] Tools = dict[str, Tool]
DEFAULT_TOOLS: Tools = {
"cp": Tool("cp"),
}
@dataclass @dataclass
class Target(Manifest): class Target(Manifest):
@ -472,7 +477,9 @@ class Registry(DataClassJsonMixin):
if resolve.enabled: if resolve.enabled:
yield c yield c
def lookup(self, name: str, type: Type[utils.T]) -> Optional[utils.T]: def lookup(
self, name: str, type: Type[utils.T], includeProvides: bool = False
) -> Optional[utils.T]:
""" """
Lookup a manifest of a given type by name Lookup a manifest of a given type by name
""" """
@ -482,6 +489,11 @@ class Registry(DataClassJsonMixin):
if isinstance(m, type): if isinstance(m, type):
return m return m
if includeProvides and type is Component:
for m in self.iter(Component):
if name in m.provides:
return m
return None return None
def ensure(self, name: str, type: Type[utils.T]) -> utils.T: def ensure(self, name: str, type: Type[utils.T]) -> utils.T:
@ -576,6 +588,12 @@ class Registry(DataClassJsonMixin):
# Resolve tooling # Resolve tooling
tools: Tools = target.tools tools: Tools = target.tools
# Merge in default tools
for k, v in DEFAULT_TOOLS.items():
if k not in tools:
tools[k] = dataclasses.replace(v)
from . import mixins as mxs from . import mixins as mxs
for mix in mixins: for mix in mixins:

View file

@ -27,6 +27,7 @@ class Rule:
rules: dict[str, Rule] = { rules: dict[str, Rule] = {
"cp": Rule("cp", ["*"], ["*"], "$in $out"),
"cc": Rule( "cc": Rule(
"cc", "cc",
["*.c"], ["*.c"],