From 93c994723ea6d14f74bbede18daf6572b61c546f Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Mon, 15 Mar 2021 08:27:16 +0800 Subject: [PATCH] [posix] detect POSIX in source (#6259) --- Android.mk | 1 - etc/gn/openthread.gni | 3 --- examples/platforms/simulation/CMakeLists.txt | 1 - include/openthread/instance.h | 2 +- src/cli/BUILD.gn | 5 ----- src/cli/Makefile.am | 10 ---------- src/cli/cli.cpp | 2 +- src/cli/cli.hpp | 4 ++-- src/cli/cli_config.h | 9 +++++++++ src/cli/cli_uart.cpp | 2 +- src/posix/platform/CMakeLists.txt | 2 -- 11 files changed, 14 insertions(+), 27 deletions(-) diff --git a/Android.mk b/Android.mk index ce7f0f3f5..4c7d80cbb 100644 --- a/Android.mk +++ b/Android.mk @@ -45,7 +45,6 @@ OPENTHREAD_PUBLIC_CFLAGS := \ -DOPENTHREAD_CONFIG_MAC_FILTER_ENABLE=1 \ -DOPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE=1 \ -DOPENTHREAD_FTD=1 \ - -DOPENTHREAD_POSIX=1 \ -DOPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE=1 \ $(NULL) diff --git a/etc/gn/openthread.gni b/etc/gn/openthread.gni index 40598cd48..2737adc63 100644 --- a/etc/gn/openthread.gni +++ b/etc/gn/openthread.gni @@ -55,9 +55,6 @@ declare_args() { # Use external mbedtls. If blank, internal mbedtls will be used. openthread_external_mbedtls = "" - # Enable building for POSIX platforms. - openthread_posix = current_os == "linux" - # Package name for OpenThread. openthread_package_name = "OPENTHREAD" diff --git a/examples/platforms/simulation/CMakeLists.txt b/examples/platforms/simulation/CMakeLists.txt index 9352fba1e..4a08b9e02 100644 --- a/examples/platforms/simulation/CMakeLists.txt +++ b/examples/platforms/simulation/CMakeLists.txt @@ -52,7 +52,6 @@ list(APPEND OT_PLATFORM_DEFINES "_BSD_SOURCE=1" "_DEFAULT_SOURCE=1" "OPENTHREAD_EXAMPLES_SIMULATION=1" - "OPENTHREAD_POSIX=1" "OPENTHREAD_CONFIG_NCP_UART_ENABLE=1" ) set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 8f92ab4bd..3f7713d82 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (83) +#define OPENTHREAD_API_VERSION (84) /** * @addtogroup api-instance diff --git a/src/cli/BUILD.gn b/src/cli/BUILD.gn index 3464a8601..3fbd6b021 100644 --- a/src/cli/BUILD.gn +++ b/src/cli/BUILD.gn @@ -58,11 +58,6 @@ openthread_cli_sources = [ config("cli_config") { defines = [] - if (openthread_posix) { - defines += ["OPENTHREAD_POSIX=1"] - } else { - defines += ["OPENTHREAD_POSIX=0"] - } } static_library("libopenthread-cli-ftd") { diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index 3491638a8..f4c1032f3 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -125,16 +125,6 @@ CPPFLAGS_COMMON = \ $(OPENTHREAD_TARGET_DEFINES) \ $(NULL) -if OPENTHREAD_POSIX -CPPFLAGS_COMMON += \ - -DOPENTHREAD_POSIX=1 \ - $(NULL) -else -CPPFLAGS_COMMON += \ - -DOPENTHREAD_POSIX=0 \ - $(NULL) -endif - libopenthread_cli_mtd_a_CPPFLAGS = \ -DOPENTHREAD_MTD=1 \ -DOPENTHREAD_FTD=0 \ diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 6e2bafd0c..3c99c916f 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -1662,7 +1662,7 @@ exit: return error; } -#if OPENTHREAD_POSIX +#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) otError Interpreter::ProcessExit(uint8_t aArgsLength, char *aArgs[]) { OT_UNUSED_VARIABLE(aArgsLength); diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index 9a8a8ae75..c5d1b95f0 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -367,7 +367,7 @@ private: otError ProcessEidCache(uint8_t aArgsLength, char *aArgs[]); #endif otError ProcessEui64(uint8_t aArgsLength, char *aArgs[]); -#if OPENTHREAD_POSIX +#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) otError ProcessExit(uint8_t aArgsLength, char *aArgs[]); #endif otError ProcessLog(uint8_t aArgsLength, char *aArgs[]); @@ -678,7 +678,7 @@ private: {"eidcache", &Interpreter::ProcessEidCache}, #endif {"eui64", &Interpreter::ProcessEui64}, -#if OPENTHREAD_POSIX +#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) {"exit", &Interpreter::ProcessExit}, #endif {"extaddr", &Interpreter::ProcessExtAddress}, diff --git a/src/cli/cli_config.h b/src/cli/cli_config.h index 16976bb4f..cbab807a3 100644 --- a/src/cli/cli_config.h +++ b/src/cli/cli_config.h @@ -37,6 +37,15 @@ #include "openthread-core-config.h" +#ifndef OPENTHREAD_POSIX +#if defined(__ANDROID__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__linux__) || defined(__NetBSD__) || \ + defined(__unix__) +#define OPENTHREAD_POSIX 1 +#else +#define OPENTHREAD_POSIX 0 +#endif +#endif + /** * @def OPENTHREAD_CONFIG_CLI_MAX_LINE_LENGTH * diff --git a/src/cli/cli_uart.cpp b/src/cli/cli_uart.cpp index 4b573a020..944548a60 100644 --- a/src/cli/cli_uart.cpp +++ b/src/cli/cli_uart.cpp @@ -152,7 +152,7 @@ void Uart::ReceiveTask(const uint8_t *aBuf, uint16_t aBufLength) break; #if !OPENTHREAD_CONFIG_UART_CLI_RAW -#if OPENTHREAD_POSIX +#if OPENTHREAD_POSIX && !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION) case 0x03: // ASCII for Ctrl-C kill(0, SIGINT); diff --git a/src/posix/platform/CMakeLists.txt b/src/posix/platform/CMakeLists.txt index 44552dc56..2056a531f 100644 --- a/src/posix/platform/CMakeLists.txt +++ b/src/posix/platform/CMakeLists.txt @@ -53,8 +53,6 @@ if(NOT OT_CONFIG) set(OT_CONFIG ${OT_CONFIG} PARENT_SCOPE) endif() -list(APPEND OT_PLATFORM_DEFINES "OPENTHREAD_POSIX=1") - set(OT_PLATFORM_DEFINES ${OT_PLATFORM_DEFINES} PARENT_SCOPE) list(APPEND OT_PLATFORM_DEFINES "OPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"${OT_CONFIG}\"")