Commit b2740d9d authored by whitequark's avatar whitequark
Browse files

build.lattice.icestorm: write build script even on dry run.

When filing a bug report, it is useful to have the complete toolchain
invocation, including synthesis and P&R command line options.
parent 2a7e33e9
......@@ -33,16 +33,14 @@ def _build_pcf(named_sc, named_pc):
return r
def _run_icestorm(source, build_template, build_name, pnr_pkg_opts,
def _build_script(source, build_template, build_name, pnr_pkg_opts,
icetime_pkg_opts, freq_constraint):
if sys.platform == "win32" or sys.platform == "cygwin":
if sys.platform in ("win32", "cygwin"):
script_ext = ".bat"
shell = ["cmd", "/c"]
build_script_contents = "@echo off\nrem Autogenerated by Migen\n\n"
fail_stmt = " || exit /b"
else:
script_ext = ".sh"
shell = ["bash"]
build_script_contents = "# Autogenerated by Migen\nset -e\n\n"
fail_stmt = ""
......@@ -57,9 +55,16 @@ def _run_icestorm(source, build_template, build_name, pnr_pkg_opts,
build_script_file = "build_" + build_name + script_ext
tools.write_to_file(build_script_file, build_script_contents,
force_unix=False)
command = shell + [build_script_file]
r = subprocess.call(command)
if r != 0:
return build_script_file
def _run_script(script):
if sys.platform in ("win32", "cygwin"):
shell = ["cmd", "/c"]
else:
shell = ["bash"]
if subprocess.call(shell + [script]) != 0:
raise OSError("Subprocess failed")
......@@ -88,7 +93,7 @@ class LatticeIceStormToolchain:
special_overrides = common.icestorm_special_overrides
def __init__(self, use_nextpnr=False):
def __init__(self):
# Variables within replacement fields should be backend-aware and
# update their syntax accordingly. Currently, only {pnr_pkg_opts}
# needs this functionality.
......@@ -122,7 +127,7 @@ class LatticeIceStormToolchain:
# platform.device should be of the form "ice40-{lp384, hx1k, etc}-{tq144, etc}"
def build(self, platform, fragment, build_dir="build", build_name="top",
use_nextpnr=False, run=True):
use_nextpnr=True, run=True):
os.makedirs(build_dir, exist_ok=True)
cwd = os.getcwd()
os.chdir(build_dir)
......@@ -149,23 +154,25 @@ class LatticeIceStormToolchain:
tools.write_to_file(build_name + ".pcf",
_build_pcf(named_sc, named_pc))
(family, series_size, package) = self.parse_device_string(platform.device)
if use_nextpnr:
pnr_pkg_opts = "--" + series_size + " --package " + package
else:
pnr_pkg_opts = "-d " + self.get_size_string(series_size) + \
" -P " + package
icetime_pkg_opts = "-P " + package + " -d " + series_size
freq_constraint = str(max(self.freq_constraints.values(),
default=0.0))
if use_nextpnr:
chosen_build_template = self.nextpnr_build_template
else:
chosen_build_template = self.build_template
script = _build_script(False, chosen_build_template, build_name,
pnr_pkg_opts, icetime_pkg_opts, freq_constraint)
if run:
(family, series_size, package) = self.parse_device_string(platform.device)
if use_nextpnr:
pnr_pkg_opts = "--" + series_size + " --package " + package
else:
pnr_pkg_opts = "-d " + self.get_size_string(series_size) + \
" -P " + package
icetime_pkg_opts = "-P " + package + " -d " + series_size
freq_constraint = str(max(self.freq_constraints.values(),
default=0.0))
if use_nextpnr:
chosen_build_template = self.nextpnr_build_template
else:
chosen_build_template = self.build_template
_run_icestorm(False, chosen_build_template, build_name,
pnr_pkg_opts, icetime_pkg_opts, freq_constraint)
_run_script(script)
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