From 3385b4c280befa011471484a0592946d724b60db Mon Sep 17 00:00:00 2001 From: ellensp <530024+ellensp@users.noreply.github.com> Date: Tue, 9 Jul 2024 11:46:03 +1200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Auto-replace=20BOTH=20/=20EITHER?= =?UTF-8?q?=20in=20configs=20(#27249)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- .../PlatformIO/scripts/preflight-checks.py | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/buildroot/share/PlatformIO/scripts/preflight-checks.py b/buildroot/share/PlatformIO/scripts/preflight-checks.py index 731537f3ed..8c52234a94 100644 --- a/buildroot/share/PlatformIO/scripts/preflight-checks.py +++ b/buildroot/share/PlatformIO/scripts/preflight-checks.py @@ -78,12 +78,15 @@ if pioutil.is_pio_build(): ( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) ) raise SystemExit(err) + # Useful values + project_dir = Path(env['PROJECT_DIR']) + config_files = ("Configuration.h", "Configuration_adv.h") + # # Check for Config files in two common incorrect places # - epath = Path(env['PROJECT_DIR']) - for p in [ epath, epath / "config" ]: - for f in ("Configuration.h", "Configuration_adv.h"): + for p in (project_dir, project_dir / "config"): + for f in config_files: if (p / f).is_file(): err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p raise SystemExit(err) @@ -114,11 +117,11 @@ if pioutil.is_pio_build(): # Check for old files indicating an entangled Marlin (mixing old and new code) # mixedin = [] - p = Path(env['PROJECT_DIR'], "Marlin/src/lcd/dogm") + p = project_dir / "Marlin/src/lcd/dogm" for f in [ "ultralcd_DOGM.cpp", "ultralcd_DOGM.h" ]: if (p / f).is_file(): mixedin += [ f ] - p = Path(env['PROJECT_DIR'], "Marlin/src/feature/bedlevel/abl") + p = project_dir / "Marlin/src/feature/bedlevel/abl" for f in [ "abl.cpp", "abl.h" ]: if (p / f).is_file(): mixedin += [ f ] @@ -137,4 +140,22 @@ if pioutil.is_pio_build(): err = "ERROR: FILAMENT_RUNOUT_SCRIPT needs a %c parameter (e.g., \"M600 T%c\") when NUM_RUNOUT_SENSORS is > 1" raise SystemExit(err) + # + # Update old macros BOTH and EITHER in configuration files + # + conf_modified = False + for f in config_files: + conf_path = project_dir / "Marlin" / f + if conf_path.is_file(): + with open(conf_path, 'r') as file: + text = file.read() + modified_text = text.replace("BOTH(", "ALL(").replace("EITHER(", "ANY(") + if text != modified_text: + conf_modified = True + with open(conf_path, 'w') as file: + file.write(modified_text) + + if conf_modified: + raise SystemExit('WARNING: Configuration files needed an update to remove incompatible items. Try the build again to use the updated files.') + sanity_check_target()