From a50d1a74dcf26b4304ed47916e20d932a90bc1ce Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Sun, 9 Nov 2025 03:34:48 +0800 Subject: [PATCH] [gn] enable warnings (#12121) This commit suppresses the undefined warnings in mbedtls. To detect such warnings in OpenThread, this commit also enables warnings check for gn BUILD and fixes issues found. --- BUILD.gn | 7 ++++++ src/core/config/misc.h | 9 ++++++++ src/lib/spinel/BUILD.gn | 10 +++++++-- src/lib/spinel/openthread-spinel-config.h | 27 +++++++++++++++++++++++ src/lib/spinel/spinel_driver.cpp | 3 +-- src/lib/spinel/spinel_driver.hpp | 7 ++---- third_party/mbedtls/BUILD.gn | 11 +++++++++ 7 files changed, 65 insertions(+), 9 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index dce4e68b3..764182b00 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -33,6 +33,13 @@ config("openthread_config") { defines += [ "OPENTHREAD_CONFIG_FILE=${openthread_config_file}" ] } + cflags = [ + "-Werror", + "-Wall", + "-Wextra", + "-Wundef", + ] + include_dirs = openthread_project_include_dirs include_dirs += [ diff --git a/src/core/config/misc.h b/src/core/config/misc.h index 4c9577ef0..bcfed58c8 100644 --- a/src/core/config/misc.h +++ b/src/core/config/misc.h @@ -629,6 +629,15 @@ #define OPENTHREAD_CONFIG_USE_STD_NEW 0 #endif +/** + * @def OPENTHREAD_PLATFORM_NEXUS + * + * Define 1 to enable nexus platform. + */ +#ifndef OPENTHREAD_PLATFORM_NEXUS +#define OPENTHREAD_PLATFORM_NEXUS 0 +#endif + /** * @} */ diff --git a/src/lib/spinel/BUILD.gn b/src/lib/spinel/BUILD.gn index c83cc08ea..7f8aefe1e 100644 --- a/src/lib/spinel/BUILD.gn +++ b/src/lib/spinel/BUILD.gn @@ -79,7 +79,10 @@ static_library("libopenthread-spinel-ncp") { "../../core:libopenthread_core_headers", "../platform:libopenthread-platform", ] - public_configs = [ ":spinel_config_openthread_message_enable" ] + public_configs = [ + ":spinel_config_openthread_message_enable", + "../../..:openthread_ftd_config", + ] } static_library("libopenthread-spinel-rcp") { @@ -89,5 +92,8 @@ static_library("libopenthread-spinel-rcp") { "../../core:libopenthread_core_headers", "../platform:libopenthread-platform", ] - public_configs = [ ":spinel_config_openthread_message_disable" ] + public_configs = [ + ":spinel_config_openthread_message_disable", + "../../..:openthread_radio_config", + ] } diff --git a/src/lib/spinel/openthread-spinel-config.h b/src/lib/spinel/openthread-spinel-config.h index fb99a63be..c8b853bf3 100644 --- a/src/lib/spinel/openthread-spinel-config.h +++ b/src/lib/spinel/openthread-spinel-config.h @@ -172,4 +172,31 @@ #define OPENTHREAD_SPINEL_CONFIG_COPROCESSOR_RESET_FAILURE_CALLBACK_ENABLE 0 #endif +/** + * @def OPENTHREAD_SPINEL_CONFIG_SKIP_RESET_IF_READY + * + * Enables skipping reset if it's ready. + */ +#ifndef OPENTHREAD_SPINEL_CONFIG_SKIP_RESET_IF_READY +#if defined(OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE) && OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE +// Avoid resetting the device twice in a row in Multipan RCP architecture +#define OPENTHREAD_SPINEL_CONFIG_SKIP_RESET_IF_READY 1 +#else +#define OPENTHREAD_SPINEL_CONFIG_SKIP_RESET_IF_READY 0 +#endif +#endif + +/** + * @def OPENTHREAD_SPINEL_CONFIG_MAX_INTERFACE_ID + * + * Specifies the maximum number of Spinel interface IDs. + */ +#ifndef OPENTHREAD_SPINEL_CONFIG_MAX_INTERFACE_ID +#if defined(OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE) && OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE +#define OPENTHREAD_SPINEL_CONFIG_MAX_INTERFACE_ID 4 +#else +#define OPENTHREAD_SPINEL_CONFIG_MAX_INTERFACE_ID 1 +#endif +#endif + #endif // OPENTHREAD_SPINEL_CONFIG_H_ diff --git a/src/lib/spinel/spinel_driver.cpp b/src/lib/spinel/spinel_driver.cpp index 9ef7e87a1..e735c5b2f 100644 --- a/src/lib/spinel/spinel_driver.cpp +++ b/src/lib/spinel/spinel_driver.cpp @@ -137,8 +137,7 @@ void SpinelDriver::ResetCoprocessor(bool aSoftwareReset) bool hardwareReset; bool resetDone = false; -#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE - // Avoid resetting the device twice in a row in Multipan RCP architecture +#if OPENTHREAD_SPINEL_CONFIG_SKIP_RESET_IF_READY VerifyOrExit(!mIsCoprocessorReady, resetDone = true); #endif diff --git a/src/lib/spinel/spinel_driver.hpp b/src/lib/spinel/spinel_driver.hpp index 8f34c7043..80fff7edf 100644 --- a/src/lib/spinel/spinel_driver.hpp +++ b/src/lib/spinel/spinel_driver.hpp @@ -33,6 +33,7 @@ #include "lib/spinel/coprocessor_type.h" #include "lib/spinel/logger.hpp" +#include "lib/spinel/openthread-spinel-config.h" #include "lib/spinel/spinel.h" #include "lib/spinel/spinel_interface.hpp" @@ -49,11 +50,7 @@ namespace Spinel { /** * Maximum number of Spinel Interface IDs. */ -#if OPENTHREAD_CONFIG_MULTIPAN_RCP_ENABLE -static constexpr uint8_t kSpinelHeaderMaxNumIid = 4; -#else -static constexpr uint8_t kSpinelHeaderMaxNumIid = 1; -#endif +static constexpr uint8_t kSpinelHeaderMaxNumIid = OPENTHREAD_SPINEL_CONFIG_MAX_INTERFACE_ID; class SpinelDriver : public otSpinelDriver, public Logger { diff --git a/third_party/mbedtls/BUILD.gn b/third_party/mbedtls/BUILD.gn index 8da087f1b..aea209720 100644 --- a/third_party/mbedtls/BUILD.gn +++ b/third_party/mbedtls/BUILD.gn @@ -41,8 +41,18 @@ config("mbedtls_config") { ] defines = [ "MBEDTLS_CONFIG_FILE=\"${mbedtls_config_file}\"" ] +} + +config("warnings_fix_config") { cflags = [ "-Wno-conversion", + "-Wno-undef", + ] +} + +group("warnings_fix") { + public_configs = [ + ":warnings_fix_config", ] } @@ -314,6 +324,7 @@ static_library("mbedtls") { ] public_deps = mbedtls_deps + public_deps += [ ":warnings_fix" ] public_configs = [ ":mbedtls_config" ] }