@@ -213,20 +213,24 @@ def run_or_die(cmd, error):
213
213
214
214
################################ UF2 Utils.
215
215
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
+
216
222
def generate_uf2 (example_path ):
217
223
"""Generates a .uf2 file from a .bin or .hex file.
218
224
:param str example_path: A path to the compiled .bin or .hex file.
219
225
"""
220
226
if ALL_PLATFORMS [platform ][1 ] == None :
221
227
return False
228
+ # Convert .hex to .uf2
222
229
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"
228
232
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 )
230
234
r = proc .wait (timeout = 60 )
231
235
out = proc .stdout .read ()
232
236
err = proc .stderr .read ()
0 commit comments