cmake: ensure shields can be placed in other BOARD_ROOTs

Fixes: #28462

This commit allows shields to be defined in other BOARD_ROOTs, either
using `-DBOARD_ROOT=<path>` or a Zephyr module defined BOARD_ROOT.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit is contained in:
Torsten Rasmussen 2020-10-27 11:08:28 +01:00 committed by Carles Cufí
commit 4558ba7128
4 changed files with 22 additions and 2 deletions

View file

@ -20,7 +20,7 @@ endmenu
# precedence over SoC defaults, so include them in that order. # precedence over SoC defaults, so include them in that order.
# #
# $ARCH and $BOARD_DIR will be glob patterns when building documentation. # $ARCH and $BOARD_DIR will be glob patterns when building documentation.
source "boards/shields/*/Kconfig.defconfig" source "$(KCONFIG_BINARY_DIR)/Kconfig.shield.defconfig"
source "$(BOARD_DIR)/Kconfig.defconfig" source "$(BOARD_DIR)/Kconfig.defconfig"
source "$(KCONFIG_BINARY_DIR)/Kconfig.soc.defconfig" source "$(KCONFIG_BINARY_DIR)/Kconfig.soc.defconfig"

View file

@ -25,7 +25,7 @@ endchoice
# Parse shields references # Parse shields references
# Don't do it as a menuconfig, as shield selection is a CMake feature. # Don't do it as a menuconfig, as shield selection is a CMake feature.
rsource "shields/*/Kconfig.shield" source "$(KCONFIG_BINARY_DIR)/Kconfig.shield"
menu "Board Options" menu "Board Options"
config QEMU_ICOUNT config QEMU_ICOUNT

View file

@ -21,6 +21,18 @@ foreach(root ${SOC_ROOT})
set(OPERATION APPEND) set(OPERATION APPEND)
endforeach() endforeach()
# Support multiple shields in BOARD_ROOT
set(OPERATION WRITE)
foreach(root ${BOARD_ROOT})
file(${OPERATION} ${KCONFIG_BINARY_DIR}/Kconfig.shield.defconfig
"osource \"${root}/boards/shields/*/Kconfig.defconfig\"\n"
)
file(${OPERATION} ${KCONFIG_BINARY_DIR}/Kconfig.shield
"osource \"${root}/boards/shields/*/Kconfig.shield\"\n"
)
set(OPERATION APPEND)
endforeach()
if(KCONFIG_ROOT) if(KCONFIG_ROOT)
zephyr_file(APPLICATION_ROOT KCONFIG_ROOT) zephyr_file(APPLICATION_ROOT KCONFIG_ROOT)
# KCONFIG_ROOT has either been specified as a CMake variable or is # KCONFIG_ROOT has either been specified as a CMake variable or is

View file

@ -265,6 +265,8 @@ class KconfigCheck(ComplianceTest):
soc_defconfig_file = os.path.join(tempfile.gettempdir(), "Kconfig.soc.defconfig") soc_defconfig_file = os.path.join(tempfile.gettempdir(), "Kconfig.soc.defconfig")
soc_file = os.path.join(tempfile.gettempdir(), "Kconfig.soc") soc_file = os.path.join(tempfile.gettempdir(), "Kconfig.soc")
soc_arch_file = os.path.join(tempfile.gettempdir(), "Kconfig.soc.arch") soc_arch_file = os.path.join(tempfile.gettempdir(), "Kconfig.soc.arch")
shield_defconfig_file = os.path.join(tempfile.gettempdir(), "Kconfig.shield.defconfig")
shield_file = os.path.join(tempfile.gettempdir(), "Kconfig.shield")
try: try:
with open(soc_defconfig_file, 'w', encoding="utf-8") as fp: with open(soc_defconfig_file, 'w', encoding="utf-8") as fp:
fp.write(f'osource "{ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig.defconfig"\n') fp.write(f'osource "{ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig.defconfig"\n')
@ -275,6 +277,12 @@ class KconfigCheck(ComplianceTest):
with open(soc_arch_file, 'w', encoding="utf-8") as fp: with open(soc_arch_file, 'w', encoding="utf-8") as fp:
fp.write(f'osource "{ZEPHYR_BASE}/soc/$(ARCH)/Kconfig"\n\ fp.write(f'osource "{ZEPHYR_BASE}/soc/$(ARCH)/Kconfig"\n\
osource "{ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig"\n') osource "{ZEPHYR_BASE}/soc/$(ARCH)/*/Kconfig"\n')
with open(shield_defconfig_file, 'w', encoding="utf-8") as fp:
fp.write(f'osource "{ZEPHYR_BASE}/boards/shields/*/Kconfig.defconfig"\n')
with open(shield_file, 'w', encoding="utf-8") as fp:
fp.write(f'osource "{ZEPHYR_BASE}/boards/shields/*/Kconfig.shield"\n')
except IOError as ex: except IOError as ex:
self.error(ex.output) self.error(ex.output)