From 4acb615c14920bb58b5ddaa6e622d9e5ef04d7ce Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Fri, 22 Mar 2024 20:17:03 +0100 Subject: [PATCH] cmake: boards: Error out if multiple boards use the same name Detecting this requires `boards.cmake` being able to handle multi-line output from `list_boards.py`. Implement a similar line reading loop to the one used in `hwm_v2.cmake`. Failing to handle this could result in an incorrectly parsed list of valid board qualifiers. Here's the expected list for `nrf52_bsim`: - "native" and here's what would happen if two copies of that board were found: - "native\nNAME" - "nrf52_bsim" - "native" Instead of that, there would now be a proper error message listing all board directories which contain `nrf52_bsim`. Signed-off-by: Grzegorz Swiderski --- cmake/modules/boards.cmake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmake/modules/boards.cmake b/cmake/modules/boards.cmake index ee81b264c1f..f76d89a8427 100644 --- a/cmake/modules/boards.cmake +++ b/cmake/modules/boards.cmake @@ -195,6 +195,24 @@ endif() if(NOT "${ret_board}" STREQUAL "") string(STRIP "${ret_board}" ret_board) + string(FIND "${ret_board}" "\n" idx REVERSE) + if(idx GREATER -1) + while(TRUE) + math(EXPR start "${idx} + 1") + string(SUBSTRING "${ret_board}" ${start} -1 line) + string(SUBSTRING "${ret_board}" 0 ${idx} ret_board) + + cmake_parse_arguments(LIST_BOARD "" "DIR" "" ${line}) + set(board_dirs "${board_dirs}\n${LIST_BOARD_DIR}") + + if(idx EQUAL -1) + break() + endif() + string(FIND "${ret_board}" "\n" idx REVERSE) + endwhile() + message(FATAL_ERROR "Multiple boards named '${BOARD}' found in:${board_dirs}") + endif() + set(single_val "NAME;DIR;HWM;REVISION_FORMAT;REVISION_DEFAULT;REVISION_EXACT") set(multi_val "REVISIONS;SOCS;QUALIFIERS") cmake_parse_arguments(LIST_BOARD "" "${single_val}" "${multi_val}" ${ret_board})