From 0dec4cf927be51c7f2ae9e438a2f630cf32a004a Mon Sep 17 00:00:00 2001 From: Nikolay Agishev Date: Thu, 22 Dec 2022 15:46:04 +0400 Subject: [PATCH] toolchain: Move extra warning options to toolchain abstraction Move extra warning option from generic twister script into compiler-dependent config files. ARCMWDT compiler doesn't support extra warning options ex. "-Wl,--fatal-warnings". To avoid build fails flag "disable_warnings_as_errors" should be passed to twister. This allows all warning messages and make atomatic test useles. Signed-off-by: Nikolay Agishev --- CMakeLists.txt | 7 +++++++ Kconfig.zephyr | 6 +++++- cmake/compiler/arcmwdt/compiler_flags.cmake | 4 ++++ cmake/compiler/compiler_flags_template.cmake | 4 ++++ cmake/compiler/gcc/compiler_flags.cmake | 4 ++++ cmake/linker/arcmwdt/linker_flags.cmake | 4 ++++ cmake/linker/ld/clang/linker_flags.cmake | 3 +++ cmake/linker/ld/gcc/linker_flags.cmake | 3 +++ cmake/linker/linker_flags_template.cmake | 3 +++ scripts/pylib/twister/twisterlib/runner.py | 10 +++------- 10 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 cmake/linker/arcmwdt/linker_flags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8894b47628b..8beff8ab6a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,6 +156,13 @@ endif() zephyr_compile_options($<$:$>) zephyr_compile_options($<$:$>) +# Extra warnings options for twister run +if (CONFIG_COMPILER_WARNINGS_AS_ERRORS) + zephyr_compile_options($<$:$>) + zephyr_compile_options($<$:$>) + zephyr_link_libraries($) +endif() + # @Intent: Set compiler flags to enable buffer overflow checks in libc functions # @details: # Kconfig.zephyr "Detect buffer overflows in libc calls" is a kconfig choice, diff --git a/Kconfig.zephyr b/Kconfig.zephyr index 2dd8492f750..20f859876e9 100644 --- a/Kconfig.zephyr +++ b/Kconfig.zephyr @@ -360,9 +360,13 @@ config NO_OPTIMIZATIONS help Compiler optimizations will be set to -O0 independently of other options. - endchoice +config COMPILER_WARNINGS_AS_ERRORS + bool "Treat warnings as errors" + help + Turn on "warning as error" toolchain flags + config COMPILER_COLOR_DIAGNOSTICS bool "Colored diagnostics" default y diff --git a/cmake/compiler/arcmwdt/compiler_flags.cmake b/cmake/compiler/arcmwdt/compiler_flags.cmake index bab3ab5c135..a4f1a13afff 100644 --- a/cmake/compiler/arcmwdt/compiler_flags.cmake +++ b/cmake/compiler/arcmwdt/compiler_flags.cmake @@ -134,6 +134,10 @@ set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b "") # Flag for disabling strict aliasing rule in C and C++ set_compiler_property(PROPERTY no_strict_aliasing -fno-strict-aliasing) +# Flags for set extra warnigs (ARCMWDT asm can't recognize --fatal-warnings. Skip it) +set_property(TARGET compiler PROPERTY warnings_as_errors -Werror) +set_property(TARGET asm PROPERTY warnings_as_errors -Werror) + # Disable exceptions flag in C++ set_property(TARGET compiler-cpp PROPERTY no_exceptions "-fno-exceptions") diff --git a/cmake/compiler/compiler_flags_template.cmake b/cmake/compiler/compiler_flags_template.cmake index b043bffbbfe..e03fb6152a6 100644 --- a/cmake/compiler/compiler_flags_template.cmake +++ b/cmake/compiler/compiler_flags_template.cmake @@ -68,6 +68,10 @@ set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b) # Flag for disabling strict aliasing rule in C and C++ set_compiler_property(PROPERTY no_strict_aliasing) +# Extra warnings options for twister run +set_property(TARGET compiler PROPERTY warnings_as_errors) +set_property(TARGET asm PROPERTY warnings_as_errors) + # Flag for disabling exceptions in C++ set_property(TARGET compiler-cpp PROPERTY no_exceptions) diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index 6d8590b7fee..08b229672c4 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -134,6 +134,10 @@ set_property(TARGET compiler-cpp PROPERTY dialect_cpp2b "-std=c++2b" # Flag for disabling strict aliasing rule in C and C++ set_compiler_property(PROPERTY no_strict_aliasing -fno-strict-aliasing) +# Extra warning options +set_property(TARGET compiler PROPERTY warnings_as_errors -Werror) +set_property(TARGET asm PROPERTY warnings_as_errors -Werror -Wa,--fatal-warnings) + # Disable exceptions flag in C++ set_property(TARGET compiler-cpp PROPERTY no_exceptions "-fno-exceptions") diff --git a/cmake/linker/arcmwdt/linker_flags.cmake b/cmake/linker/arcmwdt/linker_flags.cmake new file mode 100644 index 00000000000..4675e97e14e --- /dev/null +++ b/cmake/linker/arcmwdt/linker_flags.cmake @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 + +# Extra warnings options for twister run +set_property(TARGET linker PROPERTY warnings_as_errors -Wl,--fatal-warnings) diff --git a/cmake/linker/ld/clang/linker_flags.cmake b/cmake/linker/ld/clang/linker_flags.cmake index fd4f6f2b48e..9339e0c49a5 100644 --- a/cmake/linker/ld/clang/linker_flags.cmake +++ b/cmake/linker/ld/clang/linker_flags.cmake @@ -2,3 +2,6 @@ if (NOT CONFIG_COVERAGE_GCOV) set_property(TARGET linker PROPERTY coverage --coverage) endif() + +# Extra warnings options for twister run +set_property(TARGET linker PROPERTY ld_extra_warning_options -Wl,--fatal-warnings) diff --git a/cmake/linker/ld/gcc/linker_flags.cmake b/cmake/linker/ld/gcc/linker_flags.cmake index 0fb79bc13c9..4cde7d96ff3 100644 --- a/cmake/linker/ld/gcc/linker_flags.cmake +++ b/cmake/linker/ld/gcc/linker_flags.cmake @@ -12,3 +12,6 @@ check_set_linker_property(TARGET linker APPEND PROPERTY gprof -pg) # GCC 11 by default emits DWARF version 5 which cannot be parsed by # pyelftools. Can be removed once pyelftools supports v5. add_link_options(-gdwarf-4) + +# Extra warnings options for twister run +set_property(TARGET linker PROPERTY warnings_as_errors -Wl,--fatal-warnings) diff --git a/cmake/linker/linker_flags_template.cmake b/cmake/linker/linker_flags_template.cmake index 910515c3119..7e0118ddcb3 100644 --- a/cmake/linker/linker_flags_template.cmake +++ b/cmake/linker/linker_flags_template.cmake @@ -9,3 +9,6 @@ set_property(TARGET linker PROPERTY coverage) # If memory reporting is a post build command, please use # cmake/bintools/bintools.cmake instead. check_set_linker_property(TARGET linker PROPERTY memusage) + +# Extra warnings options for twister run +set_property(TARGET linker PROPERTY warnings_as_errors) diff --git a/scripts/pylib/twister/twisterlib/runner.py b/scripts/pylib/twister/twisterlib/runner.py index a86c59fd0cc..2b999728230 100644 --- a/scripts/pylib/twister/twisterlib/runner.py +++ b/scripts/pylib/twister/twisterlib/runner.py @@ -289,21 +289,17 @@ class CMake: def run_cmake(self, args=""): if not self.options.disable_warnings_as_errors: - ldflags = "-Wl,--fatal-warnings" - cflags = "-Werror" - aflags = "-Werror -Wa,--fatal-warnings" + warnings_as_errors = 'y' gen_defines_args = "--edtlib-Werror" else: - ldflags = cflags = aflags = "" + warnings_as_errors = 'n' gen_defines_args = "" logger.debug("Running cmake on %s for %s" % (self.source_dir, self.platform.name)) cmake_args = [ f'-B{self.build_dir}', f'-DTC_RUNID={self.instance.run_id}', - f'-DEXTRA_CFLAGS={cflags}', - f'-DEXTRA_AFLAGS={aflags}', - f'-DEXTRA_LDFLAGS={ldflags}', + f'-DCONFIG_COMPILER_WARNINGS_AS_ERRORS={warnings_as_errors}', f'-DEXTRA_GEN_DEFINES_ARGS={gen_defines_args}', f'-G{self.env.generator}' ]