Merge branch 'fix/add_libbsd_string_h' into 'master'

refactor(linux): Unified libbsd handling

See merge request espressif/esp-idf!29457
pull/13473/head
Jakob Hasse 2024-03-21 10:11:25 +08:00
commit f482a9153a
20 zmienionych plików z 61 dodań i 83 usunięć

Wyświetl plik

@ -35,13 +35,3 @@ idf_component_register(SRCS ${srcs}
PRIV_REQUIRES esp_driver_uart
esp_driver_usb_serial_jtag
)
if(${target} STREQUAL "linux")
# link bsd library for strlcpy
find_library(LIB_BSD bsd)
if(LIB_BSD)
target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD})
elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.")
endif()
endif()

Wyświetl plik

@ -6,10 +6,6 @@
#include <stdio.h>
#include <string.h>
#if __has_include(<bsd/string.h>)
// for strlcpy
#include <bsd/string.h>
#endif
#include <stdlib.h>
#include <sys/param.h>
#include "esp_heap_caps.h"

Wyświetl plik

@ -1,17 +1,15 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sdkconfig.h"
#include <sys/cdefs.h> // __containerof
#include "esp_console.h"
#include "console_private.h"
#include "esp_log.h"
#include "linenoise/linenoise.h"
#if CONFIG_IDF_TARGET_LINUX
#include "esp_linux_helper.h" // __containerof
#endif
static const char *TAG = "console.common";

Wyświetl plik

@ -12,10 +12,10 @@
#include <termios.h>
#include <string.h>
#include <assert.h>
#include <sys/cdefs.h>
#include "sdkconfig.h"
#include "esp_log.h"
#include "esp_linux_helper.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

Wyświetl plik

@ -1,16 +1,13 @@
/*
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <sys/cdefs.h>
#include "esp_tls.h"
#include "esp_tls_error_capture_internal.h"
#if CONFIG_IDF_TARGET_LINUX
#include "esp_linux_helper.h"
#endif
typedef struct esp_tls_error_storage {
struct esp_tls_last_error parent; /*!< standard esp-tls last error container */
int sock_errno; /*!< last socket error captured in esp-tls */

Wyświetl plik

@ -43,12 +43,3 @@ foreach(req ${optional_reqs})
target_link_libraries(${COMPONENT_LIB} PRIVATE ${req_lib})
endif()
endforeach()
if(${IDF_TARGET} STREQUAL "linux" AND CONFIG_ESP_ERR_TO_NAME_LOOKUP)
find_library(LIB_BSD bsd)
if(LIB_BSD)
target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD})
elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.")
endif()
endif()

Wyświetl plik

@ -7,10 +7,6 @@
//Do not edit this file because it is autogenerated by gen_esp_err_to_name.py
#include <string.h>
#if __has_include(<bsd/string.h>)
// for strlcpy
#include <bsd/string.h>
#endif
#include "esp_err.h"
#if __has_include("soc/soc.h")
#include "soc/soc.h"

Wyświetl plik

@ -7,10 +7,6 @@
@COMMENT@
#include <string.h>
#if __has_include(<bsd/string.h>)
// for strlcpy
#include <bsd/string.h>
#endif
#include "esp_err.h"
#if __has_include("soc/soc.h")
#include "soc/soc.h"

Wyświetl plik

@ -20,12 +20,3 @@ idf_component_register(SRCS "src/httpd_main.c"
PRIV_INCLUDE_DIRS ${priv_inc_dir}
REQUIRES ${requires}
PRIV_REQUIRES ${priv_req})
if(${IDF_TARGET} STREQUAL "linux")
find_library(LIB_BSD bsd)
if(LIB_BSD)
target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD})
elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.")
endif()
endif()

Wyświetl plik

@ -7,10 +7,6 @@
#include <stdlib.h>
#include <string.h>
#if __has_include(<bsd/string.h>)
// for strlcpy
#include <bsd/string.h>
#endif
#include <sys/param.h>
#include <esp_log.h>
#include <esp_err.h>

Wyświetl plik

@ -26,14 +26,6 @@ idf_component_register(SRCS "${srcs}"
if(${target} STREQUAL "linux")
# set BUILD_DIR because partition_linux.c uses a file created in the build directory
target_compile_definitions(${COMPONENT_LIB} PRIVATE "BUILD_DIR=\"${build_dir}\"")
# link bsd library for strlcpy
find_library(LIB_BSD bsd)
if(LIB_BSD)
target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD})
elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.")
endif()
endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU")

Wyświetl plik

@ -7,9 +7,6 @@
*/
#include <string.h>
#if __has_include(<bsd/string.h>)
#include <bsd/string.h>
#endif
#include <unistd.h>
#include <sys/time.h>
#include "esp_err.h"

Wyświetl plik

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -14,7 +14,7 @@
* should go back to #include "sys/queue.h" once the tests are switched to CMake
* see IDF-7000
*/
#if __has_include(<bsd/string.h>)
#if __has_include(<bsd/sys/queue.h>)
#include <bsd/sys/queue.h>
#else
#include "sys/queue.h"
@ -33,9 +33,6 @@
#include "bootloader_util.h"
#if CONFIG_IDF_TARGET_LINUX
#if __has_include(<bsd/string.h>)
#include <bsd/string.h>
#endif
#include "esp_private/partition_linux.h"
#endif

Wyświetl plik

@ -8,10 +8,6 @@
#include <assert.h>
#include <string.h>
#include <inttypes.h>
#if __has_include(<bsd/string.h>)
// for strlcpy
#include <bsd/string.h>
#endif
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>

Wyświetl plik

@ -14,3 +14,12 @@ endif()
idf_component_register(INCLUDE_DIRS ${includes}
REQUIRED_IDF_TARGETS linux
SRCS ${srcs})
if(${IDF_TARGET} STREQUAL "linux")
find_library(LIB_BSD bsd)
if(LIB_BSD)
target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD})
elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.")
endif()
endif()

Wyświetl plik

@ -1,10 +1,16 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
/*
* NOTE: This file is deprecated and will be removed in the future.
* Use include sys/cdefs.h instead, it will also include
* the corresponding libbsd header. TODO: IDF-9391
*/
#ifdef __cplusplus
extern "C" {
#endif

Wyświetl plik

@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* This header file also includes the additional libbsd string.h with functions such as strlcpy(),
* which are present in the ESP-IDF toolchain and on MacOS, but not on Linux.
*/
#pragma once
#include <bsd/string.h>
#include_next <string.h>

Wyświetl plik

@ -0,0 +1,22 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* This header file adds the libbsd defines of header cdefs.h.
* It also defines __uintptr_t which is still used by older libbsd versions (< 0.11.3)
* but not (or not guaranteed to be) defined on Linux.
*/
#pragma once
#include <stdint.h>
// We need a define. We can't typedef here since, depending on the include order,
// uintptr_t may not be defined yet.
#define __uintptr_t uintptr_t
#include_next <sys/cdefs.h>
#include <bsd/sys/cdefs.h>

Wyświetl plik

@ -25,7 +25,7 @@
#define LWIP_TIMEVAL_PRIVATE 0
#include <sys/time.h>
#include "esp_linux_helper.h"
#include <sys/cdefs.h>
#define LWIP_ERRNO_INCLUDE <errno.h>

Wyświetl plik

@ -30,13 +30,6 @@ if(${target} STREQUAL "linux")
target_compile_options(${COMPONENT_LIB} PUBLIC "-DLINUX_TARGET")
target_compile_options(${COMPONENT_LIB} PUBLIC --coverage)
target_link_libraries(${COMPONENT_LIB} PUBLIC --coverage)
find_library(LIB_BSD bsd)
if(LIB_BSD)
target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD})
elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.")
endif()
else()
target_sources(${COMPONENT_LIB} PRIVATE "src/nvs_encrypted_partition.cpp")
target_link_libraries(${COMPONENT_LIB} PRIVATE idf::mbedtls)