mibuild: use keyword arguments directly in build_cmdline
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Sun, 1 Dec 2013 16:56:07 +0000 (17:56 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Sun, 1 Dec 2013 16:56:07 +0000 (17:56 +0100)
mibuild/generic_platform.py
mibuild/xilinx_ise.py
migen/util/misc.py

index 17c8752a2b493d3834e0c08e43d8aeef1e52195f..f6e097bb2fea8922ce3ffd23c4fbf15753945287 100644 (file)
@@ -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)
index 69944ad8b8528623ed48f4c4b5472a730f8a6395..47ee23b5f06669d4c829a124795988906f570d93 100644 (file)
@@ -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")
index 0a35ea6819c3ada20e8ed41c9cf13dbb5cbd4b94..fa041618a2a4653b8e8baefd0a1ae7342329ecd1 100644 (file)
@@ -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