Files
hexapod-robot/2026-current/scripts/select_src_dir.py
T

16 lines
781 B
Python
Raw Normal View History

# PlatformIO pre-build script: point each environment at its own sketch folder.
#
# PlatformIO only has one global `src_dir`, and it only converts .ino files in
# the root of that directory. Each env sets `custom_src_dir = robot` (or
# `remote`) and this script swaps PROJECT_SRC_DIR before the build starts, so
# robot/ and remote/ stay plain Arduino-style sketch folders (one .ino plus
# paired .h/.cpp files) that also open in the Arduino IDE.
import os
Import("env") # noqa: F821 - injected by PlatformIO/SCons
sub = env.GetProjectOption("custom_src_dir") # noqa: F821
src = os.path.join(env.subst("$PROJECT_DIR"), sub) # noqa: F821
if not os.path.isdir(src):
raise SystemExit("custom_src_dir '%s' does not exist" % src)
env.Replace(PROJECT_SRC_DIR=src) # noqa: F821