From 3526af39f8a30370364fb04e47587846b6abacc2 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Tue, 6 Jun 2017 14:07:00 -0700 Subject: [PATCH] Change `enable-default-logging` build feature to a config option (#1879) This commit changes the `--enable-default-logging` option into a OpenThread config option `OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT`. Makefiles and project core config header files for different platforms are also updated accordingly. --- configure.ac | 30 ------------ examples/Makefile-cc2538 | 1 - examples/Makefile-da15000 | 1 - examples/Makefile-efr32 | 1 - examples/Makefile-emsk | 1 - examples/Makefile-kw41z | 1 - examples/Makefile-posix | 9 +++- examples/common-switches.mk | 4 -- .../cc2538/openthread-core-cc2538-config.h | 8 ++++ .../da15000/openthread-core-da15000-config.h | 8 ++++ .../efr32/openthread-core-efr32-config.h | 8 ++++ .../emsk/openthread-core-emsk-config.h | 8 ++++ .../kw41z/openthread-core-kw41z-config.h | 8 ++++ examples/platforms/nrf52840/logging.c | 4 +- examples/platforms/nrf52840/platform.c | 4 +- .../posix/openthread-core-posix-config.h | 46 +++++++++++++++++++ include/openthread-windows-config.h | 4 +- src/cli/cli_uart.cpp | 4 +- src/core/openthread-core-default-config.h | 13 ++++++ src/ncp/ncp_uart.cpp | 2 +- 20 files changed, 116 insertions(+), 49 deletions(-) create mode 100644 examples/platforms/posix/openthread-core-posix-config.h diff --git a/configure.ac b/configure.ac index b58785674..7c25ac2b8 100644 --- a/configure.ac +++ b/configure.ac @@ -837,36 +837,6 @@ AC_SUBST(OPENTHREAD_ENABLE_CHILD_SUPERVISION) AM_CONDITIONAL([OPENTHREAD_ENABLE_CHILD_SUPERVISION], [test "${enable_child_supervision}" = "yes"]) AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_CHILD_SUPERVISION],[${OPENTHREAD_ENABLE_CHILD_SUPERVISION}],[Define to 1 if you want to use child supervision feature]) -# -# Default Logging -# - -AC_ARG_ENABLE(default_logging, - [AS_HELP_STRING([--enable-default-logging],[Enable default logging support @<:@default=no@:>@.])], - [ - case "${enableval}" in - - no|yes) - enable_default_logging=${enableval} - ;; - - *) - AC_MSG_ERROR([Invalid value ${enable_default_logging} for --enable-default-logging]) - ;; - esac - ], - [enable_default_logging=no]) - -if test "$enable_default_logging" = "yes"; then - OPENTHREAD_ENABLE_DEFAULT_LOGGING=1 -else - OPENTHREAD_ENABLE_DEFAULT_LOGGING=0 -fi - -AC_SUBST(OPENTHREAD_ENABLE_DEFAULT_LOGGING) -AM_CONDITIONAL([OPENTHREAD_ENABLE_DEFAULT_LOGGING], [test "${enable_default_logging}" = "yes"]) -AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_DEFAULT_LOGGING],[${OPENTHREAD_ENABLE_DEFAULT_LOGGING}],[Define to 1 if you want to enable default logging]) - # # Log for certification test # diff --git a/examples/Makefile-cc2538 b/examples/Makefile-cc2538 index 31216b3ba..c354d1074 100644 --- a/examples/Makefile-cc2538 +++ b/examples/Makefile-cc2538 @@ -50,7 +50,6 @@ configure_OPTIONS = \ --with-platform-info=CC2538 \ $(NULL) -DEFAULT_LOGGING ?= 1 include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/common-switches.mk TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. diff --git a/examples/Makefile-da15000 b/examples/Makefile-da15000 index 02497e595..e349c1ae2 100644 --- a/examples/Makefile-da15000 +++ b/examples/Makefile-da15000 @@ -49,7 +49,6 @@ configure_OPTIONS = \ --with-platform-info=DA15000 \ $(NULL) -DEFAULT_LOGGING ?= 1 include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/common-switches.mk TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. diff --git a/examples/Makefile-efr32 b/examples/Makefile-efr32 index be4de6a82..5175de8ef 100644 --- a/examples/Makefile-efr32 +++ b/examples/Makefile-efr32 @@ -51,7 +51,6 @@ configure_OPTIONS = \ MBEDTLS_CPPFLAGS="$(EFR32_MBEDTLS_CPPFLAGS)" \ $(NULL) -DEFAULT_LOGGING ?= 1 include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/common-switches.mk TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. diff --git a/examples/Makefile-emsk b/examples/Makefile-emsk index 75c6f035f..01a4f07c3 100644 --- a/examples/Makefile-emsk +++ b/examples/Makefile-emsk @@ -45,7 +45,6 @@ configure_OPTIONS = \ --enable-cli-app=all \ --enable-ncp-app=all \ --with-ncp-bus=uart \ - --enable-default-logging \ --with-examples=emsk \ --with-platform-info=EMSK \ $(NULL) diff --git a/examples/Makefile-kw41z b/examples/Makefile-kw41z index 67ac7100c..3f228038b 100644 --- a/examples/Makefile-kw41z +++ b/examples/Makefile-kw41z @@ -50,7 +50,6 @@ configure_OPTIONS = \ --with-platform-info=KW41Z \ $(NULL) -DEFAULT_LOGGING ?= 1 include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/common-switches.mk TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. diff --git a/examples/Makefile-posix b/examples/Makefile-posix index 333a3413f..b7acfd7e2 100644 --- a/examples/Makefile-posix +++ b/examples/Makefile-posix @@ -41,9 +41,17 @@ RM_F := rm -f BuildJobs ?= 10 +TopSourceDir := $(dir $(shell readlink $(firstword $(MAKEFILE_LIST)))).. +AbsTopSourceDir := $(dir $(realpath $(firstword $(MAKEFILE_LIST)))).. + +CONFIG_FILE = OPENTHREAD_PROJECT_CORE_CONFIG_FILE='\"openthread-core-posix-config.h\"' +CONFIG_FILE_PATH = $(AbsTopSourceDir)/examples/platforms/posix/ + COMMONCFLAGS := \ -O1 \ -g \ + -D$(CONFIG_FILE) \ + -I$(CONFIG_FILE_PATH) \ $(NULL) CPPFLAGS += \ @@ -86,7 +94,6 @@ configure_OPTIONS = \ --enable-ncp-app=all \ --with-ncp-bus=uart \ --enable-diag \ - --enable-default-logging \ --enable-raw-link-api=yes \ --with-examples=posix \ --with-platform-info=POSIX \ diff --git a/examples/common-switches.mk b/examples/common-switches.mk index 13a1873e8..b07d05d01 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -62,10 +62,6 @@ ifeq ($(DHCP6_SERVER),1) configure_OPTIONS += --enable-dhcp6-server endif -ifeq ($(DEFAULT_LOGGING),1) -configure_OPTIONS += --enable-default-logging -endif - ifeq ($(DISABLE_DOC),1) configure_OPTIONS += --disable-docs endif diff --git a/examples/platforms/cc2538/openthread-core-cc2538-config.h b/examples/platforms/cc2538/openthread-core-cc2538-config.h index 0ad985ce7..3cc0768c7 100644 --- a/examples/platforms/cc2538/openthread-core-cc2538-config.h +++ b/examples/platforms/cc2538/openthread-core-cc2538-config.h @@ -34,6 +34,14 @@ #ifndef OPENTHREAD_CORE_CC2538_CONFIG_H_ #define OPENTHREAD_CORE_CC2538_CONFIG_H_ +/** + * @def OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT + * + * Define to 1 to enable default log output. + * + */ +#define OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT 1 + /** * @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ACK_TIMEOUT * diff --git a/examples/platforms/da15000/openthread-core-da15000-config.h b/examples/platforms/da15000/openthread-core-da15000-config.h index dffb87c04..d1e18fd4e 100644 --- a/examples/platforms/da15000/openthread-core-da15000-config.h +++ b/examples/platforms/da15000/openthread-core-da15000-config.h @@ -36,6 +36,14 @@ #define SETTINGS_CONFIG_BASE_ADDRESS (0x7B000) +/** + * @def OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT + * + * Define to 1 to enable default log output. + * + */ +#define OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT 1 + /** * @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ACK_TIMEOUT * diff --git a/examples/platforms/efr32/openthread-core-efr32-config.h b/examples/platforms/efr32/openthread-core-efr32-config.h index f8884e8fa..96fcfe960 100644 --- a/examples/platforms/efr32/openthread-core-efr32-config.h +++ b/examples/platforms/efr32/openthread-core-efr32-config.h @@ -36,6 +36,14 @@ #define OPENTHREAD_CORE_EFR32_CONFIG_H_ /** + * @def OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT + * + * Define to 1 to enable default log output. + * + */ +#define OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT 1 + +/* * @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_RETRANSMIT * * Define to 1 if you want to enable software retransmission logic. diff --git a/examples/platforms/emsk/openthread-core-emsk-config.h b/examples/platforms/emsk/openthread-core-emsk-config.h index 94f1e443d..558bdf058 100644 --- a/examples/platforms/emsk/openthread-core-emsk-config.h +++ b/examples/platforms/emsk/openthread-core-emsk-config.h @@ -34,6 +34,14 @@ #ifndef OPENTHREAD_CORE_EMSK_CONFIG_H_ #define OPENTHREAD_CORE_EMSK_CONFIG_H_ +/** + * @def OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT + * + * Define to 1 to enable default log output. + * + */ +#define OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT 1 + /** * @def OPENTHREAD_CONFIG_ENABLE_SOFTWARE_ACK_TIMEOUT * diff --git a/examples/platforms/kw41z/openthread-core-kw41z-config.h b/examples/platforms/kw41z/openthread-core-kw41z-config.h index 7946ec556..c801b89ea 100644 --- a/examples/platforms/kw41z/openthread-core-kw41z-config.h +++ b/examples/platforms/kw41z/openthread-core-kw41z-config.h @@ -35,6 +35,14 @@ #ifndef OPENTHREAD_CORE_KW41Z_CONFIG_H_ #define OPENTHREAD_CORE_KW41Z_CONFIG_H_ +/** + * @def OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT + * + * Define to 1 to enable default log output. + * + */ +#define OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT 1 + /** * @def SETTINGS_CONFIG_BASE_ADDRESS * diff --git a/examples/platforms/nrf52840/logging.c b/examples/platforms/nrf52840/logging.c index 57e5929a3..95d2bc37d 100644 --- a/examples/platforms/nrf52840/logging.c +++ b/examples/platforms/nrf52840/logging.c @@ -45,7 +45,7 @@ #include #include -#if (OPENTHREAD_ENABLE_DEFAULT_LOGGING == 0) +#if (OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT == 0) #include #if (LOG_RTT_COLOR_ENABLE == 1) @@ -174,4 +174,4 @@ exit: return; } -#endif // (OPENTHREAD_ENABLE_DEFAULT_LOGGING == 0) +#endif // (OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT == 0) diff --git a/examples/platforms/nrf52840/platform.c b/examples/platforms/nrf52840/platform.c index 3f2357331..9faaa2420 100644 --- a/examples/platforms/nrf52840/platform.c +++ b/examples/platforms/nrf52840/platform.c @@ -54,14 +54,14 @@ void PlatformInit(int argc, char *argv[]) nrf5MiscInit(); nrf5CryptoInit(); nrf5RadioInit(); -#if (OPENTHREAD_ENABLE_DEFAULT_LOGGING == 0) +#if (OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT == 0) nrf5LogInit(); #endif } void PlatformDeinit(void) { -#if (OPENTHREAD_ENABLE_DEFAULT_LOGGING == 0) +#if (OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT == 0) nrf5LogDeinit(); #endif nrf5RadioDeinit(); diff --git a/examples/platforms/posix/openthread-core-posix-config.h b/examples/platforms/posix/openthread-core-posix-config.h new file mode 100644 index 000000000..f4d5ddeef --- /dev/null +++ b/examples/platforms/posix/openthread-core-posix-config.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2017, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file includes posix compile-time configuration constants + * for OpenThread. + */ + +#ifndef OPENTHREAD_CORE_POSIX_CONFIG_H_ +#define OPENTHREAD_CORE_POSIX_CONFIG_H_ + +/** + * @def OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT + * + * Define to 1 to enable default log output. + * + */ +#define OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT 1 + +#endif // OPENTHREAD_CORE_POSIX_CONFIG_H_ diff --git a/include/openthread-windows-config.h b/include/openthread-windows-config.h index 83db31bfc..35a78f6d0 100644 --- a/include/openthread-windows-config.h +++ b/include/openthread-windows-config.h @@ -32,8 +32,8 @@ /* Define to 1 to enable the NCP SPI interface. */ // On the command line: #define OPENTHREAD_ENABLE_NCP_SPI 1 -/* Define to 1 if you want to enable default logging */ -#define OPENTHREAD_ENABLE_DEFAULT_LOGGING 1 +/* Define to 1 if you want to enable default log output. */ +#define OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT 1 /* Define to 1 to enable the commissioner role. */ #define OPENTHREAD_ENABLE_COMMISSIONER 1 diff --git a/src/cli/cli_uart.cpp b/src/cli/cli_uart.cpp index 5b4fa1f0e..523cd76bf 100644 --- a/src/cli/cli_uart.cpp +++ b/src/cli/cli_uart.cpp @@ -238,7 +238,7 @@ void Uart::SendDoneTask(void) Send(); } -#if OPENTHREAD_ENABLE_DEFAULT_LOGGING +#if OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT #ifdef __cplusplus extern "C" { #endif @@ -261,7 +261,7 @@ void otPlatLog(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aFormat #ifdef __cplusplus } // extern "C" #endif -#endif // OPENTHREAD_ENABLE_DEFAULT_LOGGING +#endif // OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT } // namespace Cli } // namespace ot diff --git a/src/core/openthread-core-default-config.h b/src/core/openthread-core-default-config.h index e983842f6..7c530f64e 100644 --- a/src/core/openthread-core-default-config.h +++ b/src/core/openthread-core-default-config.h @@ -599,6 +599,19 @@ #define OPENTHREAD_CONFIG_PLAT_LOG_FUNCTION otPlatLog #endif +/** + * @def OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT + * + * Define to 1 to enable default log output. + * + * When enabled OpenThread provides a default implementation for `otPlatLog()` which is tied to either NCP or CLI + * stream writes. + * + */ +#ifndef OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT +#define OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT 0 +#endif + /** * @def OPENTHREAD_CONFIG_NUM_DHCP_PREFIXES * diff --git a/src/ncp/ncp_uart.cpp b/src/ncp/ncp_uart.cpp index ee89612ba..f2dc96750 100644 --- a/src/ncp/ncp_uart.cpp +++ b/src/ncp/ncp_uart.cpp @@ -273,7 +273,7 @@ void NcpUart::HandleError(otError aError, uint8_t *aBuf, uint16_t aBufLength) otNcpStreamWrite(0, reinterpret_cast(hexbuf + 1), static_cast(strlen(hexbuf) - 1)); } -#if OPENTHREAD_ENABLE_DEFAULT_LOGGING +#if OPENTHREAD_CONFIG_ENABLE_DEFAULT_LOG_OUTPUT #ifdef __cplusplus extern "C" { #endif