Skip to content

Commit 5fcbd88

Browse files
authored
Arm backend: Fix Windows incompatibility in vgf_compile() (#16906)
Signed-off-by: Sarah Blades <sarah.blades@arm.com>
1 parent c4de50d commit 5fcbd88

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

backends/arm/vgf/backend.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2025 Arm Limited and/or its affiliates.
1+
# Copyright 2025-2026 Arm Limited and/or its affiliates.
22
#
33
# This source code is licensed under the BSD-style license found in the
44
# LICENSE file in the root directory of this source tree.
@@ -14,6 +14,7 @@
1414

1515
import logging
1616
import os # nosec B404 - used alongside subprocess for tool invocation
17+
import shutil
1718
import subprocess # nosec B404 - required to drive external converter CLI
1819
import tempfile
1920
from typing import final, List
@@ -143,30 +144,33 @@ def vgf_compile(
143144
with open(tosa_path, "wb") as f:
144145
f.write(tosa_flatbuffer)
145146

146-
additional_flags = " ".join(compile_flags)
147+
compile_flags = [f for f in compile_flags if f and f.strip()]
147148
converter_binary = require_model_converter_binary()
148149
vgf_path = tosa_path + ".vgf"
149-
conversion_command = (
150-
f"{converter_binary} {additional_flags} -i {tosa_path} -o {vgf_path}"
151-
)
150+
conversion_command = [
151+
converter_binary,
152+
*compile_flags,
153+
"-i",
154+
tosa_path,
155+
"-o",
156+
vgf_path,
157+
]
152158
try:
153159
subprocess.run( # nosec B602 - shell invocation constrained to trusted converter binary
154-
[conversion_command], shell=True, check=True, capture_output=True
160+
conversion_command, shell=True, check=True, capture_output=True
155161
)
156162
except subprocess.CalledProcessError as process_error:
163+
conversion_command_str = " ".join(conversion_command)
157164
raise RuntimeError(
158-
f"Vgf compiler ('{conversion_command}') failed with error:\n \
165+
f"Vgf compiler ('{conversion_command_str}') failed with error:\n \
159166
{process_error.stderr.decode()}\n \
160167
Stdout:\n{process_error.stdout.decode()}"
161168
)
162169

163170
if artifact_path:
164171
logger.info(f"Emitting debug output to: {vgf_path=}")
165172
os.makedirs(artifact_path, exist_ok=True)
166-
cp = f"cp {vgf_path} {artifact_path}"
167-
subprocess.run( # nosec B602 - shell copy of trusted artifact for debugging
168-
cp, shell=True, check=True, capture_output=False
169-
)
173+
shutil.copy2(vgf_path, artifact_path)
170174

171175
vgf_bytes = open(vgf_path, "rb").read()
172176
return vgf_bytes

0 commit comments

Comments
 (0)