Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions OATFWGUI/gui_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,22 @@ def patch_line(in_str: str) -> str:
else:
log.debug('No patches applied')

def maybe_add_iprefix_pre_script(self, env_vars: dict):
# TODO: should probably refactor the hot patch logic to use ConfigParser...
platformio_ini = configparser.ConfigParser()
platformio_ini.read(Path(self.logic_state.fw_dir, 'platformio.ini'))
ini_extra_scripts = platformio_ini.get('env', 'extra_scripts', fallback='')
log.info(f'Extra scripts={ini_extra_scripts}')
if 'iprefix' in ini_extra_scripts or self.logic_state.env_is_avr_based():
return

# Make sure base firmware doesn't already have the iprefix script
# AND
# Shouldn't be harmful, but it's a bit weird so we only do this on
# esp32 boards. Assume that anything not AVR based is esp32 :S
pre_script_path = Path(get_install_dir(), 'OATFWGUI', 'pre_script_esp32_iprefix.py')
env_vars.update({'PLATFORMIO_EXTRA_SCRIPTS': f'pre:{pre_script_path.absolute()}'})

def build_fw(self):
self.main_app.wSpn_build.setState(BusyIndicatorState.BUSY)

Expand Down Expand Up @@ -329,20 +345,8 @@ def build_fw(self):
self.main_app.wSpn_build.setState(BusyIndicatorState.BAD)
return

# TODO: should probably refactor the hot patch logic to use ConfigParser...
platformio_ini = configparser.ConfigParser()
platformio_ini.read(Path(self.logic_state.fw_dir, 'platformio.ini'))
ini_extra_scripts = platformio_ini['env']['extra_scripts']
log.info(f'Extra scripts={ini_extra_scripts}')
if not 'iprefix' in ini_extra_scripts and not self.logic_state.env_is_avr_based():
# Make sure base firmware doesn't already have the iprefix script
# AND
# Shouldn't be harmful, but it's a bit weird so we only do this on
# esp32 boards. Assume that anything not AVR based is esp32 :S
pre_script_path = Path(get_install_dir(), 'OATFWGUI', 'pre_script_esp32_iprefix.py')
env_vars = {'PLATFORMIO_EXTRA_SCRIPTS': f'pre:{pre_script_path.absolute()}'}
else:
env_vars = {}
env_vars = {}
self.maybe_add_iprefix_pre_script(env_vars)

external_processes['platformio'].start(
['run',
Expand Down Expand Up @@ -422,6 +426,8 @@ def upload_fw(self):
else:
env_vars = {}

self.maybe_add_iprefix_pre_script(env_vars)

external_processes['platformio'].start(
['run',
'--environment', self.logic_state.pio_env,
Expand Down
2 changes: 1 addition & 1 deletion OATFWGUI/pre_script_esp32_iprefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def cprint(*args, **kwargs):
print(f'modify_test.py:', *args, **kwargs)
print('pre_script_esp32_iprefix.py:', *args, **kwargs)


def remove_prefix(text: str, prefix: str) -> str:
Expand Down