Skip to content

Commit

Permalink
Add c_cpp_properties.json and its checker
Browse files Browse the repository at this point in the history
  • Loading branch information
okalachev committed Jun 11, 2024
1 parent 1a22350 commit c62cbfd
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ on:
branches: [ master ]

jobs:
build:
build_linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Arduino CLI
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
Expand All @@ -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
Expand All @@ -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
Expand Down
144 changes: 144 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 5 additions & 0 deletions .vscode/intellisense.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifdef __INTELLISENSE__
#pragma diag_suppress 144, 513
// diag 144: a value of type "enum <unnamed>" cannot be used to initialize an entity of type "enum <unnamed>"C/C++
// diag 513: a value of type "enum <unnamed>" cannot be assigned to an entity of type "enum <unnamed>"C/C++
#endif
49 changes: 49 additions & 0 deletions tools/check_c_cpp_properties.py
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit c62cbfd

Please sign in to comment.