From 63e489255f3dd5a66f17ca0cb2110e5aa409ca0d Mon Sep 17 00:00:00 2001 From: liuhan Date: Fri, 16 Apr 2021 17:23:18 +0800 Subject: [PATCH] transport: Add CONFI_WS_TRANSPORT for optimize the code size --- .../esp_websocket_client/CMakeLists.txt | 8 ++++++++ components/esp_websocket_client/component.mk | 4 ++++ components/mqtt/Kconfig | 1 + components/tcp_transport/CMakeLists.txt | 17 ++++++++++++----- components/tcp_transport/Kconfig | 19 ++++++++++++++----- components/tcp_transport/component.mk | 4 ++++ components/tcp_transport/transport_utils.c | 14 ++++++++++++++ components/tcp_transport/transport_ws.c | 14 ++++++++++++++ 8 files changed, 71 insertions(+), 10 deletions(-) diff --git a/components/esp_websocket_client/CMakeLists.txt b/components/esp_websocket_client/CMakeLists.txt index de17d6fdd4..af21d9d081 100644 --- a/components/esp_websocket_client/CMakeLists.txt +++ b/components/esp_websocket_client/CMakeLists.txt @@ -1,3 +1,11 @@ +if(NOT CONFIG_WS_TRANSPORT AND NOT CMAKE_BUILD_EARLY_EXPANSION) + message(STATUS "Websocket transport is disabled so the esp_websocket_client component will not be built") + # note: the component is still included in the build so it can become visible again in config + # without needing to re-run CMake. However no source or header files are built. + idf_component_register() + return() +endif() + idf_component_register(SRCS "esp_websocket_client.c" INCLUDE_DIRS "include" REQUIRES lwip esp-tls tcp_transport nghttp diff --git a/components/esp_websocket_client/component.mk b/components/esp_websocket_client/component.mk index e69de29bb2..300fea3da6 100644 --- a/components/esp_websocket_client/component.mk +++ b/components/esp_websocket_client/component.mk @@ -0,0 +1,4 @@ +ifdef CONFIG_WS_TRANSPORT +COMPONENT_SRCDIRS := . +COMPONENT_ADD_INCLUDEDIRS := include +endif diff --git a/components/mqtt/Kconfig b/components/mqtt/Kconfig index 3fc4ee6602..9a06e43ea2 100644 --- a/components/mqtt/Kconfig +++ b/components/mqtt/Kconfig @@ -15,6 +15,7 @@ menu "ESP-MQTT Configurations" config MQTT_TRANSPORT_WEBSOCKET bool "Enable MQTT over Websocket" default y + depends on WS_TRANSPORT help Enable MQTT transport over Websocket. diff --git a/components/tcp_transport/CMakeLists.txt b/components/tcp_transport/CMakeLists.txt index db4afb8752..8ec040e7b4 100644 --- a/components/tcp_transport/CMakeLists.txt +++ b/components/tcp_transport/CMakeLists.txt @@ -1,8 +1,15 @@ -idf_component_register(SRCS "transport.c" - "transport_ssl.c" - "transport_tcp.c" - "transport_ws.c" - "transport_utils.c" +set(srcs + "transport.c" + "transport_ssl.c" + "transport_tcp.c" + "transport_utils.c") + +if(CONFIG_WS_TRANSPORT) +list(APPEND srcs + "transport_ws.c") +endif() + +idf_component_register(SRCS "${srcs}" INCLUDE_DIRS "include" PRIV_INCLUDE_DIRS "private_include" REQUIRES lwip esp-tls) diff --git a/components/tcp_transport/Kconfig b/components/tcp_transport/Kconfig index a6e6df0093..1b8fc1006a 100644 --- a/components/tcp_transport/Kconfig +++ b/components/tcp_transport/Kconfig @@ -1,9 +1,18 @@ menu "TCP Transport" - config WS_BUFFER_SIZE - int "Websocket transport buffer size" - default 1024 - help - Size of the buffer used for constructing the HTTP Upgrade request during connect + menu "Websocket" + config WS_TRANSPORT + bool "Enable Websocket Transport" + default y + help + Enable support for creating websocket transport. + + config WS_BUFFER_SIZE + int "Websocket transport buffer size" + default 1024 + depends on WS_TRANSPORT + help + Size of the buffer used for constructing the HTTP Upgrade request during connect + endmenu endmenu diff --git a/components/tcp_transport/component.mk b/components/tcp_transport/component.mk index 064cc0608e..74d4e96cd6 100644 --- a/components/tcp_transport/component.mk +++ b/components/tcp_transport/component.mk @@ -1,2 +1,6 @@ COMPONENT_ADD_INCLUDEDIRS := include COMPONENT_PRIV_INCLUDEDIRS := private_include + +ifndef CONFIG_WS_TRANSPORT + COMPONENT_OBJEXCLUDE := transport_ws.o +endif diff --git a/components/tcp_transport/transport_utils.c b/components/tcp_transport/transport_utils.c index 1fa0e8a67f..5b538186c8 100644 --- a/components/tcp_transport/transport_utils.c +++ b/components/tcp_transport/transport_utils.c @@ -1,3 +1,17 @@ +// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD +// +// 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. + #include #include #include diff --git a/components/tcp_transport/transport_ws.c b/components/tcp_transport/transport_ws.c index fa0e9bd7bd..c1bfd6d8e7 100644 --- a/components/tcp_transport/transport_ws.c +++ b/components/tcp_transport/transport_ws.c @@ -1,3 +1,17 @@ +// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD +// +// 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. + #include #include #include