From 33b6845125e0ab6abfec888ef6f75f1b15d4dfd8 Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Tue, 11 Jun 2024 22:54:09 +0300 Subject: [PATCH] Add c_cpp_properties.json and its checker --- .github/workflows/build.yml | 8 +- .vscode/c_cpp_properties.json | 144 ++++++++++++++++++++++++++++++++ .vscode/intellisense.h | 5 ++ tools/check_c_cpp_properties.py | 49 +++++++++++ 4 files changed, 205 insertions(+), 1 deletion(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/intellisense.h create mode 100644 tools/check_c_cpp_properties.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eedd6a7..dc6a532 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,7 +7,7 @@ on: branches: [ master ] jobs: - build: + build_linux: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -15,6 +15,8 @@ jobs: run: curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/usr/local/bin sh - name: Build firmware run: make + - name: Check c_cpp_properties.json + run: tools/check_c_cpp_properties.py build_macos: runs-on: macos-latest @@ -24,6 +26,8 @@ jobs: run: brew install arduino-cli - name: Build firmware run: make + - name: Check c_cpp_properties.json + run: tools/check_c_cpp_properties.py build_windows: runs-on: windows-latest @@ -35,6 +39,8 @@ jobs: run: choco install make - name: Build firmware run: make + - name: Check c_cpp_properties.json + run: tools/check_c_cpp_properties.py build_simulator: runs-on: ubuntu-latest diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..186dafe --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,144 @@ +{ + // https://support.arduino.cc/hc/en-us/articles/4415103213714-Find-sketches-libraries-board-cores-and-other-files-on-your-computer# + "env": { + "coreVersion": "2.0.11" + }, + "configurations": [ + { + "name": "Linux", + "includePath": [ + "~/Arduino/libraries/**", + "~/.arduino15/packages/esp32/hardware/esp32/${coreVersion}/variants/d1_mini32", + "~/.arduino15/packages/esp32/hardware/esp32/${coreVersion}/libraries/**", + "~/.arduino15/packages/esp32/hardware/esp32/${coreVersion}/cores/**", + "~/.arduino15/packages/esp32/hardware/esp32/${coreVersion}/tools/sdk/esp32/**", + "${workspaceFolder}/flix" + ], + "forcedInclude": [ + "${workspaceFolder}/.vscode/intellisense.h", + "~/.arduino15/packages/esp32/hardware/esp32/${coreVersion}/cores/esp32/Arduino.h", + "~/.arduino15/packages/esp32/hardware/esp32/${coreVersion}/variants/d1_mini32/pins_arduino.h", + "${workspaceFolder}/flix/cli.ino", + "${workspaceFolder}/flix/control.ino", + "${workspaceFolder}/flix/estimate.ino", + "${workspaceFolder}/flix/flix.ino", + "${workspaceFolder}/flix/imu.ino", + "${workspaceFolder}/flix/led.ino", + "${workspaceFolder}/flix/log.ino", + "${workspaceFolder}/flix/mavlink.ino", + "${workspaceFolder}/flix/motors.ino", + "${workspaceFolder}/flix/rc.ino", + "${workspaceFolder}/flix/time.ino", + "${workspaceFolder}/flix/util.ino", + "${workspaceFolder}/flix/wifi.ino" + ], + "browse": { + "path": [ + "~/.arduino15/packages/esp32/hardware/esp32/${coreVersion}/cores/esp32/", + "~/.arduino15/packages/esp32/hardware/esp32/${coreVersion}/libraries", + "~/cloned/FreeRTOS-Kernel" + ] + }, + "compilerPath": "~/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/xtensa-esp32-elf-g++", + "cStandard": "c11", + "cppStandard": "c++17", + "defines": [ + "ARDUINO=10812", + "ARDUINO_D1_MINI32", + "ESP32", + "F_CPU=240000000L" + ] + }, + { + "name": "macOS", + "includePath": [ + "~/Documents/Arduino/libraries/**", + "~/Library/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/variants/d1_mini32", + "~/Library/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/libraries/**", + "~/Library/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/cores/**", + "~/Library/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/tools/sdk/esp32/**", + "${workspaceFolder}/flix" + ], + "forcedInclude": [ + "${workspaceFolder}/.vscode/intellisense.h", + "~/Library/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/cores/esp32/Arduino.h", + "~/Library/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/variants/d1_mini32/pins_arduino.h", + "${workspaceFolder}/flix/cli.ino", + "${workspaceFolder}/flix/control.ino", + "${workspaceFolder}/flix/estimate.ino", + "${workspaceFolder}/flix/flix.ino", + "${workspaceFolder}/flix/imu.ino", + "${workspaceFolder}/flix/led.ino", + "${workspaceFolder}/flix/log.ino", + "${workspaceFolder}/flix/mavlink.ino", + "${workspaceFolder}/flix/motors.ino", + "${workspaceFolder}/flix/rc.ino", + "${workspaceFolder}/flix/time.ino", + "${workspaceFolder}/flix/util.ino", + "${workspaceFolder}/flix/wifi.ino" + ], + "browse": { + "path": [ + "~/Library/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/cores/esp32/", + "~/Library/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/libraries", + "~/cloned/FreeRTOS-Kernel" + ] + }, + "compilerPath": "~/Library/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/xtensa-esp32-elf-g++", + "cStandard": "c11", + "cppStandard": "c++17", + "defines": [ + "ARDUINO=10812", + "ARDUINO_D1_MINI32", + "ESP32", + "F_CPU=240000000L" + ] + }, + { + "name": "Windows", + "includePath": [ + "~/Documents/Arduino/libraries/**", + "~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/variants/d1_mini32", + "~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/libraries/**", + "~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/cores/**", + "~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/tools/sdk/esp32/**", + "${workspaceFolder}/flix" + ], + "forcedInclude": [ + "${workspaceFolder}/.vscode/intellisense.h", + "~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/cores/esp32/Arduino.h", + "~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/variants/d1_mini32/pins_arduino.h", + "${workspaceFolder}/flix/cli.ino", + "${workspaceFolder}/flix/control.ino", + "${workspaceFolder}/flix/estimate.ino", + "${workspaceFolder}/flix/flix.ino", + "${workspaceFolder}/flix/imu.ino", + "${workspaceFolder}/flix/led.ino", + "${workspaceFolder}/flix/log.ino", + "${workspaceFolder}/flix/mavlink.ino", + "${workspaceFolder}/flix/motors.ino", + "${workspaceFolder}/flix/rc.ino", + "${workspaceFolder}/flix/time.ino", + "${workspaceFolder}/flix/util.ino", + "${workspaceFolder}/flix/wifi.ino" + ], + "browse": { + "path": [ + "~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/cores/esp32/", + "~/AppData/Local/Arduino15/packages/esp32/hardware/esp32/${coreVersion}/libraries", + "~/cloned/FreeRTOS-Kernel" + ] + }, + "compilerPath": "~/AppData/Local/Arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/xtensa-esp32-elf-g++.exe", + "cStandard": "c11", + "cppStandard": "c++17", + "defines": [ + "ARDUINO=10812", + "ARDUINO_D1_MINI32", + "ESP32", + "F_CPU=240000000L" + ] + } + ], + "version": 4 +} diff --git a/.vscode/intellisense.h b/.vscode/intellisense.h new file mode 100644 index 0000000..223bdd1 --- /dev/null +++ b/.vscode/intellisense.h @@ -0,0 +1,5 @@ +#ifdef __INTELLISENSE__ + #pragma diag_suppress 144, 513 + // diag 144: a value of type "enum " cannot be used to initialize an entity of type "enum "C/C++ + // diag 513: a value of type "enum " cannot be assigned to an entity of type "enum "C/C++ +#endif diff --git a/tools/check_c_cpp_properties.py b/tools/check_c_cpp_properties.py new file mode 100644 index 0000000..2af4a32 --- /dev/null +++ b/tools/check_c_cpp_properties.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +import os +import platform +import json5 + + +props = json5.load(open('.vscode/c_cpp_properties.git.json')) + +env = props.get('env', {}) +env['workspaceFolder'] = '.' + +def abspath(s): + # replace env + for key, value in env.items(): + s = s.replace('${' + key + '}', value) + # remove globs from the end + if s.endswith('**'): + s = s[:-2] + elif s.endswith('*'): + s = s[:-1] + return os.path.expanduser(s) + +# linux, macos or windows: +platform = platform.system().lower() +if platform == 'darwin': + platform = 'macos' +elif platform == 'linux' or platform == 'windows': + pass +else: + raise Exception('Unknown platform: ' + platform) + +for configuration in props['configurations']: + if platform not in configuration['name'].lower(): + print('Skip', configuration['name']) + continue + + print('Check configuration', configuration['name']) + + for include_path in configuration.get('includePath', []): + assert os.path.exists(abspath(include_path)), include_path + + for forced_include in configuration.get('forcedInclude', []): + assert os.path.exists(abspath(forced_include)), forced_include + + for browse in configuration.get('browse', {}).get('path', []): + assert os.path.exists(abspath(browse)), browse + + assert os.path.exists(abspath(configuration.get('compilerPath', '~'))), configuration.get('compilerPath')