From 4730ee22881f13d7a7f14af28c74f9595c4c68fe Mon Sep 17 00:00:00 2001 From: Andrew Dennison Date: Mon, 11 Sep 2023 12:30:58 +1000 Subject: [PATCH 1/2] build/parser: support set_default(cpu_type="xxx") Ensures args_fill() for new cpu_type is called, allowing for patterns in a target file like: parser.set_defaults(cpu_type="vexriscv_smp") parser.set_defaults(cpu_variant="linux") parser.set_defaults(with_fpu=True) --- litex/build/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/litex/build/parser.py b/litex/build/parser.py index 31c15308e..74359e2a9 100644 --- a/litex/build/parser.py +++ b/litex/build/parser.py @@ -217,7 +217,8 @@ class LiteXArgumentParser(argparse.ArgumentParser): 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) From 0f7ea96812a6b4d1938e3f6e9d9ef2438ac647af Mon Sep 17 00:00:00 2001 From: Andrew Dennison Date: Fri, 6 Oct 2023 14:34:53 +1100 Subject: [PATCH 2/2] build/parser: detect invalid defaults --- litex/build/parser.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/litex/build/parser.py b/litex/build/parser.py index 74359e2a9..ee2b4fb27 100644 --- a/litex/build/parser.py +++ b/litex/build/parser.py @@ -225,6 +225,13 @@ class LiteXArgumentParser(argparse.ArgumentParser): # 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)