From 68869cd5dec03d03b48417be2a5fe4c147dfaa3a Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 26 Apr 2023 21:45:39 -0500 Subject: [PATCH] Optimized source filtering Co-Authored-By: Martin Turski --- .../PlatformIO/scripts/common-dependencies.py | 111 +++++++++-- ini/features.ini | 2 + platformio.ini | 185 ++---------------- 3 files changed, 112 insertions(+), 186 deletions(-) diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py index 6b5a9aea57925..9ce26d31b3542 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.py +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py @@ -5,7 +5,9 @@ import pioutil if pioutil.is_pio_build(): - import subprocess,os,re + import subprocess,os,re,fnmatch,glob + srcfilepattern = re.compile(r".*[.](cpp|c)$") + marlinbasedir = os.path.join(os.getcwd(), "Marlin/") Import("env") from platformio.package.meta import PackageSpec @@ -128,6 +130,7 @@ def force_ignore_unused_libs(): def apply_features_config(): load_features() blab("========== Apply enabled features...") + build_filters = ' '.join(env.GetProjectOption('src_filter')) for feature in FEATURE_CONFIG: if not env.MarlinHas(feature): continue @@ -174,23 +177,95 @@ def apply_features_config(): if 'src_filter' in feat: blab("========== Adding build_src_filter for %s... " % feature, 2) - src_filter = ' '.join(env.GetProjectOption('src_filter')) - # first we need to remove the references to the same folder - my_srcs = re.findall(r'[+-](<.*?>)', feat['src_filter']) - cur_srcs = re.findall(r'[+-](<.*?>)', src_filter) - for d in my_srcs: - if d in cur_srcs: - src_filter = re.sub(r'[+-]' + d, '', src_filter) - - src_filter = feat['src_filter'] + ' ' + src_filter - set_env_field('build_src_filter', [src_filter]) - env.Replace(SRC_FILTER=src_filter) + build_filters = build_filters + ' ' + feat['src_filter'] + # Just append the filter in the order that the build environment specifies. + # Important here is the order of entries in the "features.ini" file. if 'lib_ignore' in feat: blab("========== Adding lib_ignore for %s... " % feature, 2) lib_ignore = env.GetProjectOption('lib_ignore') + [feat['lib_ignore']] set_env_field('lib_ignore', lib_ignore) + src_filter = "" + if True: + # Build the actual equivalent build_src_filter list based on the inclusions by the features. + # PlatformIO itself is NOT smart enough to do this! Maybe in the future it may become smart... + cur_srcs = set() + # first we need to remove the references to the same folder + my_srcs = re.findall(r'([+-]<.*?>)', build_filters) + def printpathdbg(x): + #print(x) + return + for d in my_srcs: + # gonna assume normalized relative paths here. + plain = d[2:-1] + if d[0] == '+': + def addentry(fullpath, info=None): + relp = os.path.relpath(fullpath, marlinbasedir) + if srcfilepattern.match(relp): + if info: + printpathdbg( "Added src file " + relp + " (" + str(info) + ")" ) + else: + printpathdbg( "Added src file " + relp ) + cur_srcs.add(relp) + # Special rule by PlatformIO: if a direct folder is specified then add all files + # inside of that folder + fullplain = os.path.join(marlinbasedir, plain) + if os.path.isdir(fullplain): + printpathdbg( "Directory content addition for " + plain ) + 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 by PlatformIO: if a direct folder is specified then remove all files + # from it. + def onremove(relp, info=None): + if info: + printpathdbg( "Removed src file " + relp + " (" + str(info) + ")" ) + else: + printpathdbg( "Removed src file " + relp ) + fullplain = os.path.join(marlinbasedir, plain) + if os.path.isdir(fullplain): + printpathdbg( "Directory content removal for " + plain ) + 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 source entries that match pattern. + def filt(x): + if not fnmatch.fnmatch(x, plain): + return True + onremove(x) + return False + cur_srcs = set(filter(filt, cur_srcs)) + # Transform the set into a string. + for x in cur_srcs: + if len(src_filter) > 0: + src_filter += ' ' + src_filter += "+<" + x + ">" + + #print( "Final: " + src_filter ) + else: + src_filter = build_filters + + # Tell it to PlatformIO. + set_env_field('build_src_filter', [src_filter]) + env.Replace(SRC_FILTER=src_filter) + # # Use the compiler to get a list of all enabled features # @@ -206,6 +281,16 @@ def load_marlin_features(): feature = define[8:].strip().decode().split(' ') feature, definition = feature[0], ' '.join(feature[1:]) marlin_features[feature] = definition + + # Only build with the required font files, shortens build time. + if 'HAS_GRAPHICAL_TFT' in marlin_features: + notofont_feat = "NOTOSANS" # default + if 'TFT_FONT' in marlin_features: + notofont_feat = marlin_features["TFT_FONT"] + + if notofont_feat: + marlin_features["TFT_FONT_" + notofont_feat] = "1" + env['MARLIN_FEATURES'] = marlin_features # @@ -226,6 +311,8 @@ def MarlinHas(env, feature): elif val in env['MARLIN_FEATURES']: some_on = env.MarlinHas(val) + #print( feature + " is " + str(some_on) ) + return some_on validate_pio() diff --git a/ini/features.ini b/ini/features.ini index 0d354519fb8ba..20ff51db42796 100644 --- a/ini/features.ini +++ b/ini/features.ini @@ -9,6 +9,8 @@ # # ################################# +# The order of the features matters for source-filter resolution inside of common-dependencies.py. + [features] YHCB2004 = red-scorp/LiquidCrystal_AIP31068@^1.0.4, red-scorp/SoftSPIB@^1.1.1 HAS_TFT_LVGL_UI = lvgl=https://github.com/makerbase-mks/LVGL-6.1.1-MKS/archive/master.zip diff --git a/platformio.ini b/platformio.ini index 3ee0e897c14cd..bd42fea93d153 100644 --- a/platformio.ini +++ b/platformio.ini @@ -54,129 +54,20 @@ extra_scripts = lib_deps = default_src_filter = + - - + - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + + - - - @@ -200,43 +91,7 @@ default_src_filter = + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - @@ -245,33 +100,15 @@ default_src_filter = + - - + - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - -