Refactor build script toolchain lookups.
Now environment variable overrides no longer infect the build scripts. _toolchain.overrides is dropped as probably misguided in the first place. Fixes #251.
This commit is contained in:
parent
29253295ee
commit
a783e4645d
9 changed files with 71 additions and 50 deletions
|
|
@ -247,12 +247,14 @@ class TemplatedPlatform(Platform):
|
|||
# {{autogenerated}}
|
||||
set -e{{verbose("x")}}
|
||||
[ -n "${{platform._toolchain_env_var}}" ] && . "${{platform._toolchain_env_var}}"
|
||||
{{emit_prelude("sh")}}
|
||||
{{emit_commands("sh")}}
|
||||
""",
|
||||
"build_{{name}}.bat": """
|
||||
@rem {{autogenerated}}
|
||||
{{quiet("@echo off")}}
|
||||
if defined {{platform._toolchain_env_var}} call %{{platform._toolchain_env_var}}%
|
||||
{{emit_prelude("bat")}}
|
||||
{{emit_commands("bat")}}
|
||||
""",
|
||||
}
|
||||
|
|
@ -286,14 +288,30 @@ class TemplatedPlatform(Platform):
|
|||
return verilog._convert_rtlil_text(rtlil_text,
|
||||
strip_internal_attrs=False, write_verilog_opts=opts)
|
||||
|
||||
def emit_commands(format):
|
||||
def emit_prelude(syntax):
|
||||
commands = []
|
||||
for name in self.required_tools:
|
||||
env_var = tool_env_var(name)
|
||||
if syntax == "sh":
|
||||
template = ": ${{{env_var}:={name}}}"
|
||||
elif syntax == "bat":
|
||||
template = \
|
||||
"if [%{env_var}%] eq [\"\"] set {env_var}=\n" \
|
||||
"if [%{env_var}%] eq [] set {env_var}={name}"
|
||||
else:
|
||||
assert False
|
||||
commands.append(template.format(env_var=env_var, name=name))
|
||||
return "\n".join(commands)
|
||||
|
||||
def emit_commands(syntax):
|
||||
commands = []
|
||||
for index, command_tpl in enumerate(self.command_templates):
|
||||
command = render(command_tpl, origin="<command#{}>".format(index + 1))
|
||||
command = render(command_tpl, origin="<command#{}>".format(index + 1),
|
||||
syntax=syntax)
|
||||
command = re.sub(r"\s+", " ", command)
|
||||
if format == "sh":
|
||||
if syntax == "sh":
|
||||
commands.append(command)
|
||||
elif format == "bat":
|
||||
elif syntax == "bat":
|
||||
commands.append(command + " || exit /b")
|
||||
else:
|
||||
assert False
|
||||
|
|
@ -315,6 +333,16 @@ class TemplatedPlatform(Platform):
|
|||
else:
|
||||
return jinja2.Undefined(name=var)
|
||||
|
||||
@jinja2.contextfunction
|
||||
def invoke_tool(context, name):
|
||||
env_var = tool_env_var(name)
|
||||
if context.parent["syntax"] == "sh":
|
||||
return "\"${}\"".format(env_var)
|
||||
elif context.parent["syntax"] == "bat":
|
||||
return "%{}%".format(env_var)
|
||||
else:
|
||||
assert False
|
||||
|
||||
def options(opts):
|
||||
if isinstance(opts, str):
|
||||
return opts
|
||||
|
|
@ -336,7 +364,7 @@ class TemplatedPlatform(Platform):
|
|||
else:
|
||||
return arg
|
||||
|
||||
def render(source, origin):
|
||||
def render(source, origin, syntax=None):
|
||||
try:
|
||||
source = textwrap.dedent(source).strip()
|
||||
compiled = jinja2.Template(source, trim_blocks=True, lstrip_blocks=True)
|
||||
|
|
@ -351,8 +379,10 @@ class TemplatedPlatform(Platform):
|
|||
"emit_rtlil": emit_rtlil,
|
||||
"emit_verilog": emit_verilog,
|
||||
"emit_debug_verilog": emit_debug_verilog,
|
||||
"emit_prelude": emit_prelude,
|
||||
"emit_commands": emit_commands,
|
||||
"get_tool": get_tool,
|
||||
"syntax": syntax,
|
||||
"invoke_tool": invoke_tool,
|
||||
"get_override": get_override,
|
||||
"verbose": verbose,
|
||||
"quiet": quiet,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue