Support clang-tidy for ESP32 variants (#3001)

This commit is contained in:
Oxan van Leeuwen 2022-01-05 21:30:15 +01:00 committed by GitHub
parent 3067e482fc
commit d8e719d1c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 40 deletions

View file

@ -51,26 +51,26 @@ jobs:
name: Run script/clang-format name: Run script/clang-format
- id: clang-tidy - id: clang-tidy
name: Run script/clang-tidy for ESP8266 name: Run script/clang-tidy for ESP8266
options: --environment esp8266-tidy --grep USE_ESP8266 options: --environment esp8266-arduino-tidy --grep USE_ESP8266
pio_cache_key: tidyesp8266 pio_cache_key: tidyesp8266
- id: clang-tidy - id: clang-tidy
name: Run script/clang-tidy for ESP32 1/4 name: Run script/clang-tidy for ESP32 Arduino 1/4
options: --environment esp32-tidy --split-num 4 --split-at 1 options: --environment esp32-arduino-tidy --split-num 4 --split-at 1
pio_cache_key: tidyesp32 pio_cache_key: tidyesp32
- id: clang-tidy - id: clang-tidy
name: Run script/clang-tidy for ESP32 2/4 name: Run script/clang-tidy for ESP32 Arduino 2/4
options: --environment esp32-tidy --split-num 4 --split-at 2 options: --environment esp32-arduino-tidy --split-num 4 --split-at 2
pio_cache_key: tidyesp32 pio_cache_key: tidyesp32
- id: clang-tidy - id: clang-tidy
name: Run script/clang-tidy for ESP32 3/4 name: Run script/clang-tidy for ESP32 Arduino 3/4
options: --environment esp32-tidy --split-num 4 --split-at 3 options: --environment esp32-arduino-tidy --split-num 4 --split-at 3
pio_cache_key: tidyesp32 pio_cache_key: tidyesp32
- id: clang-tidy - id: clang-tidy
name: Run script/clang-tidy for ESP32 4/4 name: Run script/clang-tidy for ESP32 Arduino 4/4
options: --environment esp32-tidy --split-num 4 --split-at 4 options: --environment esp32-arduino-tidy --split-num 4 --split-at 4
pio_cache_key: tidyesp32 pio_cache_key: tidyesp32
- id: clang-tidy - id: clang-tidy
name: Run script/clang-tidy for ESP32 esp-idf name: Run script/clang-tidy for ESP32 IDF
options: --environment esp32-idf-tidy --grep USE_ESP_IDF options: --environment esp32-idf-tidy --grep USE_ESP_IDF
pio_cache_key: tidyesp32-idf pio_cache_key: tidyesp32-idf

View file

@ -4,7 +4,7 @@
; It's *not* used during runtime. ; It's *not* used during runtime.
[platformio] [platformio]
default_envs = esp8266, esp32, esp32-idf default_envs = esp8266-arduino, esp32-arduino, esp32-idf
; Ideally, we want src_dir to be the root directory of the repository, to mimic the runtime build ; Ideally, we want src_dir to be the root directory of the repository, to mimic the runtime build
; environment as best as possible. Unfortunately, the ESP-IDF toolchain really doesn't like this ; environment as best as possible. Unfortunately, the ESP-IDF toolchain really doesn't like this
; being the root directory. Instead, set esphome/ as the source directory, all our sources are in ; being the root directory. Instead, set esphome/ as the source directory, all our sources are in
@ -13,14 +13,14 @@ default_envs = esp8266, esp32, esp32-idf
src_dir = esphome src_dir = esphome
include_dir = . include_dir = .
[runtime] ; This are just the build flags as set by the runtime.
; This are the flags as set by the runtime. [flags:runtime]
build_flags = build_flags =
-Wno-unused-but-set-variable -Wno-unused-but-set-variable
-Wno-sign-compare -Wno-sign-compare
[clangtidy] ; This are just the build flags for clang-tidy.
; This are the flags for clang-tidy. [flags:clangtidy]
build_flags = build_flags =
-Wall -Wall
-Wextra -Wextra
@ -30,6 +30,7 @@ build_flags =
-Wshadow-field-in-constructor -Wshadow-field-in-constructor
-Wshadow-uncaptured-local -Wshadow-uncaptured-local
; This are common settings for all environments.
[common] [common]
lib_deps = lib_deps =
esphome/noise-c@0.1.4 ; api esphome/noise-c@0.1.4 ; api
@ -43,6 +44,7 @@ src_filter =
+<../tests/dummy_main.cpp> +<../tests/dummy_main.cpp>
+<../.temp/all-include.cpp> +<../.temp/all-include.cpp>
; This are common settings for all Arduino-framework based environments.
[common:arduino] [common:arduino]
extends = common extends = common
lib_deps = lib_deps =
@ -62,13 +64,15 @@ build_flags =
${common.build_flags} ${common.build_flags}
-DUSE_ARDUINO -DUSE_ARDUINO
; This are common settings for all IDF-framework based environments.
[common:idf] [common:idf]
extends = common extends = common
build_flags = build_flags =
${common.build_flags} ${common.build_flags}
-DUSE_ESP_IDF -DUSE_ESP_IDF
[common:esp8266] ; This are common settings for the ESP8266 using Arduino.
[common:esp8266-arduino]
extends = common:arduino extends = common:arduino
; when changing this also copy it to esphome-docker-base images ; when changing this also copy it to esphome-docker-base images
platform = platformio/espressif8266 @ 3.2.0 platform = platformio/espressif8266 @ 3.2.0
@ -76,7 +80,6 @@ platform_packages =
platformio/framework-arduinoespressif8266 @ ~3.30002.0 platformio/framework-arduinoespressif8266 @ ~3.30002.0
framework = arduino framework = arduino
board = nodemcuv2
lib_deps = lib_deps =
${common:arduino.lib_deps} ${common:arduino.lib_deps}
ESP8266WiFi ; wifi (Arduino built-in) ESP8266WiFi ; wifi (Arduino built-in)
@ -87,6 +90,7 @@ build_flags =
-DUSE_ESP8266 -DUSE_ESP8266
-DUSE_ESP8266_FRAMEWORK_ARDUINO -DUSE_ESP8266_FRAMEWORK_ARDUINO
; This are common settings for the ESP32 (all variants) using Arduino.
[common:esp32-arduino] [common:esp32-arduino]
extends = common:arduino extends = common:arduino
; when changing this also copy it to esphome-docker-base images ; when changing this also copy it to esphome-docker-base images
@ -104,6 +108,7 @@ build_flags =
-DUSE_ESP32 -DUSE_ESP32
-DUSE_ESP32_FRAMEWORK_ARDUINO -DUSE_ESP32_FRAMEWORK_ARDUINO
; This are common settings for the ESP32 (all variants) using IDF.
[common:esp32-idf] [common:esp32-idf]
extends = common:idf extends = common:idf
; when changing this also copy it to esphome-docker-base images ; when changing this also copy it to esphome-docker-base images
@ -112,7 +117,6 @@ platform_packages =
platformio/framework-espidf @ ~3.40300.0 platformio/framework-espidf @ ~3.40300.0
framework = espidf framework = espidf
board = nodemcu-32s
lib_deps = lib_deps =
${common:idf.lib_deps} ${common:idf.lib_deps}
espressif/esp32-camera@1.0.0 ; esp32_camera espressif/esp32-camera@1.0.0 ; esp32_camera
@ -122,40 +126,79 @@ build_flags =
-DUSE_ESP32 -DUSE_ESP32
-DUSE_ESP32_FRAMEWORK_ESP_IDF -DUSE_ESP32_FRAMEWORK_ESP_IDF
[env:esp8266] ; All the actual environments are defined below.
extends = common:esp8266 [env:esp8266-arduino]
extends = common:esp8266-arduino
board = nodemcuv2
build_flags = build_flags =
${common:esp8266.build_flags} ${common:esp8266-arduino.build_flags}
${runtime.build_flags} ${flags:runtime.build_flags}
[env:esp8266-tidy] [env:esp8266-arduino-tidy]
extends = common:esp8266 extends = common:esp8266-arduino
board = nodemcuv2
build_flags = build_flags =
${common:esp8266.build_flags} ${common:esp8266-arduino.build_flags}
${clangtidy.build_flags} ${flags:clangtidy.build_flags}
[env:esp32] [env:esp32-arduino]
extends = common:esp32-arduino extends = common:esp32-arduino
board = esp32dev
build_flags = build_flags =
${common:esp32-arduino.build_flags} ${common:esp32-arduino.build_flags}
${runtime.build_flags} ${flags:runtime.build_flags}
[env:esp32-tidy] [env:esp32-arduino-tidy]
extends = common:esp32-arduino extends = common:esp32-arduino
board = esp32dev
build_flags = build_flags =
${common:esp32-arduino.build_flags} ${common:esp32-arduino.build_flags}
${clangtidy.build_flags} ${flags:clangtidy.build_flags}
[env:esp32-idf] [env:esp32-idf]
extends = common:esp32-idf extends = common:esp32-idf
board = esp32dev
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32-idf board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32-idf
build_flags = build_flags =
${common:esp32-idf.build_flags} ${common:esp32-idf.build_flags}
${runtime.build_flags} ${flags:runtime.build_flags}
[env:esp32-idf-tidy] [env:esp32-idf-tidy]
extends = common:esp32-idf extends = common:esp32-idf
board = esp32dev
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32-idf-tidy board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32-idf-tidy
build_flags = build_flags =
${common:esp32-idf.build_flags} ${common:esp32-idf.build_flags}
${clangtidy.build_flags} ${flags:clangtidy.build_flags}
[env:esp32c3-idf]
extends = common:esp32-idf
board = esp32-c3-devkitm-1
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32c3-idf
build_flags =
${common:esp32-idf.build_flags}
${flags:runtime.build_flags}
[env:esp32c3-idf-tidy]
extends = common:esp32-idf
board = esp32-c3-devkitm-1
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32c3-idf-tidy
build_flags =
${common:esp32-idf.build_flags}
${flags:clangtidy.build_flags}
[env:esp32s2-idf]
extends = common:esp32-idf
board = esp32-s2-kaluga-1
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32s2-idf
build_flags =
${common:esp32-idf.build_flags}
${flags:runtime.build_flags}
[env:esp32s2-idf-tidy]
extends = common:esp32-idf
board = esp32-s2-kaluga-1
board_build.esp-idf.sdkconfig_path = .temp/sdkconfig-esp32s2-idf-tidy
build_flags =
${common:esp32-idf.build_flags}
${flags:clangtidy.build_flags}

View file

@ -17,9 +17,19 @@ import threading
def clang_options(idedata): def clang_options(idedata):
cmd = [ cmd = []
# target 32-bit arch (this prevents size mismatch errors on a 64-bit host)
'-m32', # extract target architecture from triplet in g++ filename
triplet = os.path.basename(idedata['cxx_path'])[:-4]
if triplet.startswith("xtensa-"):
# clang doesn't support Xtensa (yet?), so compile in 32-bit mode and pretend we're the Xtensa compiler
cmd.append('-m32')
cmd.append('-D__XTENSA__')
else:
cmd.append(f'--target={triplet}')
# set flags
cmd.extend([
# disable built-in include directories from the host # disable built-in include directories from the host
'-nostdinc', '-nostdinc',
'-nostdinc++', '-nostdinc++',
@ -39,15 +49,13 @@ def clang_options(idedata):
# suppress warning about attribute cannot be applied to type # suppress warning about attribute cannot be applied to type
# https://github.com/esp8266/Arduino/pull/8258 # https://github.com/esp8266/Arduino/pull/8258
'-Ddeprecated(x)=', '-Ddeprecated(x)=',
# pretend we're an Xtensa compiler, which gates some features in the headers
'-D__XTENSA__',
# allow to condition code on the presence of clang-tidy # allow to condition code on the presence of clang-tidy
'-DCLANG_TIDY', '-DCLANG_TIDY',
# (esp-idf) Disable this header because they use asm with registers clang-tidy doesn't know # (esp-idf) Disable this header because they use asm with registers clang-tidy doesn't know
'-D__XTENSA_API_H__', '-D__XTENSA_API_H__',
# (esp-idf) Fix __once_callable in some libstdc++ headers # (esp-idf) Fix __once_callable in some libstdc++ headers
'-D_GLIBCXX_HAVE_TLS', '-D_GLIBCXX_HAVE_TLS',
] ])
# copy compiler flags, except those clang doesn't understand. # copy compiler flags, except those clang doesn't understand.
cmd.extend(flag for flag in idedata['cxx_flags'].split(' ') cmd.extend(flag for flag in idedata['cxx_flags'].split(' ')
@ -126,8 +134,8 @@ def main():
parser.add_argument('-j', '--jobs', type=int, parser.add_argument('-j', '--jobs', type=int,
default=multiprocessing.cpu_count(), default=multiprocessing.cpu_count(),
help='number of tidy instances to be run in parallel.') help='number of tidy instances to be run in parallel.')
parser.add_argument('-e', '--environment', default='esp32-tidy', parser.add_argument('-e', '--environment', default='esp32-arduino-tidy',
help='the PlatformIO environment to run against (esp8266-tidy or esp32-tidy)') help='the PlatformIO environment to use (as defined in platformio.ini)')
parser.add_argument('files', nargs='*', default=[], parser.add_argument('files', nargs='*', default=[],
help='files to be processed (regex on path)') help='files to be processed (regex on path)')
parser.add_argument('--fix', action='store_true', help='apply fix-its') parser.add_argument('--fix', action='store_true', help='apply fix-its')