Skip to content

Commit

Permalink
[shell] make shell really optional in Linux
Browse files Browse the repository at this point in the history
Fix the TODO in
#7205
  • Loading branch information
gjc13 committed May 28, 2021
1 parent 34bccf5 commit e91f434
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 64 deletions.
5 changes: 4 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -101,14 +102,16 @@ 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",
"${chip_root}/src/messaging/tests/echo:chip-echo-responder",
"${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" ]
}
Expand Down
2 changes: 1 addition & 1 deletion config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
2 changes: 1 addition & 1 deletion config/esp32/components/chip/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;\
Expand Down
2 changes: 1 addition & 1 deletion config/nrfconnect/chip-module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 10 additions & 1 deletion examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <core/CHIPError.h>
#include <lib/shell/Engine.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>
#include <support/CHIPMem.h>
Expand All @@ -35,13 +34,19 @@
#include <CommonRpc.h>
#endif

#if CHIP_SHELL_ENABLED
#include <lib/shell/Engine.h>
#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)
Expand Down Expand Up @@ -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
}
10 changes: 6 additions & 4 deletions examples/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [ "." ]
Expand All @@ -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" ]
}
2 changes: 2 additions & 0 deletions examples/shell/standalone/args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
import("//build_overrides/chip.gni")

import("${chip_root}/config/standalone/args.gni")

chip_shell=true
3 changes: 2 additions & 1 deletion src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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" ]
}

Expand Down
6 changes: 2 additions & 4 deletions src/lib/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [ "." ]
Expand All @@ -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" ]
}

Expand Down
80 changes: 43 additions & 37 deletions src/lib/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
}
}
18 changes: 18 additions & 0 deletions src/lib/shell/shell.gni
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 16 additions & 13 deletions src/lib/shell/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
}

0 comments on commit e91f434

Please sign in to comment.