Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser set defaults improvements #1840

Merged
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
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}")
Comment on lines +233 to +234
Copy link
Collaborator

Choose a reason for hiding this comment

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

Having a test and/or a message looks good, but raising an exception may, potentially being a problem for users:

  • if in a target I set cpu_type=vexriscv_smp and dtlb_size=xxx
  • if a user decide to use --cpu-type=naxriscv

An exception will occur because dtlb_size is something specific to the vexriscv_smp.

Maybe it's better here to displays a message (similar to compat_notice) with unused/unknown arguments list with and a delay to warn user about situation. Otherwise user has to modifiy target to remove/comment default and it's not really user friendly.


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