build/xilinx: Fixing settings finding.
authorTim 'mithro' Ansell <mithro@mithis.com>
Sun, 15 Oct 2017 15:24:29 +0000 (02:24 +1100)
committerTim 'mithro' Ansell <mithro@mithis.com>
Mon, 16 Oct 2017 07:25:51 +0000 (18:25 +1100)
 * Better error messages.
 * Search correct directories;
   - XXX/Vivado/<version>
   - XXX/<version>/ISE_DS/

litex/build/xilinx/common.py
litex/build/xilinx/ise.py
litex/build/xilinx/vivado.py

index c747945b16d265a177491272dc17d00e3a9afed4..170e67e258827c167364bb03703aeb9bd08958e7 100644 (file)
@@ -31,33 +31,49 @@ if _have_colorama:
     ]
 
 
-def settings(path, ver=None, sub=None):
-    if ver is None:
-        vers = list(tools.versions(path))
-        if not vers:
-            raise OSError("no version directory for Xilinx tools found in "
-                          + path)
-        ver = max(vers)
-
-    full = os.path.join(path, str(ver))
-    if sub:
-        full = os.path.join(full, sub)
+def settings(path, name=None, ver=None, first=None):
+    if first == "version":
+        if not ver:
+            vers = tools.versions(path)
+            ver = max(vers)
+
+        full = os.path.join(path, str(ver), name)
+
+    elif first == "name":
+        path = os.path.join(path, name)
+
+        if not ver:
+            vers = tools.versions(path)
+            ver = max(vers)
+
+        full = os.path.join(path, str(ver))
+
+    if not vers:
+        raise OSError(
+            "no version directory for Xilinx tools found in {}".format(
+                path))
 
     search = [64, 32]
     if tools.arch_bits() == 32:
-        search.reverse()
+        search = [32]
 
     if sys.platform == "win32" or sys.platform == "cygwin":
         script_ext = "bat"
     else:
         script_ext = "sh"
 
+    searched_in = []
     for b in search:
         settings = os.path.join(full, "settings{0}.{1}".format(b, script_ext))
         if os.path.exists(settings):
             return settings
+        searched_in.append(settings)
 
-    raise OSError("no Xilinx tools settings file found")
+    raise OSError(
+        "no Xilinx tools settings file found.\n"
+        "Looked in:\n"
+        "   " +
+        "\n   ".join(searched_in))
 
 
 class XilinxMultiRegImpl(MultiRegImpl):
index 0356f964462f335100524944fe6b023a63c606b9..171fbef0c757e1eb1cde8a9853af6e918639d465 100644 (file)
@@ -96,7 +96,7 @@ def _run_ise(build_name, ise_path, source, mode, ngdbuild_opt,
         build_script_contents = "# Autogenerated by LiteX\nset -e\n"
         fail_stmt = ""
     if source:
-        settings = common.settings(ise_path, ver, "ISE_DS")
+        settings = common.settings(ise_path, "ISE_DS", ver, first="version")
         build_script_contents += source_cmd + settings + "\n"
 
     ext = "ngc"
index 8051e1676839b9dc0bcf3e768fbc820084e2bd81..8511a5c508932877f735f3224ff1a0373cba0420 100644 (file)
@@ -59,7 +59,7 @@ def _run_vivado(build_name, vivado_path, source, ver=None):
         command = build_script_file
     else:
         build_script_contents = "# Autogenerated by LiteX\nset -e\n"
-        settings = common.settings(vivado_path, ver)
+        settings = common.settings(vivado_path, "Vivado", ver, first="name")
         build_script_contents += "source " + settings + "\n"
         build_script_contents += "vivado -mode batch -source " + build_name + ".tcl\n"
         build_script_file = "build_" + build_name + ".sh"
@@ -172,11 +172,11 @@ class XilinxVivadoToolchain:
             toolchain_path=None, source=True, run=True, **kwargs):
         if toolchain_path is None:
             if sys.platform == "win32":
-                toolchain_path = "C:\\Xilinx\\Vivado"
+                toolchain_path = "C:\\Xilinx"
             elif sys.platform == "cygwin":
-                toolchain_path = "/cygdrive/c/Xilinx/Vivado"
+                toolchain_path = "/cygdrive/c/Xilinx"
             else:
-                toolchain_path = "/opt/Xilinx/Vivado"
+                toolchain_path = "/opt/Xilinx"
         os.makedirs(build_dir, exist_ok=True)
         cwd = os.getcwd()
         os.chdir(build_dir)