From 09ca9dfd2c8b9ef9ac7efa896fded43c7f741990 Mon Sep 17 00:00:00 2001 From: morris Date: Mon, 25 Nov 2024 22:07:35 +0800 Subject: [PATCH 1/2] feat(ci): add ast-grep rules to lint kconfig in the hal --- sgconfig.yml | 2 +- .../sg_rules/no_kconfig_in_hal_component.yml | 114 ++++++++++++++++++ .../no_private_rom_api_in_examples.yml | 4 +- .../no_std_assert_in_hal_component.yml | 8 +- 4 files changed, 121 insertions(+), 7 deletions(-) create mode 100644 tools/ci/sg_rules/no_kconfig_in_hal_component.yml diff --git a/sgconfig.yml b/sgconfig.yml index 8f89c92acf..d79b92efca 100644 --- a/sgconfig.yml +++ b/sgconfig.yml @@ -1,2 +1,2 @@ ruleDirs: -- ./tools/ci/sg_rules + - tools/ci/sg_rules diff --git a/tools/ci/sg_rules/no_kconfig_in_hal_component.yml b/tools/ci/sg_rules/no_kconfig_in_hal_component.yml new file mode 100644 index 0000000000..40bd3f9e5e --- /dev/null +++ b/tools/ci/sg_rules/no_kconfig_in_hal_component.yml @@ -0,0 +1,114 @@ +# Refer to https://ast-grep.github.io/guide/rule-config.html for Rule Essentials +id: no-kconfig-in-hal-component +message: Don't use Kconfig macros in the hal component +severity: error # error, warning, info, hint +note: hal component should be able to deliver without 3rd party config system +language: C +files: + - "components/hal/**/*" +ignores: + # porting layer and test apps are allowed to use Kconfig macros + - "components/hal/platform_port/**/*" + - "components/hal/test_apps/**/*" + # the following files should be refactored to remove Kconfig macros + - "components/hal/adc_hal.c" + - "components/hal/adc_oneshot_hal.c" + - "components/hal/apm_hal.c" + - "components/hal/ecdsa_hal.c" + - "components/hal/emac_hal.c" + - "components/hal/mmu_hal.c" + - "components/hal/sha_hal.c" + - "components/hal/spi_flash_encrypt_hal_iram.c" + - "components/hal/spi_flash_hal_iram.c" + - "components/hal/spi_flash_hal.c" + - "components/hal/spi_hal_iram.c" + - "components/hal/spi_hal.c" + - "components/hal/spi_slave_hal_iram.c" + - "components/hal/twai_hal_iram.c" + - "components/hal/twai_hal.c" + - "components/hal/usb_dwc_hal.c" + - "components/hal/wdt_hal_iram.c" + - "components/hal/esp32/efuse_hal.c" + - "components/hal/esp32/gpio_hal_workaround.c" + - "components/hal/esp32/include/hal/twai_ll.h" + - "components/hal/esp32/include/hal/uart_ll.h" + - "components/hal/esp32c2/clk_tree_hal.c" + - "components/hal/*/efuse_hal.c" + - "components/hal/include/hal/adc_types.h" + - "components/hal/include/hal/adc_hal.h" + - "components/hal/include/hal/apm_hal.h" + - "components/hal/include/hal/ecdsa_hal.h" + - "components/hal/include/hal/emac_hal.h" + - "components/hal/include/hal/gpio_hal.h" + - "components/hal/include/hal/mmu_hal.h" + - "components/hal/include/hal/pmu_types.h" + - "components/hal/include/hal/sha_types.h" + - "components/hal/include/hal/spi_slave_hal.h" + - "components/hal/include/hal/spi_types.h" + - "components/hal/include/hal/touch_sensor_legacy_types.h" + - "components/hal/include/hal/twai_types.h" +rule: + any: + - kind: argument_list + has: + kind: identifier + pattern: $N + - kind: preproc_if + has: + field: condition + pattern: $M +constraints: + N: + regex: "^CONFIG" + M: + regex: "^CONFIG" + +--- + +id: no-sdkconfig-include-in-hal-component +message: Don't include sdkconfig.h in the hal component +severity: error # error, warning, info, hint +note: hal component should be able to deliver without 3rd party config system +language: C +files: + - "components/hal/**/*" +ignores: + # porting layer and test apps are allowed to include sdkconfig.h + - "components/hal/platform_port/**/*" + - "components/hal/test_apps/**/*" + # the following files should be refactored to remove sdkconfig.h + - "components/hal/adc_hal.c" + - "components/hal/adc_oneshot_hal.c" + - "components/hal/cache_hal.c" + - "components/hal/emac_hal.c" + - "components/hal/mmu_hal.c" + - "components/hal/mpi_hal.c" + - "components/hal/spi_flash_hal_iram.c" + - "components/hal/twai_hal_iram.c" + - "components/hal/twai_hal.c" + - "components/hal/usb_dwc_hal.c" + - "components/hal/efuse_hal.c" + - "components/hal/esp32/include/hal/twai_ll.h" + - "components/hal/esp32c2/clk_tree_hal.c" + - "components/hal/*/efuse_hal.c" + - "components/hal/include/hal/adc_types.h" + - "components/hal/include/hal/ecdsa_hal.h" + - "components/hal/include/hal/modem_clock_hal.h" + - "components/hal/include/hal/mpi_hal.h" + - "components/hal/include/hal/pmu_types.h" + - "components/hal/include/hal/rtc_hal.h" + - "components/hal/include/hal/sha_types.h" + - "components/hal/include/hal/spi_slave_hal.h" + - "components/hal/include/hal/spi_types.h" + - "components/hal/include/hal/touch_sensor_legacy_types.h" + - "components/hal/include/hal/twai_hal.h" + - "components/hal/include/hal/twai_types.h" +rule: + kind: preproc_include + has: + field: path + pattern: $N +constraints: + N: + regex: '^["<]sdkconfig' # match "sdkconfig.h" or +fix: '' diff --git a/tools/ci/sg_rules/no_private_rom_api_in_examples.yml b/tools/ci/sg_rules/no_private_rom_api_in_examples.yml index ee8dc3d7c2..4c52550828 100644 --- a/tools/ci/sg_rules/no_private_rom_api_in_examples.yml +++ b/tools/ci/sg_rules/no_private_rom_api_in_examples.yml @@ -5,7 +5,7 @@ severity: error # error, warning, info, hint note: Only APIs prefixed with "esp_rom_" are treated as public. language: C files: - - "./examples/**/*" + - "examples/**/*" rule: kind: preproc_include has: @@ -22,7 +22,7 @@ severity: error # error, warning, info, hint note: Only APIs prefixed with "esp_rom_" are treated as public. language: Cpp files: - - "./examples/**/*" + - "examples/**/*" rule: kind: preproc_include has: diff --git a/tools/ci/sg_rules/no_std_assert_in_hal_component.yml b/tools/ci/sg_rules/no_std_assert_in_hal_component.yml index 5f6c3efdba..1e3a854cc1 100644 --- a/tools/ci/sg_rules/no_std_assert_in_hal_component.yml +++ b/tools/ci/sg_rules/no_std_assert_in_hal_component.yml @@ -5,9 +5,9 @@ severity: error # error, warning, info, hint note: The standard assert function depends on newlib(G1) component, but hal is a G0 component language: C files: - - "./components/hal/**/*" + - "components/hal/**/*" ignores: - - "./components/hal/test_apps/**/*" + - "components/hal/test_apps/**/*" rule: kind: expression_statement pattern: assert($$$ARGS); @@ -21,9 +21,9 @@ severity: error # error, warning, info, hint note: Please use hal/assert.h to replace assert.h language: C files: - - "./components/hal/**/*" + - "components/hal/**/*" ignores: - - "./components/hal/test_apps/**/*" + - "components/hal/test_apps/**/*" rule: kind: preproc_include has: From a8f6776b0f6c5de27d5385ab91d9b1d548a69faf Mon Sep 17 00:00:00 2001 From: morris Date: Wed, 27 Nov 2024 14:31:27 +0800 Subject: [PATCH 2/2] change(hal): remove unused sdkconfig.h --- components/hal/adc_hal_common.c | 1 - components/hal/efuse_hal.c | 1 - components/hal/esp32c2/efuse_hal.c | 1 - components/hal/esp32c3/efuse_hal.c | 1 - components/hal/esp32c61/include/hal/gdma_ll.h | 1 - components/hal/esp32p4/include/hal/assist_debug_ll.h | 4 ++-- components/hal/include/hal/pau_types.h | 1 - components/hal/include/hal/rtc_io_hal.h | 1 - components/hal/isp_hal.c | 1 - components/hal/lp_timer_hal.c | 1 - components/hal/spi_slave_hd_hal.c | 1 - 11 files changed, 2 insertions(+), 12 deletions(-) diff --git a/components/hal/adc_hal_common.c b/components/hal/adc_hal_common.c index e1d8a652f2..1a0cddc370 100644 --- a/components/hal/adc_hal_common.c +++ b/components/hal/adc_hal_common.c @@ -5,7 +5,6 @@ */ #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "hal/adc_hal_common.h" #include "hal/adc_ll.h" diff --git a/components/hal/efuse_hal.c b/components/hal/efuse_hal.c index ae0a86de57..28cdaed788 100644 --- a/components/hal/efuse_hal.c +++ b/components/hal/efuse_hal.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "sdkconfig.h" #include #include "soc/soc_caps.h" #include "hal/efuse_ll.h" diff --git a/components/hal/esp32c2/efuse_hal.c b/components/hal/esp32c2/efuse_hal.c index 608f294040..ff76025c35 100644 --- a/components/hal/esp32c2/efuse_hal.c +++ b/components/hal/esp32c2/efuse_hal.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "sdkconfig.h" #include #include "soc/soc_caps.h" #include "hal/assert.h" diff --git a/components/hal/esp32c3/efuse_hal.c b/components/hal/esp32c3/efuse_hal.c index d1a44974ad..2d7801a453 100644 --- a/components/hal/esp32c3/efuse_hal.c +++ b/components/hal/esp32c3/efuse_hal.c @@ -4,7 +4,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "sdkconfig.h" #include #include "soc/soc_caps.h" #include "hal/assert.h" diff --git a/components/hal/esp32c61/include/hal/gdma_ll.h b/components/hal/esp32c61/include/hal/gdma_ll.h index 5dfa8e31af..f167217769 100644 --- a/components/hal/esp32c61/include/hal/gdma_ll.h +++ b/components/hal/esp32c61/include/hal/gdma_ll.h @@ -5,7 +5,6 @@ */ #pragma once -#include "sdkconfig.h" #include "soc/pcr_struct.h" #include "hal/ahb_dma_ll.h" #define GDMA_LL_AHB_BURST_SIZE_ADJUSTABLE 1 // AHB GDMA supports adjustable burst size diff --git a/components/hal/esp32p4/include/hal/assist_debug_ll.h b/components/hal/esp32p4/include/hal/assist_debug_ll.h index e22eef7463..479a38f221 100644 --- a/components/hal/esp32p4/include/hal/assist_debug_ll.h +++ b/components/hal/esp32p4/include/hal/assist_debug_ll.h @@ -18,7 +18,7 @@ #include "esp_attr.h" #include "hal/assert.h" #include "soc/hp_sys_clkrst_struct.h" -#include "sdkconfig.h" +#include "soc/soc_caps.h" #ifdef __cplusplus extern "C" { @@ -125,7 +125,7 @@ FORCE_INLINE_ATTR void _assist_debug_ll_enable_bus_clock(bool enable) FORCE_INLINE_ATTR void _assist_debug_ll_reset_register(void) { /* esp32p4 has no assist_debug reset register: disable & clear interrupts manually. */ - for (int i = 0; i < CONFIG_SOC_CPU_CORES_NUM; i++) { + for (int i = 0; i < SOC_CPU_CORES_NUM; i++) { assist_debug_ll_sp_spill_monitor_disable(i); assist_debug_ll_sp_spill_interrupt_clear(i); assist_debug_ll_sp_spill_set_min(i, 0); diff --git a/components/hal/include/hal/pau_types.h b/components/hal/include/hal/pau_types.h index 27903ceed0..d15839eba1 100644 --- a/components/hal/include/hal/pau_types.h +++ b/components/hal/include/hal/pau_types.h @@ -5,7 +5,6 @@ */ #pragma once -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "soc/regdma.h" diff --git a/components/hal/include/hal/rtc_io_hal.h b/components/hal/include/hal/rtc_io_hal.h index 471a09e006..e254ec76d5 100644 --- a/components/hal/include/hal/rtc_io_hal.h +++ b/components/hal/include/hal/rtc_io_hal.h @@ -15,7 +15,6 @@ #pragma once #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #if SOC_RTCIO_PIN_COUNT > 0 diff --git a/components/hal/isp_hal.c b/components/hal/isp_hal.c index d271b0b702..6dc1cad264 100644 --- a/components/hal/isp_hal.c +++ b/components/hal/isp_hal.c @@ -7,7 +7,6 @@ #include #include #include -#include "sdkconfig.h" #include "soc/soc_caps.h" #include "hal/assert.h" #include "hal/log.h" diff --git a/components/hal/lp_timer_hal.c b/components/hal/lp_timer_hal.c index 7fcf95452e..008e2ada9f 100644 --- a/components/hal/lp_timer_hal.c +++ b/components/hal/lp_timer_hal.c @@ -7,7 +7,6 @@ #include #include #include -#include "sdkconfig.h" #include "esp_attr.h" #include "soc/soc.h" #include "hal/lp_timer_ll.h" diff --git a/components/hal/spi_slave_hd_hal.c b/components/hal/spi_slave_hd_hal.c index ab57764f6d..53a432939a 100644 --- a/components/hal/spi_slave_hd_hal.c +++ b/components/hal/spi_slave_hd_hal.c @@ -10,7 +10,6 @@ #include "esp_types.h" #include "esp_attr.h" #include "esp_err.h" -#include "sdkconfig.h" #include "soc/spi_periph.h" #include "soc/lldesc.h" #include "soc/soc_caps.h"