Skip to content

Commit 91dde76

Browse files
nvetrininashif
authored andcommitted
sca: eclair: improve ECLAIR integration
Various improvements to the integration files in order to obtain correct static analysis results: - variable `ECLAIR_WORKSPACE' is set to the build output directory, to allow multiple ECLAIR analyses running in parallel on the same machine without conflicts; - fix the evaluation order of rulesets to allow a user-provided ruleset to be selected without a cmake options file that undefines other ECLAIR_RULESET_* variables; - add a clean-only frame to initiate the analysis and a project frame to end it. Signed-off-by: Nicola Vetrini <[email protected]>
1 parent bdd9426 commit 91dde76

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

cmake/sca/eclair/sca.cmake

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ set(ECLAIR_ANALYSIS_ECL_DIR "${ZEPHYR_BASE}/cmake/sca/eclair/ECL")
3030
set(ECLAIR_DIAGNOSTICS_OUTPUT "${ECLAIR_OUTPUT_DIR}/DIAGNOSTIC.txt")
3131
set(ECLAIR_ANALYSIS_DATA_DIR "${ECLAIR_OUTPUT_DIR}/analysis_data")
3232
set(ECLAIR_PROJECT_ECD "${ECLAIR_OUTPUT_DIR}/PROJECT.ecd")
33+
set(ECLAIR_WORKSPACE "${ECLAIR_OUTPUT_DIR}/eclair_workspace")
3334
set(CC_ALIASES "${CMAKE_C_COMPILER}")
3435
set(CXX_ALIASES "${CMAKE_CXX_COMPILER}")
3536
set(AS_ALIASES "${CMAKE_AS}")
@@ -43,7 +44,14 @@ set(ECLAIR_REPORT_ADDITIONAL_OPTIONS "")
4344
set(ECLAIR_RULESET first_analysis)
4445

4546
# ECLAIR env
46-
if(ECLAIR_RULESET_FIRST_ANALYSIS)
47+
if(ECLAIR_RULESET_USER)
48+
set(ECLAIR_RULESET ${ECLAIR_USER_RULESET_NAME})
49+
if(IS_ABSOLUTE ${ECLAIR_USER_RULESET_PATH})
50+
set(ECLAIR_ANALYSIS_ECL_DIR ${ECLAIR_USER_RULESET_PATH})
51+
else()
52+
set(ECLAIR_ANALYSIS_ECL_DIR ${APPLICATION_CONFIG_DIR}/${ECLAIR_USER_RULESET_PATH})
53+
endif()
54+
elseif(ECLAIR_RULESET_FIRST_ANALYSIS)
4755
set(ECLAIR_RULESET first_analysis)
4856
elseif(ECLAIR_RULESET_STU)
4957
set(ECLAIR_RULESET STU)
@@ -53,13 +61,6 @@ elseif(ECLAIR_RULESET_WP)
5361
set(ECLAIR_RULESET WP)
5462
elseif(ECLAIR_RULESET_STD_LIB)
5563
set(ECLAIR_RULESET std_lib)
56-
elseif(ECLAIR_RULESET_USER)
57-
set(ECLAIR_RULESET ${ECLAIR_USER_RULESET_NAME})
58-
if(IS_ABSOLUTE ${ECLAIR_USER_RULESET_PATH})
59-
set(ECLAIR_ANALYSIS_ECL_DIR ${ECLAIR_USER_RULESET_PATH})
60-
else()
61-
set(ECLAIR_ANALYSIS_ECL_DIR ${APPLICATION_CONFIG_DIR}/${ECLAIR_USER_RULESET_PATH})
62-
endif()
6364
endif()
6465

6566
# ECLAIR report
@@ -106,20 +107,47 @@ endif()
106107
message(STATUS "ECLAIR outputs have been written to: ${ECLAIR_OUTPUT_DIR}")
107108
message(STATUS "ECLAIR ECB files have been written to: ${ECLAIR_ANALYSIS_DATA_DIR}")
108109

110+
list(APPEND ECLAIR_CLEAN_ARGS
111+
+clean
112+
-project_name=${ECLAIR_PROJECT_NAME} -project_root=${ZEPHYR_BASE}
113+
-eval_file=${ECLAIR_ECL_DIR}/analysis.ecl
114+
-eval_file=${ECLAIR_ANALYSIS_ECL_DIR}/analysis_${ECLAIR_RULESET}.ecl
115+
${ECLAIR_ENV_ADDITIONAL_OPTIONS})
116+
109117
add_custom_target(eclair_setup_analysis_dir ALL
110118
COMMAND ${CMAKE_COMMAND} -E remove_directory ${ECLAIR_ANALYSIS_DATA_DIR}
111119
COMMAND ${CMAKE_COMMAND} -E make_directory ${ECLAIR_ANALYSIS_DATA_DIR}
120+
COMMAND ${CMAKE_COMMAND} -E env
121+
ECLAIR_DIAGNOSTICS_OUTPUT=${ECLAIR_DIAGNOSTICS_OUTPUT}
122+
ECLAIR_DATA_DIR=${ECLAIR_ANALYSIS_DATA_DIR}
123+
${ECLAIR_ENV} ${ECLAIR_CLEAN_ARGS} --
112124
VERBATIM
113125
USES_TERMINAL
114126
)
115127

116-
# configure the camke script which will be used to replace the compiler call with the eclair_env
128+
# configure the cmake script which will be used to replace the compiler call with the eclair_env
117129
# call which calls the compiler and to generate analysis files.
118130
configure_file(${CMAKE_CURRENT_LIST_DIR}/eclair.template ${ECLAIR_OUTPUT_DIR}/eclair.cmake @ONLY)
119131

120132
set(launch_environment ${CMAKE_COMMAND} -P ${ECLAIR_OUTPUT_DIR}/eclair.cmake --)
121133
set(CMAKE_C_COMPILER_LAUNCHER ${launch_environment} CACHE INTERNAL "")
122134

135+
list(APPEND ECLAIR_PROJECT_ARGS
136+
+project
137+
-project_name=${ECLAIR_PROJECT_NAME} -project_root=${ZEPHYR_BASE}
138+
-eval_file=${ECLAIR_ECL_DIR}/analysis.ecl
139+
-eval_file=${ECLAIR_ANALYSIS_ECL_DIR}/analysis_${ECLAIR_RULESET}.ecl
140+
${ECLAIR_ENV_ADDITIONAL_OPTIONS})
141+
142+
add_custom_target(eclair_project_analysis ALL
143+
COMMAND ${CMAKE_COMMAND} -E env
144+
ECLAIR_DIAGNOSTICS_OUTPUT=${ECLAIR_DIAGNOSTICS_OUTPUT}
145+
ECLAIR_DATA_DIR=${ECLAIR_ANALYSIS_DATA_DIR}
146+
${ECLAIR_ENV} ${ECLAIR_PROJECT_ARGS} --
147+
VERBATIM
148+
USES_TERMINAL
149+
)
150+
123151
# This target is used to generate the ECLAIR database when all the compilation is done and the
124152
# elf file was generated with this we cane make sure that the analysis is completed.
125153
add_custom_target(eclair_report ALL
@@ -141,4 +169,6 @@ add_custom_target(eclair_summary_print ALL
141169
-overall_txt=${ECLAIR_OUTPUT_DIR}/summary_overall.txt
142170
COMMAND ${CMAKE_COMMAND} -E cat ${ECLAIR_OUTPUT_DIR}/summary_overall.txt
143171
)
172+
173+
add_dependencies(eclair_report eclair_project_analysis)
144174
add_dependencies(eclair_summary_print eclair_report)

0 commit comments

Comments
 (0)