🔨 Simplify generic variants, update DFU tool (#27502)

This commit is contained in:
Scott Lahteine 2024-11-02 18:42:20 -05:00 committed by GitHub
parent 7b104a108f
commit 08717d3f60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 110 additions and 100 deletions

View file

@ -3,28 +3,41 @@
#
import pioutil
if pioutil.is_pio_build():
import shutil, marlin
from pathlib import Path
env = pioutil.env
platform = env.PioPlatform()
board = env.BoardConfig()
FRAMEWORK_DIR = Path(platform.get_package_dir("framework-arduinoststm32-maple"))
assert FRAMEWORK_DIR.is_dir()
source_root = Path("buildroot/share/PlatformIO/variants")
source_root_str = "buildroot/share/PlatformIO/variants"
source_root = Path(source_root_str)
assert source_root.is_dir()
env = pioutil.env
board = env.BoardConfig()
variant = board.get("build.variant")
variant_dir = FRAMEWORK_DIR / "STM32F1/variants" / variant
source_dir = source_root / variant
assert source_dir.is_dir()
if variant_dir.is_dir():
shutil.rmtree(variant_dir)
if True:
# Copying to the platform folder is still needed by STM32F1 (Maple).
# The alternative code below comes close. See if you can solve it!
platform = env.PioPlatform()
FRAMEWORK_DIR = Path(platform.get_package_dir("framework-arduinoststm32-maple"))
assert FRAMEWORK_DIR.is_dir()
if not variant_dir.is_dir():
variant_dir.mkdir()
variant_dir = FRAMEWORK_DIR / "STM32F1/variants" / variant
marlin.copytree(source_dir, variant_dir)
if variant_dir.is_dir():
import shutil
shutil.rmtree(variant_dir)
if not variant_dir.is_dir():
variant_dir.mkdir()
import marlin
marlin.copytree(source_dir, variant_dir)
else:
# The following almost works, but __start__ (from wirish/start.S) is not seen by common.inc
board.update("build.variants_dir", source_root_str);
src = str(source_dir)
env.Append(BUILD_FLAGS=[f"-I{src}", f"-L{src}/ld"]) # Add include path for variant

View file

@ -188,77 +188,75 @@ if pioutil.is_pio_build():
set_env_field('lib_ignore', lib_ignore)
build_src_filter = ""
if True:
# Build the actual equivalent build_src_filter list based on the inclusions by the features.
# PlatformIO doesn't do it this way, but maybe in the future....
cur_srcs = set()
# Remove the references to the same folder
my_srcs = re.findall(r'([+-]<.*?>)', build_filters)
for d in my_srcs:
# Assume normalized relative paths
plain = d[2:-1]
if d[0] == '+':
def addentry(fullpath, info=None):
relp = os.path.relpath(fullpath, marlinbasedir)
if srcfilepattern.match(relp):
if info:
blab("Added src file %s (%s)" % (relp, str(info)), 3)
else:
blab("Added src file %s " % relp, 3)
cur_srcs.add(relp)
# Special rule: If a direct folder is specified add all files within.
fullplain = os.path.join(marlinbasedir, plain)
if os.path.isdir(fullplain):
blab("Directory content addition for %s " % plain, 3)
gpattern = os.path.join(fullplain, "**")
for fname in glob.glob(gpattern, recursive=True):
addentry(fname, "dca")
else:
# Add all the things from the pattern by GLOB.
def srepl(matchi):
g0 = matchi.group(0)
return r"**" + g0[1:]
gpattern = re.sub(r'[*]($|[^*])', srepl, plain)
gpattern = os.path.join(marlinbasedir, gpattern)
for fname in glob.glob(gpattern, recursive=True):
addentry(fname)
else:
# Special rule: If a direct folder is specified then remove all files within.
def onremove(relp, info=None):
# Build the actual equivalent build_src_filter list based on the inclusions by the features.
# PlatformIO doesn't do it this way, but maybe in the future....
cur_srcs = set()
# Remove the references to the same folder
my_srcs = re.findall(r'([+-]<.*?>)', build_filters)
for d in my_srcs:
# Assume normalized relative paths
plain = d[2:-1]
if d[0] == '+':
def addentry(fullpath, info=None):
relp = os.path.relpath(fullpath, marlinbasedir)
if srcfilepattern.match(relp):
if info:
blab("Removed src file %s (%s)" % (relp, str(info)), 3)
blab("Added src file %s (%s)" % (relp, str(info)), 3)
else:
blab("Removed src file %s " % relp, 3)
fullplain = os.path.join(marlinbasedir, plain)
if os.path.isdir(fullplain):
blab("Directory content removal for %s " % plain, 2)
def filt(x):
common = os.path.commonpath([plain, x])
if not common == os.path.normpath(plain): return True
onremove(x, "dcr")
return False
cur_srcs = set(filter(filt, cur_srcs))
else:
# Remove matching source entries.
def filt(x):
if not fnmatch.fnmatch(x, plain): return True
onremove(x)
return False
cur_srcs = set(filter(filt, cur_srcs))
# Transform the resulting set into a string.
for x in cur_srcs:
if build_src_filter != "": build_src_filter += ' '
build_src_filter += "+<" + x + ">"
blab("Added src file %s " % relp, 3)
cur_srcs.add(relp)
# Special rule: If a direct folder is specified add all files within.
fullplain = os.path.join(marlinbasedir, plain)
if os.path.isdir(fullplain):
blab("Directory content addition for %s " % plain, 3)
gpattern = os.path.join(fullplain, "**")
for fname in glob.glob(gpattern, recursive=True):
addentry(fname, "dca")
else:
# Add all the things from the pattern by GLOB.
def srepl(matchi):
g0 = matchi.group(0)
return r"**" + g0[1:]
gpattern = re.sub(r'[*]($|[^*])', srepl, plain)
gpattern = os.path.join(marlinbasedir, gpattern)
#blab("Final build_src_filter: " + build_src_filter, 3)
else:
build_src_filter = build_filters
for fname in glob.glob(gpattern, recursive=True):
addentry(fname)
else:
# Special rule: If a direct folder is specified then remove all files within.
def onremove(relp, info=None):
if info:
blab("Removed src file %s (%s)" % (relp, str(info)), 3)
else:
blab("Removed src file %s " % relp, 3)
fullplain = os.path.join(marlinbasedir, plain)
if os.path.isdir(fullplain):
blab("Directory content removal for %s " % plain, 2)
def filt(x):
common = os.path.commonpath([plain, x])
if not common == os.path.normpath(plain): return True
onremove(x, "dcr")
return False
cur_srcs = set(filter(filt, cur_srcs))
else:
# Remove matching source entries.
def filt(x):
if not fnmatch.fnmatch(x, plain): return True
onremove(x)
return False
cur_srcs = set(filter(filt, cur_srcs))
# Transform the resulting set into a string.
for x in cur_srcs:
if build_src_filter != "": build_src_filter += ' '
build_src_filter += "+<" + x + ">"
# Update in PlatformIO
set_env_field('build_src_filter', [build_src_filter])
env.Replace(SRC_FILTER=build_src_filter)
#blab("Final build_src_filter: " + build_src_filter, 3)
#
# Use the compiler to get a list of all enabled features
#

View file

@ -40,26 +40,17 @@ if pioutil.is_pio_build():
FRAMEWORK_DIR = Path(platform.get_package_dir(platform_name))
assert FRAMEWORK_DIR.is_dir()
#
# Point variants_dir to our variant folder when board_build.variant
# is provided and the variant name begins with "marlin_".
#
board = env.BoardConfig()
#mcu_type = board.get("build.mcu")[:-2]
variant = board.get("build.variant")
#mcu_type = board.get("build.mcu")[:-2]
#series = mcu_type[:7].upper() + "xx"
# Only prepare a new variant if the PlatformIO configuration provides it (board_build.variant).
# This check is important to avoid deleting official board config variants.
# Make sure the local variant sub-folder exists
if marlin_variant_pattern.match(str(variant).lower()):
# Prepare a new empty folder at the destination
variant_dir = FRAMEWORK_DIR / "variants" / variant
if variant_dir.is_dir():
shutil.rmtree(variant_dir)
if not variant_dir.is_dir():
variant_dir.mkdir()
# Source dir is a local variant sub-folder
source_dir = Path("buildroot/share/PlatformIO/variants", variant)
assert source_dir.is_dir()
print("Copying variant " + str(variant) + " to framework directory...")
marlin.copytree(source_dir, variant_dir)
board.update("build.variants_dir", "buildroot/share/PlatformIO/variants");