change(build): reject BUILD_COMPONENTS in all cmakev2 builds

The compatibility shim populated BUILD_COMPONENTS from the library
interface's linked-components list so that consumers reading it kept
working. Those consumers now query the library interface directly, so
drop the shim population and reject reads of the property
unconditionally.
This commit is contained in:
Sudeep Mohanty
2026-08-18 10:50:49 +02:00
parent 052f444f32
commit b91f894234
3 changed files with 24 additions and 25 deletions

View File

@@ -90,12 +90,7 @@ function(idf_build_get_property variable property)
cmake_parse_arguments(ARG "${options}" "${one_value}" "${multi_value}" ${ARGN})
if("${property}" STREQUAL BUILD_COMPONENTS)
# BUILD_COMPONENTS is populated by the Build system v1 compatibility
# shim; reject only when running as a native Build system v2 project.
idf_build_get_property(_v1_compat __V1_COMPAT_SHIM)
if(NOT _v1_compat)
idf_die("Build property 'BUILD_COMPONENTS' is not supported")
endif()
idf_die("Build property 'BUILD_COMPONENTS' is not supported")
endif()
set(genexpr)

View File

@@ -923,29 +923,12 @@ function(__project_default)
set(project_elf "${executable}" PARENT_SCOPE)
# Provide Build system v1-compatible build properties so that existing
# test apps and project CMakeLists.txt files that query EXECUTABLE or
# BUILD_COMPONENTS continue to work when built through the shim.
# test apps and project CMakeLists.txt files that query EXECUTABLE
# continue to work when built through the shim.
idf_build_get_property(v1_compat __V1_COMPAT_SHIM)
if(v1_compat)
idf_build_set_property(EXECUTABLE "${executable}")
idf_build_set_property(EXECUTABLE_NAME "${executable}")
# BUILD_COMPONENTS: in Build system v1 this is the set of components
# actually processed during the build (COMPONENTS + their transitive
# REQUIRES within the restricted scope). Use LIBRARY_COMPONENTS_LINKED
# from the Build system v2 library target which reflects the actual
# list of components linked, plus the architecture component which
# Build system v1 always includes but Build system v2 does not track
# as a linked library.
get_target_property(library ${executable} LIBRARY_INTERFACE)
if(library)
idf_library_get_property(linked_components "${library}" LIBRARY_COMPONENTS_LINKED)
idf_build_get_property(target_arch IDF_TARGET_ARCH)
if(target_arch AND NOT target_arch IN_LIST linked_components)
list(APPEND linked_components ${target_arch})
endif()
idf_build_set_property(BUILD_COMPONENTS "${linked_components}")
endif()
endif()
if(CONFIG_APP_BUILD_GENERATE_BINARIES AND TARGET idf::esptool_py)

View File

@@ -118,3 +118,24 @@ def test_build_components_not_available(idf_py: IdfPyFunc) -> None:
check_file = Path('build/build_components_check.txt')
assert check_file.exists(), 'Variable check file should be written before the fatal error'
assert check_file.read_text().strip() == 'NOT_FOUND', 'BUILD_COMPONENTS variable should not be available in v2'
@pytest.mark.usefixtures('test_app_copy')
def test_build_components_rejected_through_shim(idf_py: IdfPyFunc) -> None:
"""BUILD_COMPONENTS must be rejected even when building through the compatibility shim."""
logging.info('Testing BUILD_COMPONENTS rejection through the compatibility shim')
# Arm the shim via the v1 project.cmake, then query BUILD_COMPONENTS before the graph is configured.
Path('CMakeLists.txt').write_text(
'cmake_minimum_required(VERSION 3.22)\n'
'include($ENV{IDF_PATH}/tools/cmake/project.cmake)\n'
'idf_build_get_property(_bc BUILD_COMPONENTS)\n'
'project(build_test_app)\n'
)
result = idf_py('reconfigure', check=False)
assert result.returncode != 0, 'reconfigure must fail when BUILD_COMPONENTS is queried through the shim'
combined = (result.stdout or '') + (result.stderr or '')
assert 'BUILD_COMPONENTS' in combined, 'Error output must mention BUILD_COMPONENTS'
assert 'not supported' in combined.lower(), 'Error output must state that BUILD_COMPONENTS is not supported'