Skip to content

Commit 8bf5bd5

Browse files
committed
Use subprocess instead of os.system
1 parent 7beb695 commit 8bf5bd5

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

hls4ml/backends/fpga/fpga_backend.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import math
22
import os
33
import re
4+
import subprocess
45
from bisect import bisect_left
56
from collections.abc import Iterable
67

@@ -131,19 +132,22 @@ def compile(self, model):
131132
Returns:
132133
string: Returns the name of the compiled library.
133134
"""
134-
curr_dir = os.getcwd()
135-
os.chdir(model.config.get_output_dir())
136135

137136
lib_name = None
138-
try:
139-
ret_val = os.system('bash build_lib.sh')
140-
if ret_val != 0:
141-
raise Exception(f'Failed to compile project "{model.config.get_project_name()}"')
142-
lib_name = '{}/firmware/{}-{}.so'.format(
143-
model.config.get_output_dir(), model.config.get_project_name(), model.config.get_config_value('Stamp')
144-
)
145-
finally:
146-
os.chdir(curr_dir)
137+
ret_val = subprocess.run(
138+
['./build_lib.sh'],
139+
shell=True,
140+
text=True,
141+
stdout=subprocess.PIPE,
142+
stderr=subprocess.STDOUT,
143+
cwd=model.config.get_output_dir()
144+
)
145+
if ret_val.returncode != 0:
146+
print(ret_val.stdout)
147+
raise Exception(f'Failed to compile project "{model.config.get_project_name()}"')
148+
lib_name = '{}/firmware/{}-{}.so'.format(
149+
model.config.get_output_dir(), model.config.get_project_name(), model.config.get_config_value('Stamp')
150+
)
147151

148152
return lib_name
149153

0 commit comments

Comments
 (0)