Skip to content

Commit

Permalink
Merge pull request #1840 from motec-research/parser_set_defaults_impr…
Browse files Browse the repository at this point in the history
…ovements

Parser set defaults improvements
  • Loading branch information
enjoy-digital authored Jun 21, 2024
2 parents f40f63a + 0f7ea96 commit 29bdf68
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion litex/build/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,21 @@ def parse_args(self, args=None, namespace=None):
self._platform.fill_args(self._toolchain, self)

# Intercept selected CPU to fill arguments.
cpu_cls = cpu.CPUS.get(self.get_value_from_key("--cpu-type"), None)
default_cpu_type = self._args_default.get("cpu_type", None)
cpu_cls = cpu.CPUS.get(self.get_value_from_key("--cpu-type", default_cpu_type))
if cpu_cls is not None and hasattr(cpu_cls, "args_fill"):
cpu_cls.args_fill(self)

# Injects arguments default values
if len(self._args_default):
argparse.ArgumentParser.set_defaults(self, **self._args_default)
# Catch defaults which do not match any arguments - typos?
remaining = list(self._args_default.keys())
for action in self._actions:
if action.dest in remaining:
remaining.remove(action.dest)
if len(remaining) > 0:
raise ValueError(f"set_default() for invalid argument(s): {remaining}")

# Parse args.
self._args = argparse.ArgumentParser.parse_args(self, args, namespace)
Expand Down

0 comments on commit 29bdf68

Please sign in to comment.