fbt, vscode: tweaks for cdb generation for clangd (#3680)

* fbt, vscode: tweaks for cdb generation for clangd
* .clangd: updated config
* vscode: disabled auto header insertion for clangd
* .clangd: updated config, ignoring format warnings
* Add sublime text project
* vscode: enabled clang-tidy for clangd
* clangd: strict include checks for sources only

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
hedger 2024-06-01 16:20:51 +04:00 committed by GitHub
parent 83e4bcc35a
commit c93d164785
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 64 additions and 13 deletions

13
.clangd Normal file
View file

@ -0,0 +1,13 @@
CompileFlags:
Add:
- -Wno-unknown-warning-option
- -Wno-format
Remove:
- -mword-relocations
---
If:
PathMatch: .*\.h
Diagnostics:
UnusedIncludes: None

3
.gitignore vendored
View file

@ -12,6 +12,9 @@ compile_commands.json
# JetBrains IDEs
.idea/
# Sublime Text
.sublime-project.sublime-workspace
# Python VirtEnvironments
.env
.venv

21
.sublime-project vendored Normal file
View file

@ -0,0 +1,21 @@
{
"folders":
[
{
"path": ".",
}
],
"settings": {
"LSP": {
"clangd": {
"initializationOptions": {
"clangd.compile-commands-dir": "build/latest",
"clangd.header-insertion": null,
"clangd.query-driver": "**",
"clangd.clang-tidy": true,
},
"enabled": true,
},
},
},
}

View file

@ -19,6 +19,8 @@
"clangd.arguments": [
// We might be able to tighten this a bit more to only include the correct toolchain.
"--query-driver=**",
"--compile-commands-dir=${workspaceFolder}/build/latest"
"--compile-commands-dir=${workspaceFolder}/build/latest",
"--clang-tidy",
"--header-insertion=never"
]
}

View file

@ -20,6 +20,7 @@ env = ENV.Clone(
"fbt_resources",
],
COMPILATIONDB_USE_ABSPATH=False,
COMPILATIONDB_USE_BINARY_ABSPATH=True,
BUILD_DIR=fw_build_meta["build_dir"],
IS_BASE_FIRMWARE=fw_build_meta["type"] == "firmware",
FW_FLAVOR=fw_build_meta["flavor"],

View file

@ -12,3 +12,4 @@ def generate(env):
env["LINK"] = env["CXX"]
env["CXX_NOCACHE"] = env["CXX"]
env["CXX"] = "$CCACHE $CXX_NOCACHE"
env.AppendUnique(COMPILATIONDB_OMIT_BINARIES=["ccache"])

View file

@ -32,7 +32,7 @@ which is the name that most clang tools search for by default.
import fnmatch
import itertools
import json
from shlex import quote
from shlex import join, split
import SCons
from SCons.Tool.asm import ASPPSuffixes, ASSuffixes
@ -108,6 +108,10 @@ def make_emit_compilation_DB_entry(comstr):
return emit_compilation_db_entry
def __is_value_true(value):
return value in [True, 1, "True", "true"]
def compilation_db_entry_action(target, source, env, **kw):
"""
Create a dictionary with evaluated command line, target, source
@ -126,16 +130,19 @@ def compilation_db_entry_action(target, source, env, **kw):
env=env["__COMPILATIONDB_ENV"],
)
# We assume first non-space character is the executable
executable = command.split(" ", 1)[0]
if not (tool_path := _TOOL_PATH_CACHE.get(executable, None)):
tool_path = env.WhereIs(executable) or executable
_TOOL_PATH_CACHE[executable] = tool_path
# If there are spaces in the executable path, we need to quote it
if " " in tool_path:
tool_path = quote(tool_path)
# Replacing the executable with the full path
command = tool_path + command[len(executable) :]
cmdline = split(command)
binaries_to_omit = env["COMPILATIONDB_OMIT_BINARIES"]
while (executable := cmdline[0]) in binaries_to_omit:
cmdline.pop(0)
if __is_value_true(env["COMPILATIONDB_USE_BINARY_ABSPATH"]):
if not (tool_path := _TOOL_PATH_CACHE.get(executable, None)):
tool_path = env.WhereIs(executable) or executable
_TOOL_PATH_CACHE[executable] = tool_path
# Replacing the executable with the full path
executable = tool_path
command = join((executable, *cmdline[1:]))
entry = {
"directory": env.Dir("#").abspath,
@ -150,7 +157,7 @@ def compilation_db_entry_action(target, source, env, **kw):
def write_compilation_db(target, source, env):
entries = []
use_abspath = env["COMPILATIONDB_USE_ABSPATH"] in [True, 1, "True", "true"]
use_abspath = __is_value_true(env["COMPILATIONDB_USE_ABSPATH"])
use_path_filter = env.subst("$COMPILATIONDB_PATH_FILTER")
use_srcpath_filter = env.subst("$COMPILATIONDB_SRCPATH_FILTER")
@ -225,6 +232,8 @@ def generate(env, **kwargs):
COMPILATIONDB_USE_ABSPATH=False,
COMPILATIONDB_PATH_FILTER="",
COMPILATIONDB_SRCPATH_FILTER="",
COMPILATIONDB_OMIT_BINARIES=[],
COMPILATIONDB_USE_BINARY_ABSPATH=False,
)
components_by_suffix = itertools.chain(

View file

@ -102,6 +102,7 @@ env = core_env.Clone(
core_env.subst("$SDK_DEFINITION"), load_version_only=True
).version,
APPCHECK_COMSTR="\tAPPCHK\t${SOURCE}\n\t\tTarget: ${TARGET_HW}, API: ${UFBT_API_VERSION}",
COMPILATIONDB_USE_BINARY_ABSPATH=True,
)
wrap_tempfile(env, "LINKCOM")