Skip to content

Commit

Permalink
Optimized source filtering
Browse files Browse the repository at this point in the history
Co-Authored-By: Martin Turski <[email protected]>
  • Loading branch information
thinkyhead and quiret committed Apr 27, 2023
1 parent a96cc2a commit 68869cd
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 186 deletions.
111 changes: 99 additions & 12 deletions buildroot/share/PlatformIO/scripts/common-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
#
Expand All @@ -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

#
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions ini/features.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
185 changes: 11 additions & 174 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,129 +54,20 @@ extra_scripts =
lib_deps =
default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared> -<src/tests>
-<src/lcd/HD44780> -<src/lcd/TFTGLCD> -<src/lcd/dogm> -<src/lcd/tft> -<src/lcd/tft_io>
-<src/HAL/STM32/tft> -<src/HAL/STM32F1/tft>
-<src/lcd/e3v2/common> -<src/lcd/e3v2/creality> -<src/lcd/e3v2/proui> -<src/lcd/e3v2/jyersui> -<src/lcd/e3v2/marlinui>
-<src/lcd/e3v2>
-<src/lcd/menu>
-<src/lcd/menu/game/game.cpp> -<src/lcd/menu/game/brickout.cpp> -<src/lcd/menu/game/invaders.cpp>
-<src/lcd/menu/game/maze.cpp> -<src/lcd/menu/game/snake.cpp>
-<src/lcd/menu/menu_backlash.cpp>
-<src/lcd/menu/menu_bed_leveling.cpp>
-<src/lcd/menu/menu_bed_tramming.cpp>
-<src/lcd/menu/menu_cancelobject.cpp>
-<src/lcd/menu/menu_delta_calibrate.cpp>
-<src/lcd/menu/menu_filament.cpp>
-<src/lcd/menu/menu_info.cpp>
-<src/lcd/menu/menu_job_recovery.cpp>
-<src/lcd/menu/menu_language.cpp>
-<src/lcd/menu/menu_led.cpp>
-<src/lcd/menu/menu_media.cpp>
-<src/lcd/menu/menu_mmu2.cpp>
-<src/lcd/menu/menu_password.cpp>
-<src/lcd/menu/menu_power_monitor.cpp>
-<src/lcd/menu/menu_spindle_laser.cpp>
-<src/lcd/menu/menu_temperature.cpp>
-<src/lcd/menu/menu_tmc.cpp>
-<src/lcd/menu/menu_touch_screen.cpp>
-<src/lcd/menu/menu_tramming_wizard.cpp>
-<src/lcd/menu/menu_ubl.cpp>
-<src/lcd/menu/menu_x_twist.cpp>
-<src/lcd/extui/anycubic> -<src/lcd/extui/anycubic_chiron> -<src/lcd/extui/anycubic_vyper> -<src/lcd/extui/anycubic_i3mega>
-<src/lcd/extui/dgus> -<src/lcd/extui/dgus/fysetc> -<src/lcd/extui/dgus/hiprecy> -<src/lcd/extui/dgus/mks> -<src/lcd/extui/dgus/origin>
-<src/lcd/extui/dgus_reloaded>
-<src/lcd/extui/example>
-<src/lcd/extui/ftdi_eve_touch_ui>
-<src/lcd/extui/malyan>
-<src/lcd/extui/mks_ui>
-<src/lcd/extui/nextion>
-<src/lcd/extui/ia_creality>
-<src/lcd/extui>
-<src/lcd/lcdprint.cpp>
-<src/lcd/touch/touch_buttons.cpp>
-<src/sd/usb_flashdrive/lib-uhs2> -<src/sd/usb_flashdrive/lib-uhs3>
-<src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp>
-<src/sd/cardreader.cpp> -<src/sd/Sd2Card.cpp> -<src/sd/SdBaseFile.cpp> -<src/sd/SdFatUtil.cpp> -<src/sd/SdFile.cpp> -<src/sd/SdVolume.cpp>
-<src/lcd/touch>
-<src/sd>
-<src/HAL/shared/backtrace>
-<src/HAL/shared/cpu_exception>
-<src/HAL/shared/eeprom_if_i2c.cpp>
-<src/HAL/shared/eeprom_if_spi.cpp>
-<src/feature/adc>
-<src/feature/ammeter.cpp>
-<src/feature/babystep.cpp>
-<src/feature/backlash.cpp>
-<src/feature/baricuda.cpp>
-<src/feature/bedlevel/bedlevel.cpp>
-<src/feature/bedlevel/abl>
-<src/feature/bedlevel/bdl>
-<src/feature/bedlevel/mbl>
-<src/feature/bedlevel/ubl>
-<src/feature/bedlevel/hilbert_curve.cpp>
-<src/feature/binary_stream.cpp>
-<src/feature/bltouch.cpp>
-<src/feature/cancel_object.cpp>
-<src/feature/caselight.cpp>
-<src/feature/closedloop.cpp>
-<src/feature/controllerfan.cpp>
-<src/feature/cooler.cpp>
-<src/feature/dac> -<src/feature/digipot>
-<src/feature/direct_stepping.cpp>
-<src/feature/e_parser.cpp>
-<src/feature/easythreed_ui.cpp>
-<src/feature/encoder_i2c.cpp>
-<src/feature/ethernet.cpp>
-<src/feature/fancheck.cpp>
-<src/feature/fanmux.cpp>
-<src/feature/filwidth.cpp>
-<src/feature/fwretract.cpp>
-<src/feature/host_actions.cpp>
-<src/feature/hotend_idle.cpp>
-<src/feature/joystick.cpp>
-<src/feature/leds/blinkm.cpp>
-<src/feature/leds/leds.cpp>
-<src/feature/leds/neopixel.cpp>
-<src/feature/leds/pca9533.cpp>
-<src/feature/leds/pca9632.cpp>
-<src/feature/leds/printer_event_leds.cpp>
-<src/feature/leds/tempstat.cpp>
-<src/feature/max7219.cpp>
-<src/feature/meatpack.cpp>
-<src/feature/mixing.cpp>
-<src/feature/mmu/mmu.cpp>
-<src/feature/mmu/mmu2.cpp>
-<src/feature/password>
-<src/feature/pause.cpp>
-<src/feature/power.cpp>
-<src/feature/power_monitor.cpp>
-<src/feature/powerloss.cpp>
-<src/feature/probe_temp_comp.cpp>
-<src/feature/repeat.cpp>
-<src/feature/runout.cpp>
-<src/feature/snmm.cpp>
-<src/feature/solenoid.cpp>
-<src/feature/spindle_laser.cpp>
-<src/feature/stepper_driver_safety.cpp>
-<src/feature/tmc_util.cpp>
-<src/feature/tramming.cpp>
-<src/feature/twibus.cpp>
-<src/feature/x_twist.cpp>
-<src/feature/z_stepper_align.cpp>
-<src/gcode/bedlevel/abl>
-<src/gcode/bedlevel/mbl>
-<src/gcode/bedlevel/ubl>
-<src/gcode/bedlevel/G26.cpp>
-<src/gcode/bedlevel/G35.cpp>
-<src/gcode/bedlevel/G42.cpp>
-<src/gcode/bedlevel/M420.cpp>
-<src/gcode/calibrate/G33.cpp>
-<src/gcode/calibrate/G34.cpp>
-<src/gcode/calibrate/G34_M422.cpp>
-<src/gcode/calibrate/G76_M871.cpp>
-<src/gcode/calibrate/G425.cpp>
-<src/gcode/calibrate/M12.cpp>
-<src/gcode/calibrate/M48.cpp>
-<src/gcode/calibrate/M100.cpp>
-<src/gcode/calibrate/M425.cpp>
-<src/gcode/calibrate/M665.cpp>
-<src/gcode/calibrate/M666.cpp>
-<src/gcode/calibrate/M852.cpp>
-<src/feature>
-<src/gcode/bedlevel>
-<src/gcode/calibrate>
+<src/gcode/calibrate/G28.cpp>
-<src/gcode/config/M43.cpp>
-<src/gcode/config/M217.cpp>
-<src/gcode/config/M218.cpp>
Expand All @@ -200,43 +91,7 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared> -<src/t
-<src/gcode/control/M350_M351.cpp>
-<src/gcode/control/M380_M381.cpp>
-<src/gcode/control/M605.cpp>
-<src/gcode/feature/advance>
-<src/gcode/feature/adc>
-<src/gcode/feature/baricuda>
-<src/gcode/feature/camera>
-<src/gcode/feature/cancel>
-<src/gcode/feature/caselight>
-<src/gcode/feature/clean>
-<src/gcode/feature/controllerfan>
-<src/gcode/feature/filwidth>
-<src/gcode/feature/ft_motion>
-<src/gcode/feature/fwretract>
-<src/gcode/feature/i2c>
-<src/gcode/feature/input_shaping>
-<src/gcode/feature/L6470>
-<src/gcode/feature/leds/M150.cpp>
-<src/gcode/feature/leds/M7219.cpp>
-<src/gcode/feature/macro>
-<src/gcode/feature/mixing/M163-M165.cpp>
-<src/gcode/feature/mixing/M166.cpp>
-<src/gcode/feature/network/M552-M554.cpp>
-<src/gcode/feature/password>
-<src/gcode/feature/pause/G27.cpp>
-<src/gcode/feature/pause/G60.cpp>
-<src/gcode/feature/pause/G61.cpp>
-<src/gcode/feature/pause/M125.cpp>
-<src/gcode/feature/pause/M600.cpp>
-<src/gcode/feature/pause/M603.cpp>
-<src/gcode/feature/pause/M701_M702.cpp>
-<src/gcode/feature/power_monitor>
-<src/gcode/feature/powerloss>
-<src/gcode/feature/prusa_MMU2>
-<src/gcode/feature/runout>
-<src/gcode/feature/trinamic/M122.cpp>
-<src/gcode/feature/trinamic/M569.cpp>
-<src/gcode/feature/trinamic/M906.cpp>
-<src/gcode/feature/trinamic/M911-M914.cpp>
-<src/gcode/feature/trinamic/M919.cpp>
-<src/gcode/feature>
-<src/gcode/geometry/G17-G19.cpp>
-<src/gcode/geometry/G53-G59.cpp>
-<src/gcode/geometry/M206_M428.cpp>
Expand All @@ -245,33 +100,15 @@ default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared> -<src/t
-<src/gcode/host/M154.cpp>
-<src/gcode/host/M360.cpp>
-<src/gcode/host/M876.cpp>
-<src/gcode/lcd/M0_M1.cpp>
-<src/gcode/lcd/M73.cpp>
-<src/gcode/lcd/M117.cpp>
-<src/gcode/lcd/M145.cpp>
-<src/gcode/lcd/M250.cpp>
-<src/gcode/lcd/M255.cpp>
-<src/gcode/lcd/M256.cpp>
-<src/gcode/lcd/M300.cpp>
-<src/gcode/lcd/M414.cpp>
-<src/gcode/lcd/M995.cpp>
-<src/gcode/lcd>
-<src/gcode/motion/G2_G3.cpp>
-<src/gcode/motion/G5.cpp>
-<src/gcode/motion/G6.cpp>
-<src/gcode/motion/G80.cpp>
-<src/gcode/motion/M290.cpp>
-<src/gcode/probe/G30.cpp>
-<src/gcode/probe/G31_G32.cpp>
-<src/gcode/probe/G38.cpp>
-<src/gcode/probe/M102.cpp>
-<src/gcode/probe/M401_M402.cpp>
-<src/gcode/probe/M423.cpp>
-<src/gcode/probe/M851.cpp>
-<src/gcode/probe/M951.cpp>
-<src/gcode/probe>
-<src/gcode/scara>
-<src/gcode/sd>
-<src/gcode/sd/M32.cpp>
-<src/gcode/sd/M808.cpp>
-<src/gcode/temp/M104_M109.cpp>
-<src/gcode/temp/M143_M193.cpp>
-<src/gcode/temp/M123.cpp>
Expand Down

0 comments on commit 68869cd

Please sign in to comment.