Skip to content

Commit 3385b4c

Browse files
ellenspthinkyhead
andauthored
🔨 Auto-replace BOTH / EITHER in configs (#27249)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
1 parent 7c1f82c commit 3385b4c

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

buildroot/share/PlatformIO/scripts/preflight-checks.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,15 @@ def sanity_check_target():
7878
( build_env, motherboard, ", ".join([ e[4:] for e in board_envs if e.startswith("env:") ]) )
7979
raise SystemExit(err)
8080

81+
# Useful values
82+
project_dir = Path(env['PROJECT_DIR'])
83+
config_files = ("Configuration.h", "Configuration_adv.h")
84+
8185
#
8286
# Check for Config files in two common incorrect places
8387
#
84-
epath = Path(env['PROJECT_DIR'])
85-
for p in [ epath, epath / "config" ]:
86-
for f in ("Configuration.h", "Configuration_adv.h"):
88+
for p in (project_dir, project_dir / "config"):
89+
for f in config_files:
8790
if (p / f).is_file():
8891
err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p
8992
raise SystemExit(err)
@@ -114,11 +117,11 @@ def rm_ofile(subdir, name):
114117
# Check for old files indicating an entangled Marlin (mixing old and new code)
115118
#
116119
mixedin = []
117-
p = Path(env['PROJECT_DIR'], "Marlin/src/lcd/dogm")
120+
p = project_dir / "Marlin/src/lcd/dogm"
118121
for f in [ "ultralcd_DOGM.cpp", "ultralcd_DOGM.h" ]:
119122
if (p / f).is_file():
120123
mixedin += [ f ]
121-
p = Path(env['PROJECT_DIR'], "Marlin/src/feature/bedlevel/abl")
124+
p = project_dir / "Marlin/src/feature/bedlevel/abl"
122125
for f in [ "abl.cpp", "abl.h" ]:
123126
if (p / f).is_file():
124127
mixedin += [ f ]
@@ -137,4 +140,22 @@ def rm_ofile(subdir, name):
137140
err = "ERROR: FILAMENT_RUNOUT_SCRIPT needs a %c parameter (e.g., \"M600 T%c\") when NUM_RUNOUT_SENSORS is > 1"
138141
raise SystemExit(err)
139142

143+
#
144+
# Update old macros BOTH and EITHER in configuration files
145+
#
146+
conf_modified = False
147+
for f in config_files:
148+
conf_path = project_dir / "Marlin" / f
149+
if conf_path.is_file():
150+
with open(conf_path, 'r') as file:
151+
text = file.read()
152+
modified_text = text.replace("BOTH(", "ALL(").replace("EITHER(", "ANY(")
153+
if text != modified_text:
154+
conf_modified = True
155+
with open(conf_path, 'w') as file:
156+
file.write(modified_text)
157+
158+
if conf_modified:
159+
raise SystemExit('WARNING: Configuration files needed an update to remove incompatible items. Try the build again to use the updated files.')
160+
140161
sanity_check_target()

0 commit comments

Comments
 (0)