From 8eaf6aebc6dacb8ce1950872b18d480249290a38 Mon Sep 17 00:00:00 2001 From: Luca Ciucci Date: Fri, 2 May 2025 09:16:09 +0200 Subject: [PATCH] sca: enforce selection of a single ECLAIR_RULESET in configuration This check prevents misconfigurations where more than one ruleset is selected, ensuring that the analysis is not silently performed with an unintended configuration. Signed-off-by: Luca Ciucci --- cmake/sca/eclair/sca_options.cmake | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/cmake/sca/eclair/sca_options.cmake b/cmake/sca/eclair/sca_options.cmake index 2402b0e8446..6f1201a6a7f 100644 --- a/cmake/sca/eclair/sca_options.cmake +++ b/cmake/sca/eclair/sca_options.cmake @@ -32,3 +32,28 @@ cmake_dependent_option(ECLAIR_FULL_TXT_ALL_AREAS "Show all areas in a full text OFF "ECLAIR_FULL_TXT" OFF) cmake_dependent_option(ECLAIR_FULL_TXT_FIRST_AREA "Show only the first area in a full text report" ON "ECLAIR_FULL_TXT" OFF) + +# Ensure that exactly one ECLAIR_RULESET is selected +set(ECLAIR_RULESETS + ECLAIR_RULESET_FIRST_ANALYSIS + ECLAIR_RULESET_STU + ECLAIR_RULESET_STU_HEAVY + ECLAIR_RULESET_WP + ECLAIR_RULESET_STD_LIB + ECLAIR_RULESET_USER +) + +set(selected_rulesets "") +foreach(ruleset ${ECLAIR_RULESETS}) + if(${ruleset}) + list(APPEND selected_rulesets ${ruleset}) + endif() +endforeach() + +list(LENGTH selected_rulesets selected_count) +if(selected_count EQUAL 0) + message(FATAL_ERROR "No ECLAIR_RULESET is selected. Please select exactly one.") +elseif(selected_count GREATER 1) + message(FATAL_ERROR "Only one ECLAIR_RULESET can be selected at a time. + Selected: ${selected_rulesets}") +endif()