Disable berry pio scripts for targets where not needed (#24723)

This commit is contained in:
Jason2866
2026-05-07 22:54:58 +02:00
committed by GitHub
parent 1287868780
commit 2d807e9b4c
4 changed files with 79 additions and 0 deletions
+7
View File
@@ -24,6 +24,8 @@ import subprocess
from colorama import Fore
from tasmotapiolib import is_non_build_target
# Skip during the espidf libs compile phase that runs first when
# `custom_sdkconfig` is set. The Arduino-as-component / hybrid build
# triggers a recursive SConscript("espidf.py") which sets
@@ -33,6 +35,11 @@ if env.subst("$ARDUINO_LIB_COMPILE_FLAG") == "Build":
print("berry-dump-defines: skipped (ESP-IDF libs compile phase)")
Return()
# Skip for non-compiling targets (upload, erase, monitor, ...).
if is_non_build_target(env):
print("berry-dump-defines: skipped (non-build target)")
Return()
_IS_ESP32 = env["PIOPLATFORM"] == "espressif32"
+7
View File
@@ -23,6 +23,8 @@ import re
from colorama import Fore
from tasmotapiolib import is_non_build_target
# Skip during the espidf libs compile phase that runs first when
# `custom_sdkconfig` is set. The Arduino-as-component / hybrid build
# triggers a recursive SConscript("espidf.py") which sets
@@ -32,6 +34,11 @@ if env.subst("$ARDUINO_LIB_COMPILE_FLAG") == "Build":
print("gen-berry-defines: skipped (ESP-IDF libs compile phase)")
Return()
# Skip for non-compiling targets (upload, erase, monitor, ...).
if is_non_build_target(env):
print("gen-berry-defines: skipped (non-build target)")
Return()
# ---------------------------------------------------------------------------
# Regex patterns
# ---------------------------------------------------------------------------
+7
View File
@@ -7,6 +7,8 @@ import json
import subprocess
from os.path import join, isfile
from tasmotapiolib import is_non_build_target
# Skip during the espidf libs compile phase that runs first when
# `custom_sdkconfig` is set. The Arduino-as-component / hybrid build
# triggers a recursive SConscript("espidf.py") which sets
@@ -16,6 +18,11 @@ if env.subst("$ARDUINO_LIB_COMPILE_FLAG") == "Build":
print("gen-berry-structures: skipped (ESP-IDF libs compile phase)")
Return()
# Skip for non-compiling targets (upload, erase, monitor, ...).
if is_non_build_target(env):
print("gen-berry-structures: skipped (non-build target)")
Return()
# generate all precompiled Berry structures from multiple modules
CURRENT_DIR = os.getcwd()
PROJECT_DIR = env.subst("$PROJECT_DIR")
+58
View File
@@ -21,6 +21,7 @@ map_dir = /tmp/map_files/
Values in .ini files override environment variables
"""
import sys
import zlib
import pathlib
import os
@@ -126,6 +127,63 @@ def is_env_set(name: str, env):
return val == "1"
return False
# ---------------------------------------------------------------------------
# Target detection helper
#
# The Berry generator scripts (dump-defines.py, gen-berry-defines.py,
# gen-berry-structures.py) are wired in as `extra_scripts` and therefore
# execute during PlatformIO's SCons script-loading phase for *every*
# invocation - including targets that do not actually compile firmware
# (upload, erase, monitor, ...).
#
# `is_non_build_target(env)` returns True when the user only asked for one
# of those non-compiling targets, so the Berry pipeline can short-circuit
# and avoid regenerating .be / .h artifacts.
# ---------------------------------------------------------------------------
# Targets for which Berry artifact regeneration should be skipped.
NON_BUILD_TARGETS = frozenset({
# uploads
"upload", "uploadfs", "uploadfsota",
# filesystem build/download
"buildfs", "downloadfs", "download_fs",
# erase variants
"erase", "erase_flash", "eraseflash",
# info-only / no-op
"monitor", "nobuild", "envdump", "exec",
"size", "sizedata", "metrics", "idedata", "compiledb",
# cleanups
"clean", "fullclean", "cleanall",
# custom Tasmota targets (see pio-tools/custom_target.py)
"reset_target", "factory_flash", "external_crashreport",
})
def is_non_build_target(env=None):
"""Return True if the current PlatformIO invocation only requests
non-compiling targets (upload, erase, monitor, ...).
Returns False for the default build (no -t given) and for any
invocation that mixes a build-relevant target.
"""
try:
from SCons.Script import COMMAND_LINE_TARGETS
except ImportError:
COMMAND_LINE_TARGETS = []
if COMMAND_LINE_TARGETS:
# SCons targets available - use them directly.
return all(t in NON_BUILD_TARGETS for t in COMMAND_LINE_TARGETS)
# COMMAND_LINE_TARGETS is empty (e.g. VS Code / PlatformIO IDE environment).
# Fall back to inspecting sys.argv for known non-build target keywords.
argv_lower = [str(a).lower() for a in sys.argv]
if any(t in arg for t in NON_BUILD_TARGETS for arg in argv_lower):
return True
return False # default build
def _compress_with_gzip(data, level=9):
import zlib
if level < 0: level = 0