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
This commit is contained in:
Jakob Hasse 2023-08-09 14:12:21 +08:00
parent 44e4ef79e2
commit 8b9f8555ea
5 changed files with 153 additions and 53 deletions

View File

@ -32,8 +32,16 @@ class HeaderFailedSdkconfig(HeaderFailed):
class HeaderFailedBuildError(HeaderFailed): class HeaderFailedBuildError(HeaderFailed):
def __init__(self, compiler: str):
self.compiler = compiler
def __str__(self) -> str: 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): class HeaderFailedCppGuardMissing(HeaderFailed):
@ -164,7 +172,7 @@ class PublicHeaderChecker:
elif res == self.COMPILE_ERR_ERROR_MACRO_HDR_OK: elif res == self.COMPILE_ERR_ERROR_MACRO_HDR_OK:
return self.compile_one_header(header) return self.compile_one_header(header)
elif res == self.COMPILE_ERR_HDR_FAILED: elif res == self.COMPILE_ERR_HDR_FAILED:
raise HeaderFailedBuildError() raise HeaderFailedPreprocessError()
elif res == self.PREPROC_OUT_ZERO_HDR_OK: elif res == self.PREPROC_OUT_ZERO_HDR_OK:
return self.compile_one_header(header) return self.compile_one_header(header)
elif res == self.PREPROC_OUT_SAME_HRD_FAILED: elif res == self.PREPROC_OUT_SAME_HRD_FAILED:
@ -186,7 +194,11 @@ class PublicHeaderChecker:
os.unlink(temp_header) os.unlink(temp_header)
def compile_one_header(self, header: str) -> None: 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 rc == 0:
if not re.sub(self.assembly_nocode, '', out, flags=re.M).isspace(): if not re.sub(self.assembly_nocode, '', out, flags=re.M).isspace():
raise HeaderFailedContainsCode() raise HeaderFailedContainsCode()
@ -194,7 +206,7 @@ class PublicHeaderChecker:
self.log('{}: FAILED: compilation issue'.format(header), True) self.log('{}: FAILED: compilation issue'.format(header), True)
self.log(err, True) self.log(err, True)
self.log('\nCompilation command failed:\n{}\n'.format(cmd), 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: 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 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 = [] all_include_files = []
files_to_check = [] files_to_check = []
for d in include_dirs: 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)) self.log('{} - directory ignored (not in "{}")'.format(d, only_dir))
continue continue
if os.path.relpath(d, idf_path).startswith(tuple(ignore_dirs)): 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 referenced macros, types are available (defined or included)
* Check that all included header files are available (included in paths) * Check that all included header files are available (included in paths)
* Check for possible compilation issues * 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 * Try to compile only the offending header file
3) "Header Missing C++ Guard": Preprocessing the header by C and C++ should produce different output 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 * Check if the "#ifdef __cplusplus" header sentinels are present

View File

@ -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/esp_wifi_netif.h
components/esp_wifi/include/smartconfig_ack.h components/esp_wifi/include/smartconfig_ack.h
components/esp_wifi/include/esp_wifi_default.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_defaults.h
components/esp_netif/include/esp_netif_net_stack.h components/esp_netif/include/esp_netif_net_stack.h
components/esp_netif/include/esp_netif_ppp.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/esp_private/usb_phy.h
components/usb/include/usb/usb_types_stack.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: ### To be fixed: files which don't compile for esp32s2 target:
components/esp_psram/include/esp32/himem.h components/esp_psram/include/esp32/himem.h

View File

@ -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. 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 :( ## This App Broke My Build :(
It is likely that one of the following situations occurred: It is possible that the language standard for IDF has been changed without changing the test in this application.
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.
## Adding New Test ## Adding New Test
Create a new file `main/test_<name>.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. Create a new file `main/test_<name>.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.

View File

@ -1,9 +1,6 @@
idf_component_register(SRCS cxx_build_test_main.cpp idf_component_register(SRCS cxx_build_test_main.cpp
test_soc_reg_macros.cpp test_soc_reg_macros.cpp
test_esp_hw_support.cpp
test_cxx_standard.cpp test_cxx_standard.cpp
INCLUDE_DIRS "." INCLUDE_DIRS "."
PRIV_REQUIRES driver PRIV_REQUIRES driver
REQUIRES soc) REQUIRES soc)
set_source_files_properties(test_esp_hw_support.cpp PROPERTIES COMPILE_FLAGS -Wsign-conversion)

View File

@ -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() { }