From 342a5b428c2be3a59b38ea409bfdff07e995ffe4 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Mon, 7 Aug 2023 16:15:28 +0800 Subject: [PATCH 1/3] fix(esp_event): made #include explicit --- components/esp_event/include/esp_event_base.h | 7 +++---- tools/ci/check_public_headers_exceptions.txt | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/components/esp_event/include/esp_event_base.h b/components/esp_event/include/esp_event_base.h index 0da0a99159..6eb3f31e94 100644 --- a/components/esp_event/include/esp_event_base.h +++ b/components/esp_event/include/esp_event_base.h @@ -4,8 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef ESP_EVENT_BASE_H_ -#define ESP_EVENT_BASE_H_ +#pragma once + +#include #ifdef __cplusplus extern "C" { @@ -31,5 +32,3 @@ typedef void* esp_event_handler_instance_t; /**< context identifying an i #ifdef __cplusplus } #endif - -#endif // #ifndef ESP_EVENT_BASE_H_ diff --git a/tools/ci/check_public_headers_exceptions.txt b/tools/ci/check_public_headers_exceptions.txt index b18d7b8849..977da40289 100644 --- a/tools/ci/check_public_headers_exceptions.txt +++ b/tools/ci/check_public_headers_exceptions.txt @@ -114,7 +114,7 @@ components/esp_wifi/include/esp_wifi_crypto_types.h components/esp_wifi/include/esp_wifi_netif.h components/esp_wifi/include/smartconfig_ack.h components/esp_wifi/include/esp_wifi_default.h -components/esp_event/include/esp_event_base.h +components/esp_netif/include/esp_netif_sta_list.h components/esp_netif/include/esp_netif_defaults.h components/esp_netif/include/esp_netif_net_stack.h components/esp_netif/include/esp_netif_ppp.h From 44e4ef79e28e3757df27d7e87570bb04c2a5aa34 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Wed, 9 Aug 2023 14:11:22 +0800 Subject: [PATCH 2/3] fix(esp_system): Fixed C++ compilation of libunwind.h --- components/esp_system/include/libunwind.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/esp_system/include/libunwind.h b/components/esp_system/include/libunwind.h index a91de95965..09c4d6247d 100644 --- a/components/esp_system/include/libunwind.h +++ b/components/esp_system/include/libunwind.h @@ -4,8 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef LIBUNWIND_H -#define LIBUNWIND_H +#pragma once #include "sdkconfig.h" #include @@ -132,4 +131,6 @@ int unw_get_reg(unw_cursor_t* cp, unw_regnum_t reg, unw_word_t* valp); */ int unw_set_reg(unw_cursor_t* cp, unw_regnum_t reg, unw_word_t val); -#endif // LIBUNWIND_H +#ifdef __cplusplus +} +#endif From 8b9f8555ea06394bf3d745d0a4a9d3718d0ae907 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Wed, 9 Aug 2023 14:12:21 +0800 Subject: [PATCH 3/3] refactor(tools): public header check also checks c++ now * Also changed --only-dir argument to accept system-wide directories instead of directories from IDF root --- tools/ci/check_public_headers.py | 23 ++- tools/ci/check_public_headers_exceptions.txt | 133 +++++++++++++++++- .../test_apps/system/cxx_build_test/README.md | 6 +- .../system/cxx_build_test/main/CMakeLists.txt | 3 - .../main/test_esp_hw_support.cpp | 41 ------ 5 files changed, 153 insertions(+), 53 deletions(-) delete mode 100644 tools/test_apps/system/cxx_build_test/main/test_esp_hw_support.cpp diff --git a/tools/ci/check_public_headers.py b/tools/ci/check_public_headers.py index c3d8bb4406..a68622c96f 100644 --- a/tools/ci/check_public_headers.py +++ b/tools/ci/check_public_headers.py @@ -32,8 +32,16 @@ class HeaderFailedSdkconfig(HeaderFailed): class HeaderFailedBuildError(HeaderFailed): + def __init__(self, compiler: str): + self.compiler = compiler + def __str__(self) -> str: - return 'Header Build Error' + return 'Header Build Error with {}'.format(self.compiler) + + +class HeaderFailedPreprocessError(HeaderFailed): + def __str__(self) -> str: + return 'Header Procecessing Error' class HeaderFailedCppGuardMissing(HeaderFailed): @@ -164,7 +172,7 @@ class PublicHeaderChecker: elif res == self.COMPILE_ERR_ERROR_MACRO_HDR_OK: return self.compile_one_header(header) elif res == self.COMPILE_ERR_HDR_FAILED: - raise HeaderFailedBuildError() + raise HeaderFailedPreprocessError() elif res == self.PREPROC_OUT_ZERO_HDR_OK: return self.compile_one_header(header) elif res == self.PREPROC_OUT_SAME_HRD_FAILED: @@ -186,7 +194,11 @@ class PublicHeaderChecker: os.unlink(temp_header) def compile_one_header(self, header: str) -> None: - rc, out, err, cmd = exec_cmd([self.gcc, '-S', '-o-', '-include', header, self.main_c] + self.include_dir_flags) + self.compile_one_header_with(self.gcc, header) + self.compile_one_header_with(self.gpp, header) + + def compile_one_header_with(self, compiler: str, header: str) -> None: + rc, out, err, cmd = exec_cmd([compiler, '-S', '-o-', '-include', header, self.main_c] + self.include_dir_flags) if rc == 0: if not re.sub(self.assembly_nocode, '', out, flags=re.M).isspace(): raise HeaderFailedContainsCode() @@ -194,7 +206,7 @@ class PublicHeaderChecker: self.log('{}: FAILED: compilation issue'.format(header), True) self.log(err, True) self.log('\nCompilation command failed:\n{}\n'.format(cmd), True) - raise HeaderFailedBuildError() + raise HeaderFailedBuildError(compiler) def preprocess_one_header(self, header: str, num: int, ignore_common_issues: bool=False) -> int: all_compilation_flags = ['-w', '-P', '-E', '-DESP_PLATFORM', '-include', header, self.main_c] + self.include_dir_flags @@ -292,7 +304,7 @@ class PublicHeaderChecker: all_include_files = [] files_to_check = [] for d in include_dirs: - if only_dir is not None and not os.path.relpath(d, idf_path).startswith(only_dir): + if only_dir is not None and not os.path.relpath(d, idf_path).startswith(os.path.relpath(only_dir, idf_path)): self.log('{} - directory ignored (not in "{}")'.format(d, only_dir)) continue if os.path.relpath(d, idf_path).startswith(tuple(ignore_dirs)): @@ -331,6 +343,7 @@ def check_all_headers() -> None: * Check that all referenced macros, types are available (defined or included) * Check that all included header files are available (included in paths) * Check for possible compilation issues + * If only the C++ compilation fails, check that the header is C++ compatible * Try to compile only the offending header file 3) "Header Missing C++ Guard": Preprocessing the header by C and C++ should produce different output * Check if the "#ifdef __cplusplus" header sentinels are present diff --git a/tools/ci/check_public_headers_exceptions.txt b/tools/ci/check_public_headers_exceptions.txt index 977da40289..40b753dbfd 100644 --- a/tools/ci/check_public_headers_exceptions.txt +++ b/tools/ci/check_public_headers_exceptions.txt @@ -114,7 +114,6 @@ components/esp_wifi/include/esp_wifi_crypto_types.h components/esp_wifi/include/esp_wifi_netif.h components/esp_wifi/include/smartconfig_ack.h components/esp_wifi/include/esp_wifi_default.h -components/esp_netif/include/esp_netif_sta_list.h components/esp_netif/include/esp_netif_defaults.h components/esp_netif/include/esp_netif_net_stack.h components/esp_netif/include/esp_netif_ppp.h @@ -126,6 +125,138 @@ components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h components/usb/include/esp_private/usb_phy.h components/usb/include/usb/usb_types_stack.h +### Headers that don't compile with C++ +# +components/bootloader_support/bootloader_flash/include/bootloader_flash.h +components/bootloader_support/bootloader_flash/include/bootloader_flash_priv.h +components/esp_hw_support/include/esp_private/regdma_link.h +components/hal/esp32/include/hal/aes_ll.h +components/hal/esp32/include/hal/cache_ll.h +components/hal/esp32/include/hal/i2c_ll.h +components/hal/esp32/include/hal/ledc_ll.h +components/hal/esp32/include/hal/mcpwm_ll.h +components/hal/esp32/include/hal/mpi_ll.h +components/hal/esp32/include/hal/pcnt_ll.h +components/hal/esp32/include/hal/sdio_slave_ll.h +components/hal/esp32/include/hal/spi_flash_ll.h +components/hal/esp32c2/include/hal/adc_ll.h +components/hal/esp32c2/include/hal/cache_ll.h +components/hal/esp32c2/include/hal/ecc_ll.h +components/hal/esp32c2/include/hal/gpspi_flash_ll.h +components/hal/esp32c2/include/hal/i2c_ll.h +components/hal/esp32c2/include/hal/ledc_ll.h +components/hal/esp32c2/include/hal/mpu_ll.h +components/hal/esp32c2/include/hal/spi_flash_ll.h +components/hal/esp32c2/include/hal/spi_ll.h +components/hal/esp32c2/include/hal/spimem_flash_ll.h +components/hal/esp32c3/include/hal/adc_ll.h +components/hal/esp32c3/include/hal/aes_ll.h +components/hal/esp32c3/include/hal/cache_ll.h +components/hal/esp32c3/include/hal/gpspi_flash_ll.h +components/hal/esp32c3/include/hal/i2c_ll.h +components/hal/esp32c3/include/hal/ledc_ll.h +components/hal/esp32c3/include/hal/memprot_ll.h +components/hal/esp32c3/include/hal/mpi_ll.h +components/hal/esp32c3/include/hal/mpu_ll.h +components/hal/esp32c3/include/hal/spi_flash_ll.h +components/hal/esp32c3/include/hal/spi_ll.h +components/hal/esp32c3/include/hal/spimem_flash_ll.h +components/hal/esp32c3/include/hal/uhci_ll.h +components/hal/esp32c6/include/hal/aes_ll.h +components/hal/esp32c6/include/hal/cache_ll.h +components/hal/esp32c6/include/hal/ecc_ll.h +components/hal/esp32c6/include/hal/gpspi_flash_ll.h +components/hal/esp32c6/include/hal/i2c_ll.h +components/hal/esp32c6/include/hal/ieee802154_ll.h +components/hal/esp32c6/include/hal/mcpwm_ll.h +components/hal/esp32c6/include/hal/mpi_ll.h +components/hal/esp32c6/include/hal/mpu_ll.h +components/hal/esp32c6/include/hal/pcnt_ll.h +components/hal/esp32c6/include/hal/sdio_slave_ll.h +components/hal/esp32c6/include/hal/spi_flash_ll.h +components/hal/esp32c6/include/hal/spi_ll.h +components/hal/esp32c6/include/hal/spimem_flash_ll.h +components/hal/esp32h2/include/hal/aes_ll.h +components/hal/esp32h2/include/hal/cache_ll.h +components/hal/esp32h2/include/hal/ecc_ll.h +components/hal/esp32h2/include/hal/ecdsa_ll.h +components/hal/esp32h2/include/hal/gpspi_flash_ll.h +components/hal/esp32h2/include/hal/i2c_ll.h +components/hal/esp32h2/include/hal/ieee802154_ll.h +components/hal/esp32h2/include/hal/mcpwm_ll.h +components/hal/esp32h2/include/hal/mpi_ll.h +components/hal/esp32h2/include/hal/mpu_ll.h +components/hal/esp32h2/include/hal/pcnt_ll.h +components/hal/esp32h2/include/hal/spi_flash_ll.h +components/hal/esp32h2/include/hal/spi_ll.h +components/hal/esp32h2/include/hal/spimem_flash_ll.h +components/hal/esp32p4/include/hal/cache_ll.h +components/hal/esp32p4/include/hal/clk_tree_ll.h +components/hal/esp32p4/include/hal/ecc_ll.h +components/hal/esp32p4/include/hal/gpspi_flash_ll.h +components/hal/esp32p4/include/hal/mcpwm_ll.h +components/hal/esp32p4/include/hal/mpi_ll.h +components/hal/esp32p4/include/hal/mpu_ll.h +components/hal/esp32p4/include/hal/spi_flash_ll.h +components/hal/esp32p4/include/hal/spimem_flash_ll.h +components/hal/esp32s2/include/hal/aes_ll.h +components/hal/esp32s2/include/hal/cache_ll.h +components/hal/esp32s2/include/hal/dedic_gpio_ll.h +components/hal/esp32s2/include/hal/gpspi_flash_ll.h +components/hal/esp32s2/include/hal/i2c_ll.h +components/hal/esp32s2/include/hal/ledc_ll.h +components/hal/esp32s2/include/hal/memprot_peri_ll.h +components/hal/esp32s2/include/hal/mpi_ll.h +components/hal/esp32s2/include/hal/pcnt_ll.h +components/hal/esp32s2/include/hal/spi_flash_ll.h +components/hal/esp32s2/include/hal/spi_ll.h +components/hal/esp32s2/include/hal/spimem_flash_ll.h +components/hal/esp32s2/include/hal/touch_sensor_hal.h +components/hal/esp32s2/include/hal/touch_sensor_ll.h +components/hal/esp32s2/include/hal/usb_ll.h +components/hal/esp32s2/include/hal/usb_phy_ll.h +components/hal/esp32s3/include/hal/aes_ll.h +components/hal/esp32s3/include/hal/cache_ll.h +components/hal/esp32s3/include/hal/gpspi_flash_ll.h +components/hal/esp32s3/include/hal/i2c_ll.h +components/hal/esp32s3/include/hal/ledc_ll.h +components/hal/esp32s3/include/hal/mcpwm_ll.h +components/hal/esp32s3/include/hal/memprot_ll.h +components/hal/esp32s3/include/hal/mpi_ll.h +components/hal/esp32s3/include/hal/mspi_timing_tuning_ll.h +components/hal/esp32s3/include/hal/pcnt_ll.h +components/hal/esp32s3/include/hal/spi_flash_ll.h +components/hal/esp32s3/include/hal/spi_ll.h +components/hal/esp32s3/include/hal/spimem_flash_ll.h +components/hal/esp32s3/include/hal/touch_sensor_hal.h +components/hal/esp32s3/include/hal/touch_sensor_ll.h +components/hal/esp32s3/include/hal/uhci_ll.h +components/hal/esp32s3/include/hal/usb_ll.h +components/hal/esp32s3/include/hal/usb_phy_ll.h +components/hal/include/hal/adc_hal.h +components/hal/include/hal/aes_hal.h +components/hal/include/hal/assist_debug_hal.h +components/hal/include/hal/i2c_hal.h +components/hal/include/hal/ieee802154_common_ll.h +components/hal/include/hal/ledc_hal.h +components/hal/include/hal/sdio_slave_hal.h +components/hal/include/hal/spi_flash_hal.h +components/hal/include/hal/spi_hal.h +components/hal/include/hal/spi_slave_hal.h +components/hal/include/hal/spi_slave_hd_hal.h +components/lwip/include/lwip/netdb.h +components/soc/esp32c2/include/soc/ext_mem_defs.h +components/soc/esp32c2/include/soc/mmu.h +components/soc/esp32c3/include/soc/ext_mem_defs.h +components/soc/esp32c3/include/soc/mmu.h +components/soc/esp32c6/include/soc/ext_mem_defs.h +components/soc/esp32c6/include/soc/mmu.h +components/soc/esp32h2/include/soc/ext_mem_defs.h +components/soc/esp32h2/include/soc/mmu.h +components/soc/esp32p4/include/soc/ext_mem_defs.h +components/soc/esp32p4/include/soc/mmu.h +components/spi_flash/include/esp_private/spi_flash_os.h + ### To be fixed: files which don't compile for esp32s2 target: components/esp_psram/include/esp32/himem.h diff --git a/tools/test_apps/system/cxx_build_test/README.md b/tools/test_apps/system/cxx_build_test/README.md index 8d0f8f8c7f..1be06feb3e 100644 --- a/tools/test_apps/system/cxx_build_test/README.md +++ b/tools/test_apps/system/cxx_build_test/README.md @@ -5,11 +5,11 @@ This build-only app can be used to check if certain headers, macros or features can be successfully compiled in a C++ source file. It furthermore checks the current C++ language standard set in IDF is the expected one. +**Note:** C++ compatibility of all public header files is checked by [general public header check](../../../ci/check_public_headers.py) already. + ## This App Broke My Build :( -It is likely that one of the following situations occurred: -1. The language standard for IDF has been changed without changing the test in this application. -2. Code incompatible to C++ has been added to one of the public header files in IDF. Check the C++ documentation section [Combining C and C++ code](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/cplusplus.html#combining-c-and-c-code) for more details. +It is possible that the language standard for IDF has been changed without changing the test in this application. ## Adding New Test Create a new file `main/test_.cpp` and add it to main/CMakeLists.txt. If you need to check specific compiler flags, use `set_source_files_properties` CMake function to adjust the compilation flags for the given source file. diff --git a/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt b/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt index 941c102217..695b17a1b3 100644 --- a/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt +++ b/tools/test_apps/system/cxx_build_test/main/CMakeLists.txt @@ -1,9 +1,6 @@ idf_component_register(SRCS cxx_build_test_main.cpp test_soc_reg_macros.cpp - test_esp_hw_support.cpp test_cxx_standard.cpp INCLUDE_DIRS "." PRIV_REQUIRES driver REQUIRES soc) - -set_source_files_properties(test_esp_hw_support.cpp PROPERTIES COMPILE_FLAGS -Wsign-conversion) diff --git a/tools/test_apps/system/cxx_build_test/main/test_esp_hw_support.cpp b/tools/test_apps/system/cxx_build_test/main/test_esp_hw_support.cpp deleted file mode 100644 index a22927c706..0000000000 --- a/tools/test_apps/system/cxx_build_test/main/test_esp_hw_support.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ - -#include "esp_cpu.h" -#include "clk_ctrl_os.h" -//#include "clk_tree.h" TODO: outdated header name (IDF-7286) -#include "dport_access.h" -#include "esp_async_memcpy.h" -#include "esp_chip_info.h" -#include "esp_crc.h" -#include "esp_etm.h" -#include "esp_fault.h" -#include "esp_interface.h" -#include "esp_intr_alloc.h" -#include "esp_mac.h" -#include "esp_memory_utils.h" -#include "esp_memprot_err.h" -#include "esp_memprot.h" -#include "esp_memprot_types.h" -#include "esp_random.h" -#include "esp_sleep.h" -#include "esp_wake_stub.h" -#include "intr_types.h" -#include "rtc_wdt.h" -#include "spinlock.h" - -#include "soc/soc_caps.h" - -#if SOC_HMAC_SUPPORTED -#include "esp_hmac.h" -#endif - -#if SOC_DIG_SIGN_SUPPORTED -#include "esp_ds_err.h" -#include "esp_ds.h" -#endif - -extern "C" void app_main() { }