From e5d2c5860ee8341992249193ab7cf36e34d40181 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Wed, 28 Jan 2026 14:58:07 +0800 Subject: [PATCH] [gn] add cli_uart (#12345) This commit adds the `cli_uart` for applications to integrate OpenThread CLI based on UART APIs. One of the example is OTNS. --- examples/apps/cli/BUILD.gn | 35 ++++++++++++++++++++++++++++++++++ examples/apps/cli/cli_uart.cpp | 5 +++-- src/cli/BUILD.gn | 18 ++++++++++------- 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 examples/apps/cli/BUILD.gn diff --git a/examples/apps/cli/BUILD.gn b/examples/apps/cli/BUILD.gn new file mode 100644 index 000000000..ab08d0361 --- /dev/null +++ b/examples/apps/cli/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (c) 2026, 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. +# + +static_library("cli_uart") { + sources = [ "cli_uart.cpp" ] + include_dirs = [ "../../platforms" ] + deps = [ + "../../../src/cli:cli_config", + "../../../src/core:libopenthread_core_headers", + ] +} diff --git a/examples/apps/cli/cli_uart.cpp b/examples/apps/cli/cli_uart.cpp index c3ca42698..3ca7de8db 100644 --- a/examples/apps/cli/cli_uart.cpp +++ b/examples/apps/cli/cli_uart.cpp @@ -29,9 +29,7 @@ #include #include -#include -#include #include #include #include @@ -291,6 +289,9 @@ static int Output(const char *aBuf, uint16_t aBufLength) return sent; } +static int CliUartOutput(void *aContext, const char *aFormat, va_list aArguments) + OT_TOOL_PRINTF_STYLE_FORMAT_ARG_CHECK(2, 0); + static int CliUartOutput(void *aContext, const char *aFormat, va_list aArguments) { OT_UNUSED_VARIABLE(aContext); diff --git a/src/cli/BUILD.gn b/src/cli/BUILD.gn index ae41b3b60..deb978afc 100644 --- a/src/cli/BUILD.gn +++ b/src/cli/BUILD.gn @@ -42,7 +42,6 @@ openthread_cli_sources = [ "cli_coap_secure.hpp", "cli_commissioner.cpp", "cli_commissioner.hpp", - "cli_config.h", "cli_dataset.cpp", "cli_dataset.hpp", "cli_dns.cpp", @@ -76,20 +75,25 @@ openthread_cli_sources = [ "x509_cert_key.hpp", ] -config("cli_config") { - defines = [] +static_library("cli_config") { + public = [ "cli_config.h" ] + deps = [ "../../src/core:libopenthread_core_headers" ] } static_library("libopenthread-cli-ftd") { sources = openthread_cli_sources - public_deps = [ "../core:libopenthread-ftd" ] - public_configs = [":cli_config"] + public_deps = [ + ":cli_config", + "../core:libopenthread-ftd", + ] visibility = [ "../../*" ] } static_library("libopenthread-cli-mtd") { sources = openthread_cli_sources - public_deps = [ "../core:libopenthread-mtd" ] - public_configs = [":cli_config"] + public_deps = [ + ":cli_config", + "../core:libopenthread-mtd", + ] visibility = [ "../../*" ] }