From: Sebastien Bourdeauducq Date: Sun, 1 Dec 2013 16:56:07 +0000 (+0100) Subject: mibuild: use keyword arguments directly in build_cmdline X-Git-Tag: 24jan2021_ls180~2099^2~415 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=de830dc743dbf007aeb07d382efbc8cac0df5385;p=litex.git mibuild: use keyword arguments directly in build_cmdline --- diff --git a/mibuild/generic_platform.py b/mibuild/generic_platform.py index 17c8752a..f6e097bb 100644 --- a/mibuild/generic_platform.py +++ b/mibuild/generic_platform.py @@ -1,9 +1,10 @@ -import os, argparse +import os, sys from migen.fhdl.std import * from migen.fhdl.structure import _Fragment from migen.genlib.record import Record from migen.fhdl import verilog, edif +from migen.util.misc import autotype from mibuild import tools @@ -225,14 +226,11 @@ class GenericPlatform: def build(self, fragment): raise NotImplementedError("GenericPlatform.build must be overloaded") - def add_arguments(self, parser): - pass # default: no arguments - - def build_arg_ns(self, ns, *args, **kwargs): - self.build(*args, **kwargs) - def build_cmdline(self, *args, **kwargs): - parser = argparse.ArgumentParser(description="FPGA bitstream build system") - self.add_arguments(parser) - ns = parser.parse_args() - self.build_arg_ns(ns, *args, **kwargs) + arg = sys.argv[1:] + if len(arg) % 2: + print("Missing value for option: "+sys.argv[-1]) + sys.exit(1) + argdict = dict((k, autotype(v)) for k, v in zip(*[iter(arg)]*2)) + kwargs.update(argdict) + self.build(*args, **kwargs) diff --git a/mibuild/xilinx_ise.py b/mibuild/xilinx_ise.py index 69944ad8..47ee23b5 100644 --- a/mibuild/xilinx_ise.py +++ b/mibuild/xilinx_ise.py @@ -227,21 +227,3 @@ class XilinxISEPlatform(GenericPlatform): _run_ise(build_name, ise_path, source, isemode, ngdbuild_opt) os.chdir("..") - - def build_arg_ns(self, ns, *args, **kwargs): - for n in ["build_dir", "build_name", "ise_path"]: - attr = getattr(ns, n) - if attr is not None: - kwargs[n] = attr - if ns.no_source: - kwargs["source"] = False - if ns.no_run: - kwargs["run"] = False - self.build(*args, **kwargs) - - def add_arguments(self, parser): - parser.add_argument("--build-dir", default=None, help="Set the directory in which to generate files and run ISE") - parser.add_argument("--build-name", default=None, help="Base name for the generated files") - parser.add_argument("--ise-path", default=None, help="ISE installation path (without version directory)") - parser.add_argument("--no-source", action="store_true", help="Do not source ISE settings file") - parser.add_argument("--no-run", action="store_true", help="Only generate files, do not run ISE") diff --git a/migen/util/misc.py b/migen/util/misc.py index 0a35ea68..fa041618 100644 --- a/migen/util/misc.py +++ b/migen/util/misc.py @@ -5,3 +5,14 @@ def xdir(obj, return_values=False): yield attr, getattr(obj, attr) else: yield attr + +def autotype(s): + if s == "True": + return True + elif s == "False": + return False + try: + return int(s, 0) + except ValueError: + pass + return s