xilinx_ise: add --no-source option to disable sourcing of ISE settings file
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Tue, 16 Apr 2013 20:39:35 +0000 (22:39 +0200)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Tue, 16 Apr 2013 20:39:35 +0000 (22:39 +0200)
mibuild/xilinx_ise.py

index a6c31c00cba0fef07652da763ac31513ace36d76..0d7a663bec1a7900a8523018ae32a62c09ade4f4 100644 (file)
@@ -85,29 +85,28 @@ def _build_files(device, sources, named_sc, named_pc, build_name):
 -p %s""" % (build_name, build_name, device)
        tools.write_to_file(build_name + ".xst", xst_contents)
 
-def _run_ise(build_name, ise_path):
+def _run_ise(build_name, ise_path, source):
        def is_valid_version(v):
                try: 
                        Decimal(v)
                        return os.path.isdir(os.path.join(ise_path, v))
                except:
                        return False
-       vers = [ver for ver in os.listdir(ise_path) if is_valid_version(ver)]
-       tools_version = max(vers)
-       bits = struct.calcsize("P")*8
-       xilinx_settings_file = '%s/%s/ISE_DS/settings%d.sh' % (ise_path, tools_version, bits) 
-
-       build_script_contents = """# Autogenerated by mibuild
-
-set -e
-
-source {xilinx_settings_file}
+       build_script_contents = "# Autogenerated by mibuild\nset -e\n"
+       if source:
+               vers = [ver for ver in os.listdir(ise_path) if is_valid_version(ver)]
+               tools_version = max(vers)
+               bits = struct.calcsize("P")*8
+               xilinx_settings_file = '%s/%s/ISE_DS/settings%d.sh' % (ise_path, tools_version, bits) 
+               build_script_contents += "source " + xilinx_settings_file + "\n"
+
+       build_script_contents += """
 xst -ifn {build_name}.xst
 ngdbuild -uc {build_name}.ucf {build_name}.ngc
 map -ol high -w {build_name}.ngd
 par -ol high -w {build_name}.ncd {build_name}-routed.ncd
 bitgen -g LCK_cycle:6 -g Binary:Yes -w {build_name}-routed.ncd {build_name}.bit
-""".format(build_name=build_name, xilinx_settings_file=xilinx_settings_file)
+""".format(build_name=build_name)
        build_script_file = "build_" + build_name + ".sh"
        tools.write_to_file(build_script_file, build_script_contents)
 
@@ -133,7 +132,7 @@ class XilinxISEPlatform(GenericPlatform):
                return GenericPlatform.get_verilog(self, *args, special_overrides=so, **kwargs)
 
        def build(self, fragment, build_dir="build", build_name="top",
-                       ise_path="/opt/Xilinx", run=True):
+                       ise_path="/opt/Xilinx", source=True, run=True):
                tools.mkdir_noerror(build_dir)
                os.chdir(build_dir)
 
@@ -143,13 +142,14 @@ class XilinxISEPlatform(GenericPlatform):
                sources = self.sources + [(v_file, "verilog")]
                _build_files(self.device, sources, named_sc, named_pc, build_name)
                if run:
-                       _run_ise(build_name, ise_path)
+                       _run_ise(build_name, ise_path, source)
                
                os.chdir("..")
 
        def build_arg_ns(self, ns, *args, **kwargs):
                for n in ["build_dir", "build_name", "ise_path"]:
                        kwargs[n] = getattr(ns, n)
+               kwargs["source"] = not ns.no_source
                kwargs["run"] = not ns.no_run
                self.build(*args, **kwargs)
 
@@ -157,4 +157,5 @@ class XilinxISEPlatform(GenericPlatform):
                parser.add_argument("--build-dir", default="build", help="Set the directory in which to generate files and run ISE")
                parser.add_argument("--build-name", default="top", help="Base name for the generated files")
                parser.add_argument("--ise-path", default="/opt/Xilinx", 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")