@@ -302,6 +302,22 @@ def patch_line(in_str: str) -> str:
302302 else :
303303 log .debug ('No patches applied' )
304304
305+ def maybe_add_iprefix_pre_script (self , env_vars : dict ):
306+ # TODO: should probably refactor the hot patch logic to use ConfigParser...
307+ platformio_ini = configparser .ConfigParser ()
308+ platformio_ini .read (Path (self .logic_state .fw_dir , 'platformio.ini' ))
309+ ini_extra_scripts = platformio_ini .get ('env' , 'extra_scripts' , fallback = '' )
310+ log .info (f'Extra scripts={ ini_extra_scripts } ' )
311+ if 'iprefix' in ini_extra_scripts or self .logic_state .env_is_avr_based ():
312+ return
313+
314+ # Make sure base firmware doesn't already have the iprefix script
315+ # AND
316+ # Shouldn't be harmful, but it's a bit weird so we only do this on
317+ # esp32 boards. Assume that anything not AVR based is esp32 :S
318+ pre_script_path = Path (get_install_dir (), 'OATFWGUI' , 'pre_script_esp32_iprefix.py' )
319+ env_vars .update ({'PLATFORMIO_EXTRA_SCRIPTS' : f'pre:{ pre_script_path .absolute ()} ' })
320+
305321 def build_fw (self ):
306322 self .main_app .wSpn_build .setState (BusyIndicatorState .BUSY )
307323
@@ -329,20 +345,8 @@ def build_fw(self):
329345 self .main_app .wSpn_build .setState (BusyIndicatorState .BAD )
330346 return
331347
332- # TODO: should probably refactor the hot patch logic to use ConfigParser...
333- platformio_ini = configparser .ConfigParser ()
334- platformio_ini .read (Path (self .logic_state .fw_dir , 'platformio.ini' ))
335- ini_extra_scripts = platformio_ini ['env' ]['extra_scripts' ]
336- log .info (f'Extra scripts={ ini_extra_scripts } ' )
337- if not 'iprefix' in ini_extra_scripts and not self .logic_state .env_is_avr_based ():
338- # Make sure base firmware doesn't already have the iprefix script
339- # AND
340- # Shouldn't be harmful, but it's a bit weird so we only do this on
341- # esp32 boards. Assume that anything not AVR based is esp32 :S
342- pre_script_path = Path (get_install_dir (), 'OATFWGUI' , 'pre_script_esp32_iprefix.py' )
343- env_vars = {'PLATFORMIO_EXTRA_SCRIPTS' : f'pre:{ pre_script_path .absolute ()} ' }
344- else :
345- env_vars = {}
348+ env_vars = {}
349+ self .maybe_add_iprefix_pre_script (env_vars )
346350
347351 external_processes ['platformio' ].start (
348352 ['run' ,
@@ -422,6 +426,8 @@ def upload_fw(self):
422426 else :
423427 env_vars = {}
424428
429+ self .maybe_add_iprefix_pre_script (env_vars )
430+
425431 external_processes ['platformio' ].start (
426432 ['run' ,
427433 '--environment' , self .logic_state .pio_env ,
0 commit comments