Commit 7bdc4ed2 authored by whitequark's avatar whitequark
Browse files

build/lattice/diamond: add Linux support.

This also alters the build_top.sh script to be always generated, like
in IcestormToolchain, and makes the build script more robust on both
Linux and Windows. This commit has not been tested on Windows but
should not break anything, in principle...
parent 3a84a8bf
...@@ -66,19 +66,49 @@ def _build_files(device, sources, vincpaths, build_name): ...@@ -66,19 +66,49 @@ def _build_files(device, sources, vincpaths, build_name):
tools.write_to_file(build_name + ".tcl", "\n".join(tcl)) tools.write_to_file(build_name + ".tcl", "\n".join(tcl))
def _run_diamond(build_name, source, ver=None): def _build_script(build_name, device, toolchain_path, ver=None):
if sys.platform == "win32" or sys.platform == "cygwin": if sys.platform in ("win32", "cygwin"):
build_script_contents = "REM Autogenerated by Migen\n" script_ext = ".bat"
build_script_contents = "pnmainc " + build_name + ".tcl\n" build_script_contents = "@echo off\nrem Autogenerated by Migen\n\n"
build_script_file = "build_" + build_name + ".bat" copy_stmt = "copy"
tools.write_to_file(build_script_file, build_script_contents) fail_stmt = " || exit /b"
r = subprocess.call([build_script_file])
shutil.copy(os.path.join("implementation", build_name + "_implementation.bit"), build_name + ".bit")
shutil.copy(os.path.join("implementation", build_name + "_implementation.jed"), build_name + ".jed")
else: else:
raise NotImplementedError script_ext = ".sh"
build_script_contents = "# Autogenerated by Migen\nset -e\n\n"
copy_stmt = "cp"
fail_stmt = ""
if sys.platform not in ("win32", "cygwin"):
build_script_contents += "bindir={}\n".format(toolchain_path)
build_script_contents += ". ${{bindir}}/diamond_env{fail_stmt}\n".format(
fail_stmt=fail_stmt)
build_script_contents += "{pnmainc} {tcl_script}{fail_stmt}\n".format(
pnmainc=os.path.join(toolchain_path, "pnmainc"),
tcl_script=build_name + ".tcl",
fail_stmt=fail_stmt)
for ext in (".bit", ".jed"):
if ext == ".jed" and not _produces_jedec(device):
continue
build_script_contents += "{copy_stmt} {diamond_product} {migen_product}" \
"{fail_stmt}\n".format(
copy_stmt=copy_stmt,
fail_stmt=fail_stmt,
diamond_product=os.path.join("implementation", build_name + "_implementation" + ext),
migen_product=build_name + ext)
build_script_file = "build_" + build_name + script_ext
tools.write_to_file(build_script_file, build_script_contents,
force_unix=False)
return build_script_file
def _run_script(script):
if sys.platform in ("win32", "cygwin"):
shell = ["cmd", "/c"]
else:
shell = ["bash"]
if r != 0: if subprocess.call(shell + [script]) != 0:
raise OSError("Subprocess failed") raise OSError("Subprocess failed")
...@@ -106,8 +136,9 @@ class LatticeDiamondToolchain: ...@@ -106,8 +136,9 @@ class LatticeDiamondToolchain:
tools.write_to_file(build_name + ".lpf", _build_lpf(named_sc, named_pc)) tools.write_to_file(build_name + ".lpf", _build_lpf(named_sc, named_pc))
script = _build_script(build_name, platform.device, toolchain_path)
if run: if run:
_run_diamond(build_name, toolchain_path) _run_script(script)
os.chdir(cwd) os.chdir(cwd)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment