clangd enhancements. (#23310)

This commit is contained in:
Nick Brassel 2024-05-02 20:08:41 +10:00 committed by GitHub
parent 29a4e5c50b
commit 9a4f39b738
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 5 deletions

View File

@ -1,4 +1,4 @@
CompileFlags: CompileFlags:
Add: [-Wno-unknown-attributes, -Wno-maybe-uninitialized, -Wno-unknown-warning-option] Add: [-Wno-unknown-attributes, -Wno-maybe-uninitialized, -Wno-unknown-warning-option]
Remove: [-W*, -mcall-prologues] Remove: [-W*, -mmcu=*, -mcpu=*, -mfpu=*, -mfloat-abi=*, -mno-unaligned-access, -mno-thumb-interwork, -mcall-prologues]
Compiler: clang Compiler: clang

View File

@ -25,7 +25,6 @@ def system_libs(binary: str) -> List[Path]:
"""Find the system include directory that the given build tool uses. """Find the system include directory that the given build tool uses.
""" """
cli.log.debug("searching for system library directory for binary: %s", binary) cli.log.debug("searching for system library directory for binary: %s", binary)
bin_path = shutil.which(binary)
# Actually query xxxxxx-gcc to find its include paths. # Actually query xxxxxx-gcc to find its include paths.
if binary.endswith("gcc") or binary.endswith("g++"): if binary.endswith("gcc") or binary.endswith("g++"):
@ -37,7 +36,31 @@ def system_libs(binary: str) -> List[Path]:
paths.append(Path(line.strip()).resolve()) paths.append(Path(line.strip()).resolve())
return paths return paths
return list(Path(bin_path).resolve().parent.parent.glob("*/include")) if bin_path else [] return list(Path(binary).resolve().parent.parent.glob("*/include")) if binary else []
@lru_cache(maxsize=10)
def cpu_defines(binary: str, compiler_args: str) -> List[str]:
cli.log.debug("gathering definitions for compilation: %s %s", binary, compiler_args)
if binary.endswith("gcc") or binary.endswith("g++"):
invocation = [binary, '-dM', '-E']
if binary.endswith("gcc"):
invocation.extend(['-x', 'c'])
elif binary.endswith("g++"):
invocation.extend(['-x', 'c++'])
compiler_args = shlex.split(compiler_args)
invocation.extend(compiler_args)
invocation.append('-')
result = cli.run(invocation, capture_output=True, check=True, stdin=None, input='\n')
define_args = []
for line in result.stdout.splitlines():
line_args = line.split(' ', 2)
if len(line_args) == 3 and line_args[0] == '#define':
define_args.append(f'-D{line_args[1]}={line_args[2]}')
elif len(line_args) == 2 and line_args[0] == '#define':
define_args.append(f'-D{line_args[1]}')
return list(sorted(set(define_args)))
return []
file_re = re.compile(r'printf "Compiling: ([^"]+)') file_re = re.compile(r'printf "Compiling: ([^"]+)')
@ -68,9 +91,12 @@ def parse_make_n(f: Iterator[str]) -> List[Dict[str, str]]:
# we have a hit! # we have a hit!
this_cmd = m.group(1) this_cmd = m.group(1)
args = shlex.split(this_cmd) args = shlex.split(this_cmd)
for s in system_libs(args[0]): binary = shutil.which(args[0])
compiler_args = set(filter(lambda x: x.startswith('-m') or x.startswith('-f'), args))
for s in system_libs(binary):
args += ['-isystem', '%s' % s] args += ['-isystem', '%s' % s]
new_cmd = ' '.join(shlex.quote(s) for s in args if s != '-mno-thumb-interwork') args.extend(cpu_defines(binary, ' '.join(shlex.quote(s) for s in compiler_args)))
new_cmd = ' '.join(shlex.quote(s) for s in args)
records.append({"directory": str(QMK_FIRMWARE.resolve()), "command": new_cmd, "file": this_file}) records.append({"directory": str(QMK_FIRMWARE.resolve()), "command": new_cmd, "file": this_file})
state = 'start' state = 'start'