diff --git a/BUILD.gn b/BUILD.gn index d372410bd4e2ee..8f5e14b7aab767 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -29,6 +29,7 @@ assert(chip_root == "//") import("${chip_root}/build/chip/tests.gni") import("${chip_root}/build/chip/tools.gni") +import("${chip_root}/src/lib/shell/shell.gni") import("//src/crypto/crypto.gni") @@ -101,7 +102,6 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { if (chip_build_tools) { deps += [ ":certification", - "${chip_root}/examples/shell/standalone:chip-shell", "${chip_root}/src/app/tests/integration:chip-im-initiator", "${chip_root}/src/app/tests/integration:chip-im-responder", "${chip_root}/src/messaging/tests/echo:chip-echo-requester", @@ -109,6 +109,9 @@ if (current_toolchain != "${dir_pw_toolchain}/dummy:dummy") { "${chip_root}/src/qrcodetool", "${chip_root}/src/setup_payload", ] + if (chip_shell) { + deps += [ "${chip_root}/examples/shell/standalone:chip-shell" ] + } if (chip_crypto == "openssl") { deps += [ "${chip_root}/src/tools/chip-cert" ] } diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index 5baf5efaac454e..5bf07fe6386898 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -72,7 +72,7 @@ if (NOT CONFIG_USE_MINIMAL_MDNS) endif() if (CONFIG_ENABLE_CHIP_SHELL) - chip_gn_arg_append("chip_build_libshell" "true") + chip_gn_arg_append("chip_shell" "true") endif() diff --git a/config/esp32/components/chip/component.mk b/config/esp32/components/chip/component.mk index bf7cbee1f79dd6..fe0bff05381bc5 100644 --- a/config/esp32/components/chip/component.mk +++ b/config/esp32/components/chip/component.mk @@ -140,7 +140,7 @@ endif echo "dir_pw_third_party_nanopb = \"//third_party/connectedhomeip/third_party/nanopb/repo\"" >>$(OUTPUT_DIR)/args.gn ;\ fi if [[ "$(CONFIG_ENABLE_CHIP_SHELL)" = "y" ]]; then \ - echo "chip_build_libshell = true" >> $(OUTPUT_DIR)/args.gn ;\ + echo "chip_shell = true" >> $(OUTPUT_DIR)/args.gn ;\ fi if [[ "$(CONFIG_USE_MINIMAL_MDNS)" = "n" ]]; then \ echo "chip_mdns = platform" >> $(OUTPUT_DIR)/args.gn ;\ diff --git a/config/nrfconnect/chip-module/CMakeLists.txt b/config/nrfconnect/chip-module/CMakeLists.txt index 91c5ad83c29bd9..568a535a92ec6e 100644 --- a/config/nrfconnect/chip-module/CMakeLists.txt +++ b/config/nrfconnect/chip-module/CMakeLists.txt @@ -205,7 +205,7 @@ chip_gn_arg_bool ("chip_monolithic_tests" CONFIG_CHIP_BUILD_TE chip_gn_arg_bool ("chip_inet_config_enable_raw_endpoint" CONFIG_CHIP_BUILD_TESTS) chip_gn_arg_bool ("chip_inet_config_enable_tcp_endpoint" CONFIG_CHIP_BUILD_TESTS) chip_gn_arg_bool ("chip_inet_config_enable_dns_resolver" CONFIG_CHIP_BUILD_TESTS) -chip_gn_arg_bool ("chip_build_libshell" CONFIG_CHIP_STANDALONE_SHELL) +chip_gn_arg_bool ("chip_shell" CONFIG_CHIP_STANDALONE_SHELL) chip_gn_arg_bool ("chip_build_zephyr_shell" CONFIG_CHIP_ZEPHYR_SHELL) chip_gn_arg_bool ("chip_build_pw_rpc_lib" CONFIG_CHIP_PW_RPC) diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index 59ab87db15c1cf..d0951fcf8636d9 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -35,13 +34,19 @@ #include #endif +#if CHIP_SHELL_ENABLED +#include +#endif + #include "Options.h" using namespace chip; using namespace chip::Inet; using namespace chip::Transport; using namespace chip::DeviceLayer; +#if CHIP_SHELL_ENABLED using chip::Shell::Engine; +#endif namespace { void EventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) @@ -112,11 +117,15 @@ int ChipLinuxAppInit(int argc, char ** argv) void ChipLinuxAppMainLoop() { +#if CHIP_SHELL_ENABLED std::thread shellThread([]() { Engine::Root().RunMainLoop(); }); +#endif // Init ZCL Data Model and CHIP App Server InitServer(); chip::DeviceLayer::PlatformMgr().RunEventLoop(); +#if CHIP_SHELL_ENABLED shellThread.join(); +#endif } diff --git a/examples/platform/linux/BUILD.gn b/examples/platform/linux/BUILD.gn index 89157f9f945ef6..3d5f0905c664e9 100644 --- a/examples/platform/linux/BUILD.gn +++ b/examples/platform/linux/BUILD.gn @@ -14,6 +14,7 @@ import("//build_overrides/chip.gni") import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") +import("${chip_root}/src/lib/shell/shell.gni") config("app-main-config") { include_dirs = [ "." ] @@ -36,12 +37,13 @@ source_set("app-main") { public_deps = [ "${chip_root}/src/app/server", "${chip_root}/src/lib", - "${chip_root}/src/lib/shell", - "${chip_root}/src/lib/shell:shell_core", ] - public_deps += [ - ] + if (chip_shell) { + public_deps += [ "${chip_root}/src/lib/shell" ] + + defines += [ "CHIP_SHELL_ENABLED=1" ] + } public_configs = [ ":app-main-config" ] } diff --git a/examples/shell/standalone/args.gni b/examples/shell/standalone/args.gni index 311ddab32d5fe5..d5c12348a7f754 100644 --- a/examples/shell/standalone/args.gni +++ b/examples/shell/standalone/args.gni @@ -15,3 +15,5 @@ import("//build_overrides/chip.gni") import("${chip_root}/config/standalone/args.gni") + +chip_shell=true diff --git a/src/BUILD.gn b/src/BUILD.gn index dbac7c57707fb7..d653d5e35ce127 100644 --- a/src/BUILD.gn +++ b/src/BUILD.gn @@ -17,6 +17,7 @@ import("//build_overrides/chip.gni") import("${chip_root}/build/chip/tests.gni") import("${chip_root}/src/ble/ble.gni") +import("${chip_root}/src/lib/shell/shell.gni") import("${chip_root}/src/lwip/lwip.gni") import("${chip_root}/src/platform/device.gni") @@ -83,7 +84,7 @@ if (chip_build_tests) { deps += [ "${chip_root}/src/lwip/tests" ] } - if (current_os != "zephyr" && chip_device_platform != "esp32") { + if (chip_shell) { deps += [ "${chip_root}/src/lib/shell/tests" ] } diff --git a/src/lib/BUILD.gn b/src/lib/BUILD.gn index b63e040d2bac76..8691f88cca7fa0 100644 --- a/src/lib/BUILD.gn +++ b/src/lib/BUILD.gn @@ -14,9 +14,7 @@ import("//build_overrides/chip.gni") -declare_args() { - chip_build_libshell = false -} +import("${chip_root}/src/lib/shell/shell.gni") config("includes") { include_dirs = [ "." ] @@ -40,7 +38,7 @@ static_library("lib") { "${chip_root}/src/transport", ] - if (chip_build_libshell) { + if (chip_shell) { public_deps += [ "${chip_root}/src/lib/shell" ] } diff --git a/src/lib/shell/BUILD.gn b/src/lib/shell/BUILD.gn index d4d765c1675998..4ea89aebb39707 100644 --- a/src/lib/shell/BUILD.gn +++ b/src/lib/shell/BUILD.gn @@ -15,51 +15,57 @@ import("//build_overrides/chip.gni") import("${chip_root}/src/lib/core/core.gni") +import("${chip_root}/src/lib/shell/shell.gni") import("${chip_root}/src/platform/device.gni") -source_set("shell_core") { - sources = [ - "Commands.h", - "Engine.cpp", - "Engine.h", - "streamer.cpp", - "streamer.h", - ] +if (chip_shell) { + source_set("shell_core") { + sources = [ + "Commands.h", + "Engine.cpp", + "Engine.h", + "streamer.cpp", + "streamer.h", + ] - public_deps = [ - "${chip_root}/src/lib/core", - "${chip_root}/src/lib/support", - "${chip_root}/src/platform", - ] -} + public_deps = [ + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/support", + "${chip_root}/src/platform", + ] + } -static_library("shell") { - output_name = "libCHIPShell" - output_dir = "${root_out_dir}/lib" + static_library("shell") { + output_name = "libCHIPShell" + output_dir = "${root_out_dir}/lib" - sources = [] + sources = [] - if (chip_target_style == "unix") { - sources += [ "streamer_stdio.cpp" ] - } + if (chip_target_style == "unix") { + sources += [ "streamer_stdio.cpp" ] + } - if (chip_device_platform == "esp32") { - sources += [ - "MainLoopESP32.cpp", - "streamer_esp32.cpp", - ] - } else { - sources += [ "MainLoopDefault.cpp" ] - } + if (chip_device_platform == "esp32") { + sources += [ + "MainLoopESP32.cpp", + "streamer_esp32.cpp", + ] + } else { + sources += [ "MainLoopDefault.cpp" ] + } - if (current_os == "zephyr") { - sources += [ "streamer_zephyr.cpp" ] - } + if (current_os == "zephyr") { + sources += [ "streamer_zephyr.cpp" ] + } - cflags = [ "-Wconversion" ] + cflags = [ "-Wconversion" ] - public_deps = [ - ":shell_core", - "${chip_root}/src/lib/shell/commands", - ] + public_deps = [ + ":shell_core", + "${chip_root}/src/lib/shell/commands", + ] + } +} else { + group("shell") { + } } diff --git a/src/lib/shell/shell.gni b/src/lib/shell/shell.gni new file mode 100644 index 00000000000000..79429b96c43422 --- /dev/null +++ b/src/lib/shell/shell.gni @@ -0,0 +1,18 @@ +# Copyright (c) 2021 Project CHIP Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +declare_args() { + # Enable shell. + chip_shell = false +} diff --git a/src/lib/shell/tests/BUILD.gn b/src/lib/shell/tests/BUILD.gn index 6180de017c3312..48e8b869d23934 100644 --- a/src/lib/shell/tests/BUILD.gn +++ b/src/lib/shell/tests/BUILD.gn @@ -17,22 +17,25 @@ import("//build_overrides/chip.gni") import("//build_overrides/nlunit_test.gni") import("${chip_root}/build/chip/chip_test_suite.gni") +import("${chip_root}/src/lib/shell/shell.gni") -chip_test_suite("tests") { - output_name = "libTestShell" +if (chip_shell) { + chip_test_suite("tests") { + output_name = "libTestShell" - sources = [ - "TestStreamerStdio.cpp", - "TestStreamerStdio.h", - ] + sources = [ + "TestStreamerStdio.cpp", + "TestStreamerStdio.h", + ] - cflags = [ "-Wconversion" ] + cflags = [ "-Wconversion" ] - public_deps = [ - "${chip_root}/src/lib/core", - "${chip_root}/src/lib/shell", - "${nlunit_test_root}:nlunit-test", - ] + public_deps = [ + "${chip_root}/src/lib/core", + "${chip_root}/src/lib/shell", + "${nlunit_test_root}:nlunit-test", + ] - tests = [ "TestStreamerStdio" ] + tests = [ "TestStreamerStdio" ] + } }