Skip to content

Commit 18d7089

Browse files
committed
add glob1 pattern matchin
1 parent 5851559 commit 18d7089

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

build_platform.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,24 @@ def run_or_die(cmd, error):
213213

214214
################################ UF2 Utils.
215215

216+
def glob1(pattern):
217+
result = glob.glob(pattern)
218+
if len(result) != 1:
219+
raise RuntimeError(f"Required pattern {pattern} to match exactly 1 file, got {result}")
220+
return result[0]
221+
216222
def generate_uf2(example_path):
217223
"""Generates a .uf2 file from a .bin or .hex file.
218224
:param str example_path: A path to the compiled .bin or .hex file.
219225
"""
220226
if ALL_PLATFORMS[platform][1] == None:
221227
return False
228+
# Convert .hex to .uf2
222229
family_id = ALL_PLATFORMS[platform][1]
223-
input_file = os.path.join(example_path, "build/*/*.hex")
224-
output_file = os.path.join(example_path, "build/*/*.uf2")
225-
# Pack the example into .uf2
226-
print("input_file: ", input_file)
227-
print("output_file: ", output_file)
230+
input_file = glob1(os.path.join(example_path, "build/*/*.hex"))
231+
output_file = os.path.splitext(input_file)[0] + ".uf2"
228232
cmd = ['python3', 'uf2conv.py', input_file, '-c', '-f', family_id, '-o', output_file]
229-
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
233+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
230234
r = proc.wait(timeout=60)
231235
out = proc.stdout.read()
232236
err = proc.stderr.read()

0 commit comments

Comments
 (0)