mirror of
https://github.com/espressif/esp-mqtt.git
synced 2026-10-20 06:28:12 +00:00
refactor: Split message library into subcomponent
Signed-off-by: Euripedes Rocha Filho <[email protected]>
This commit is contained in:
@@ -38,8 +38,8 @@ examples_and_unit_tests:
|
||||
|
||||
third_party_libs:
|
||||
include:
|
||||
- "lib/mqtt_msg.c"
|
||||
- "lib/include/mqtt_msg.h"
|
||||
- "lib/mqtt_msg/mqtt_msg.c"
|
||||
- "lib/mqtt_msg/include/mqtt_msg.h"
|
||||
- "test/host/mocks/include/sys/queue.h"
|
||||
allowed_licenses:
|
||||
- BSD-3-Clause
|
||||
|
||||
+2
-2
@@ -128,8 +128,8 @@ mqtt_conformance_coverage_report{{ settings.gitlab.test_pipeline.job_name_suffix
|
||||
gcovr_filters=(
|
||||
--filter="${CI_PROJECT_DIR}/mqtt_client.c"
|
||||
--filter="${CI_PROJECT_DIR}/mqtt5_client.c"
|
||||
--filter="${CI_PROJECT_DIR}/lib/mqtt_msg.c"
|
||||
--filter="${CI_PROJECT_DIR}/lib/mqtt5_msg.c"
|
||||
--filter="${CI_PROJECT_DIR}/lib/mqtt_msg/mqtt_msg.c"
|
||||
--filter="${CI_PROJECT_DIR}/lib/mqtt_msg/mqtt5_msg.c"
|
||||
--filter="${CI_PROJECT_DIR}/lib/platform.c"
|
||||
)
|
||||
shopt -s nullglob
|
||||
|
||||
+6
-3
@@ -1,12 +1,12 @@
|
||||
set(srcs mqtt_client.c lib/mqtt_msg.c lib/platform.c)
|
||||
set(srcs mqtt_client.c lib/platform.c)
|
||||
|
||||
if(CONFIG_MQTT_PROTOCOL_5)
|
||||
list(APPEND srcs lib/mqtt5_msg.c mqtt5_client.c)
|
||||
list(APPEND srcs mqtt5_client.c)
|
||||
endif()
|
||||
|
||||
list(TRANSFORM srcs PREPEND ${CMAKE_CURRENT_LIST_DIR}/)
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include
|
||||
INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/include ${CMAKE_CURRENT_LIST_DIR}/lib/mqtt_msg/include
|
||||
PRIV_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/lib/include
|
||||
REQUIRES esp_event tcp_transport
|
||||
PRIV_REQUIRES esp_timer http_parser esp_hw_support heap
|
||||
@@ -16,5 +16,8 @@ idf_component_register(SRCS "${srcs}"
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/mqtt_utils)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC idf::mqtt::utils)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/mqtt_msg)
|
||||
target_link_libraries(${COMPONENT_LIB} PRIVATE idf::mqtt::msg)
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/lib/mqtt_outbox)
|
||||
target_link_libraries(${COMPONENT_LIB} PRIVATE idf::mqtt::outbox)
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
set(srcs "${CMAKE_CURRENT_LIST_DIR}/mqtt_msg.c")
|
||||
|
||||
if(CONFIG_MQTT_PROTOCOL_5)
|
||||
list(APPEND srcs "${CMAKE_CURRENT_LIST_DIR}/mqtt5_msg.c")
|
||||
endif()
|
||||
|
||||
add_library(mqtt_msg_lib ${srcs})
|
||||
target_include_directories(mqtt_msg_lib
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/include
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../include
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../include)
|
||||
|
||||
idf_component_get_property(heap heap COMPONENT_LIB)
|
||||
idf_component_get_property(log log COMPONENT_LIB)
|
||||
target_link_libraries(mqtt_msg_lib PRIVATE ${heap} ${log})
|
||||
|
||||
add_library(idf::mqtt::msg ALIAS mqtt_msg_lib)
|
||||
@@ -331,6 +331,9 @@ static mqtt5_user_property_handle_t mqtt5_msg_parse_user_property(uint8_t *buffe
|
||||
/* False positive: user_porperty is released at err or returned to the caller.
|
||||
* The analyzer cannot track its cleanup across the translation-unit boundary. */
|
||||
#pragma GCC diagnostic push
|
||||
#ifdef __clang__
|
||||
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
|
||||
#endif
|
||||
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
|
||||
|
||||
if (mqtt5_msg_set_user_property(&user_property, (char *)key, key_len, (char *)value, value_len) != ESP_OK) {
|
||||
@@ -6,5 +6,7 @@ target_include_directories(mqtt_outbox_lib PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../include)
|
||||
idf_component_get_property(heap heap COMPONENT_LIB)
|
||||
idf_component_get_property(log log COMPONENT_LIB)
|
||||
target_link_libraries(mqtt_outbox_lib PRIVATE ${heap} ${log})
|
||||
target_link_libraries(mqtt_outbox_lib
|
||||
PUBLIC idf::mqtt::msg
|
||||
PRIVATE ${heap} ${log})
|
||||
add_library(idf::mqtt::outbox ALIAS mqtt_outbox_lib)
|
||||
|
||||
@@ -796,6 +796,9 @@ esp_err_t esp_mqtt5_client_set_connect_property(esp_mqtt5_client_handle_t client
|
||||
* esp_mqtt_destroy_config() calls esp_mqtt5_client_destory(), which frees this allocation.
|
||||
* The cleanup crosses a translation-unit boundary that analyzer does not follow. */
|
||||
#pragma GCC diagnostic push
|
||||
#ifdef __clang__
|
||||
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
|
||||
#endif
|
||||
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
|
||||
client->mqtt5_config->will_property_info.correlation_data = malloc(connect_property->correlation_data_len);
|
||||
ESP_MEM_CHECK(TAG, client->mqtt5_config->will_property_info.correlation_data, goto _mqtt_set_config_failed);
|
||||
|
||||
@@ -301,6 +301,9 @@ bool esp_mqtt_set_if_config(char const *const new_config, char **old_config)
|
||||
* (e.g. client->config->uri). On the failure path esp_mqtt_destroy_config frees it,
|
||||
* but the analyzer cannot follow that cross-TU cleanup chain. */
|
||||
#pragma GCC diagnostic push
|
||||
#ifdef __clang__
|
||||
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
|
||||
#endif
|
||||
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
|
||||
*old_config = strdup(new_config);
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ if(CONFIG_ESP_GCOV_ENABLE AND COMMAND idf_create_coverage_report)
|
||||
GCOV_OPTIONS
|
||||
"--filter=${mqtt_root}/mqtt_client.c"
|
||||
"--filter=${mqtt_root}/mqtt5_client.c"
|
||||
"--filter=${mqtt_root}/lib/mqtt_msg.c"
|
||||
"--filter=${mqtt_root}/lib/mqtt5_msg.c"
|
||||
"--filter=${mqtt_root}/lib/mqtt_msg/mqtt_msg.c"
|
||||
"--filter=${mqtt_root}/lib/mqtt_msg/mqtt5_msg.c"
|
||||
"--filter=${mqtt_root}/lib/platform.c"
|
||||
"--xml=${CMAKE_CURRENT_BINARY_DIR}/coverage_report/coverage.xml")
|
||||
idf_clean_coverage_report(${CMAKE_CURRENT_BINARY_DIR}/coverage_report)
|
||||
|
||||
@@ -7,22 +7,16 @@ set(SANITIZER_FLAGS -fsanitize=address,undefined -fno-sanitize-recover=undefined
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE ${SANITIZER_FLAGS} -Wno-missing-field-initializers)
|
||||
target_link_options(${COMPONENT_LIB} INTERFACE ${SANITIZER_FLAGS})
|
||||
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../lib/mqtt_msg
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mqtt_msg)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../../../lib/mqtt_outbox
|
||||
${CMAKE_CURRENT_BINARY_DIR}/mqtt_outbox)
|
||||
|
||||
# mqtt_outbox.c now owns mqtt_message_t and calls mqtt_msg_destroy().
|
||||
add_library(mqtt_msg_lib "${CMAKE_CURRENT_LIST_DIR}/../../../lib/mqtt_msg.c")
|
||||
target_include_directories(mqtt_msg_lib PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../lib/include
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../include)
|
||||
idf_component_get_property(heap heap COMPONENT_LIB)
|
||||
idf_component_get_property(log log COMPONENT_LIB)
|
||||
target_link_libraries(mqtt_msg_lib PRIVATE ${heap} ${log})
|
||||
target_compile_options(mqtt_msg_lib PRIVATE ${SANITIZER_FLAGS})
|
||||
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC
|
||||
idf::mqtt::outbox
|
||||
mqtt_msg_lib
|
||||
idf::mqtt::msg
|
||||
Catch2::Catch2WithMain
|
||||
rapidcheck
|
||||
rapidcheck_catch)
|
||||
|
||||
Reference in New Issue
Block a user