Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiledb: query include paths from gcc directly. #14462

Merged
merged 4 commits into from
Sep 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/python/qmk/cli/generate/compilation_database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Creates a compilation database for the given keyboard build.
"""

import itertools
import json
import os
import re
Expand All @@ -24,6 +23,16 @@ def system_libs(binary: str) -> List[Path]:
"""
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.
if binary.endswith("gcc") or binary.endswith("g++"):
result = cli.run([binary, '-E', '-Wp,-v', '-'], capture_output=True, check=True, input='\n')
paths = []
for line in result.stderr.splitlines():
if line.startswith(" "):
paths.append(Path(line.strip()).resolve())
return paths

return list(Path(bin_path).resolve().parent.parent.glob("*/include")) if bin_path else []


Expand Down Expand Up @@ -55,7 +64,8 @@ def parse_make_n(f: Iterator[str]) -> List[Dict[str, str]]:
# we have a hit!
this_cmd = m.group(1)
args = shlex.split(this_cmd)
args += ['-I%s' % s for s in system_libs(args[0])]
for s in system_libs(args[0]):
args += ['-isystem', '%s' % s]
new_cmd = ' '.join(shlex.quote(s) for s in args if s != '-mno-thumb-interwork')
records.append({"directory": str(QMK_FIRMWARE.resolve()), "command": new_cmd, "file": this_file})
state = 'start'
Expand Down