From 7f4b1abb3914b8984ae8b808085adda475846ea8 Mon Sep 17 00:00:00 2001 From: Grzegorz Swiderski Date: Thu, 10 Aug 2023 08:34:42 +0200 Subject: [PATCH] cmake: Don't lose global sysbuild value with zephyr_get(... MERGE) According to the doc comment: If using MERGE then SYSBUILD GLOBAL will get both the local and global sysbuild scope variables (in that order, if both exist). This stopped working in commit 8460d91e323cfa7d0017ee027e300f34d4d01a49, when support for `zephyr_get(... VAR )` was added. Instead of returning both values, the local sysbuild scope value would clobber the global one. Fix this by splitting the internal `sysbuild` scope into `sysbuild_local` and `sysbuild_global`, in that order. Signed-off-by: Grzegorz Swiderski --- cmake/modules/extensions.cmake | 17 ++++++++++------- tests/cmake/zephyr_get/CMakeLists.txt | 18 +++++++++--------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/cmake/modules/extensions.cmake b/cmake/modules/extensions.cmake index ab8232c820..eb1c7f27fd 100644 --- a/cmake/modules/extensions.cmake +++ b/cmake/modules/extensions.cmake @@ -2641,14 +2641,17 @@ function(zephyr_get variable) if(SYSBUILD) get_property(sysbuild_name TARGET sysbuild_cache PROPERTY SYSBUILD_NAME) get_property(sysbuild_main_app TARGET sysbuild_cache PROPERTY SYSBUILD_MAIN_APP) - get_property(sysbuild_${var} TARGET sysbuild_cache PROPERTY ${sysbuild_name}_${var}) - if(NOT DEFINED sysbuild_${var} AND - ("${GET_VAR_SYSBUILD}" STREQUAL "GLOBAL" OR sysbuild_main_app) - ) - get_property(sysbuild_${var} TARGET sysbuild_cache PROPERTY ${var}) + get_property(sysbuild_local_${var} TARGET sysbuild_cache PROPERTY ${sysbuild_name}_${var}) + get_property(sysbuild_global_${var} TARGET sysbuild_cache PROPERTY ${var}) + if(NOT DEFINED sysbuild_local_${var} AND sysbuild_main_app) + set(sysbuild_local_${var} ${sysbuild_global_${var}}) + endif() + if(NOT "${GET_VAR_SYSBUILD}" STREQUAL "GLOBAL") + set(sysbuild_global_${var}) endif() else() - set(sysbuild_${var}) + set(sysbuild_local_${var}) + set(sysbuild_global_${var}) endif() if(TARGET snippets_scope) @@ -2656,7 +2659,7 @@ function(zephyr_get variable) endif() endforeach() - set(scopes "sysbuild;CACHE;snippets;ENV;current") + set(scopes "sysbuild_local;sysbuild_global;CACHE;snippets;ENV;current") if(GET_VAR_REVERSE) list(REVERSE scopes) endif() diff --git a/tests/cmake/zephyr_get/CMakeLists.txt b/tests/cmake/zephyr_get/CMakeLists.txt index a60c26309c..93b771366d 100644 --- a/tests/cmake/zephyr_get/CMakeLists.txt +++ b/tests/cmake/zephyr_get/CMakeLists.txt @@ -230,7 +230,7 @@ function(test_merge) IMAGE no_sysbuild "" # This image's LOCAL and GLOBAL are identical; duplicates are removed. IMAGE zephyr_get "sysbuild.main" - IMAGE zephyr_get_2nd "sysbuild.2nd" # BUG + IMAGE zephyr_get_2nd "sysbuild.2nd;sysbuild.main" IMAGE zephyr_get_3rd "sysbuild.main" ) @@ -243,7 +243,7 @@ function(test_merge) assert_equal(TESTCASE_VARIABLE IMAGE no_sysbuild "cmake cache;environment;local" IMAGE zephyr_get "cmake cache;sysbuild.main;environment;local" # BUG - IMAGE zephyr_get_2nd "cmake cache;sysbuild.2nd;environment;local" # BUG + IMAGE zephyr_get_2nd "cmake cache;sysbuild.2nd;sysbuild.main;environment;local" # BUG IMAGE zephyr_get_3rd "cmake cache;sysbuild.main;environment;local" # BUG ) @@ -264,7 +264,7 @@ function(test_merge) assert_equal(TESTCASE_VARIABLE IMAGE no_sysbuild "environment" IMAGE zephyr_get "sysbuild.main;environment" - IMAGE zephyr_get_2nd "sysbuild.2nd;environment" # BUG + IMAGE zephyr_get_2nd "sysbuild.2nd;sysbuild.main;environment" IMAGE zephyr_get_3rd "sysbuild.main;environment" ) assert_equal(CACHE{TESTCASE_VARIABLE} "") @@ -377,7 +377,7 @@ function(test_multivar) assert_equal(RESULT IMAGE no_sysbuild "cmake cache s;cmake cache 2;environment s;environment 1;environment 3;local s;local 2;local 3" IMAGE zephyr_get "sysbuild.main;cmake cache s;cmake cache 2;environment s;environment 1;environment 3;local s;local 2;local 3" - IMAGE zephyr_get_2nd "sysbuild.2nd;cmake cache s;cmake cache 2;environment s;environment 1;environment 3;local s;local 2;local 3" # BUG + IMAGE zephyr_get_2nd "sysbuild.2nd;sysbuild.main;cmake cache s;cmake cache 2;environment s;environment 1;environment 3;local s;local 2;local 3" IMAGE zephyr_get_3rd "sysbuild.main;cmake cache s;cmake cache 2;environment s;environment 1;environment 3;local s;local 2;local 3" ) unset(RESULT) @@ -393,7 +393,7 @@ function(test_multivar) assert_equal(RESULT IMAGE no_sysbuild "cmake cache 2;cmake cache s;environment 3;environment 1;environment s;local 3;local 2;local s" IMAGE zephyr_get "sysbuild.main;cmake cache 2;cmake cache s;environment 3;environment 1;environment s;local 3;local 2;local s" - IMAGE zephyr_get_2nd "sysbuild.2nd;cmake cache 2;cmake cache s;environment 3;environment 1;environment s;local 3;local 2;local s" # BUG + IMAGE zephyr_get_2nd "sysbuild.2nd;sysbuild.main;cmake cache 2;cmake cache s;environment 3;environment 1;environment s;local 3;local 2;local s" IMAGE zephyr_get_3rd "sysbuild.main;cmake cache 2;cmake cache s;environment 3;environment 1;environment s;local 3;local 2;local s" ) unset(RESULT) @@ -449,7 +449,7 @@ function(test_merge_reverse) assert_equal(TESTCASE_VARIABLE IMAGE no_sysbuild "" IMAGE zephyr_get "sysbuild.main" - IMAGE zephyr_get_2nd "sysbuild.2nd" # BUG + IMAGE zephyr_get_2nd "sysbuild.main;sysbuild.2nd" IMAGE zephyr_get_3rd "sysbuild.main" ) @@ -462,7 +462,7 @@ function(test_merge_reverse) assert_equal(TESTCASE_VARIABLE IMAGE no_sysbuild "local s;environment s;cmake cache s" IMAGE zephyr_get "local s;environment s;cmake cache s;sysbuild.main" - IMAGE zephyr_get_2nd "local s;environment s;cmake cache s;sysbuild.2nd" # BUG + IMAGE zephyr_get_2nd "local s;environment s;cmake cache s;sysbuild.main;sysbuild.2nd" IMAGE zephyr_get_3rd "local s;environment s;cmake cache s;sysbuild.main" ) @@ -483,7 +483,7 @@ function(test_merge_reverse) assert_equal(RESULT IMAGE no_sysbuild "local s;local 1;local 2;environment s;environment 1;environment 2;cmake cache s;cmake cache 1;cmake cache 2" IMAGE zephyr_get "local s;local 1;local 2;environment s;environment 1;environment 2;cmake cache s;cmake cache 1;cmake cache 2;sysbuild.main" - IMAGE zephyr_get_2nd "local s;local 1;local 2;environment s;environment 1;environment 2;cmake cache s;cmake cache 1;cmake cache 2;sysbuild.2nd" # BUG + IMAGE zephyr_get_2nd "local s;local 1;local 2;environment s;environment 1;environment 2;cmake cache s;cmake cache 1;cmake cache 2;sysbuild.main;sysbuild.2nd" IMAGE zephyr_get_3rd "local s;local 1;local 2;environment s;environment 1;environment 2;cmake cache s;cmake cache 1;cmake cache 2;sysbuild.main" ) endfunction() @@ -556,7 +556,7 @@ function(test_snippets_scope) assert_equal(TESTCASE_VARIABLE IMAGE no_sysbuild "snippet s" IMAGE zephyr_get "sysbuild.main;snippet s" - IMAGE zephyr_get_2nd "sysbuild.2nd;snippet s" # BUG + IMAGE zephyr_get_2nd "sysbuild.2nd;sysbuild.main;snippet s" IMAGE zephyr_get_3rd "sysbuild.main;snippet s" )