Merge branch 'contrib/github_pr_14036' into 'master'

fix(cmake): check for missing component_target (GitHub PR)

Closes IDFGH-13091

See merge request espressif/esp-idf!32061
This commit is contained in:
Roland Dobai 2024-07-12 15:14:01 +08:00
commit 1ac37b6901
2 changed files with 29 additions and 4 deletions

View File

@ -44,7 +44,7 @@ function(__component_get_target var name_or_alias)
idf_build_get_property(component_targets __COMPONENT_TARGETS)
# Assume first that the paramters is an alias.
# Assume first that the parameters is an alias.
string(REPLACE "::" "_" name_or_alias "${name_or_alias}")
set(component_target ___${name_or_alias})
@ -376,10 +376,14 @@ endmacro()
function(idf_component_get_property var component property)
cmake_parse_arguments(_ "GENERATOR_EXPRESSION" "" "" ${ARGN})
__component_get_target(component_target ${component})
if(__GENERATOR_EXPRESSION)
set(val "$<TARGET_PROPERTY:${component_target},${property}>")
if("${component_target}" STREQUAL "")
message(FATAL_ERROR "Failed to resolve component '${component}'")
else()
__component_get_property(val ${component_target} ${property})
if(__GENERATOR_EXPRESSION)
set(val "$<TARGET_PROPERTY:${component_target},${property}>")
else()
__component_get_property(val ${component_target} ${property})
endif()
endif()
set(${var} "${val}" PARENT_SCOPE)
endfunction()
@ -398,6 +402,9 @@ endfunction()
function(idf_component_set_property component property val)
cmake_parse_arguments(_ "APPEND" "" "" ${ARGN})
__component_get_target(component_target ${component})
if(NOT component_target)
message(FATAL_ERROR "Failed to resolve component '${component}'")
endif()
if(__APPEND)
__component_set_property(${component_target} ${property} "${val}" APPEND)

View File

@ -87,6 +87,24 @@ def test_component_properties_are_set(idf_py: IdfPyFunc, test_app_copy: Path) ->
assert 'SRCS:{}'.format((test_app_copy / 'main' / 'build_test_app.c').as_posix()) in ret.stdout, 'Component properties should be set'
def test_get_property_for_unknown_component(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
logging.info('Getting property of unknown component fails gracefully')
append_to_file(test_app_copy / 'CMakeLists.txt', '\n'.join(['',
'idf_component_get_property(VAR UNKNOWN PROP)']))
ret = idf_py('reconfigure', check=False)
assert "Failed to resolve component 'UNKNOWN'" in ret.stderr, ('idf_component_get_property '
'for unknown component should fail gracefully')
def test_set_property_for_unknown_component(idf_py: IdfPyFunc, test_app_copy: Path) -> None:
logging.info('Setting property of unknown component fails gracefully')
append_to_file(test_app_copy / 'CMakeLists.txt', '\n'.join(['',
'idf_component_set_property(UNKNOWN PROP VAL)']))
ret = idf_py('reconfigure', check=False)
assert "Failed to resolve component 'UNKNOWN'" in ret.stderr, ('idf_component_set_property '
'for unknown component should fail gracefully')
def test_component_overridden_dir(idf_py: IdfPyFunc, test_app_copy: Path, default_idf_env: EnvDict) -> None:
logging.info('Getting component overridden dir')
(test_app_copy / 'components' / 'hal').mkdir(parents=True)