Skip to content

Commit c1666ad

Browse files
committed
build.plat: allow spaces in environment variables on Windows.
Specifically, allow spaces in: - set AMARANTH_ENV_<toolchain>=c:\program files\... - set <tool>=c:\program files\...
1 parent 77dab78 commit c1666ad

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

amaranth/build/plat.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ class TemplatedPlatform(Platform):
184184
"build_{{name}}.bat": """
185185
@rem {{autogenerated}}
186186
{{quiet("@echo off")}}
187-
if defined {{platform._toolchain_env_var}} call %{{platform._toolchain_env_var}}%
187+
SetLocal EnableDelayedExpansion
188+
if defined {{platform._toolchain_env_var}} call "%{{platform._toolchain_env_var}}%"
188189
{{emit_commands("bat")}}
189190
""",
190191
}
@@ -283,8 +284,8 @@ def emit_commands(syntax):
283284
template = ": ${{{env_var}:={name}}}"
284285
elif syntax == "bat":
285286
template = \
286-
"if [%{env_var}%] equ [\"\"] set {env_var}=\n" \
287-
"if [%{env_var}%] equ [] set {env_var}={name}"
287+
"if [!{env_var}!] equ [\"\"] set {env_var}=\n" \
288+
"if [!{env_var}!] equ [] set {env_var}={name}"
288289
else:
289290
assert False
290291
commands.append(template.format(env_var=env_var, name=name))
@@ -308,7 +309,7 @@ def invoke_tool(context, name):
308309
if context.parent["syntax"] == "sh":
309310
return f"\"${env_var}\""
310311
elif context.parent["syntax"] == "bat":
311-
return f"%{env_var}%"
312+
return f"\"%{env_var}%\""
312313
else:
313314
assert False
314315

0 commit comments

Comments
 (0)