From fad428651dce7584cda42c0fff809465599464d1 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Thu, 16 Sep 2021 15:31:46 +1000 Subject: [PATCH 1/4] Query include paths from gcc directly. --- lib/python/qmk/cli/generate/compilation_database.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index 2748d96e7aaa..1276a83e61c7 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -24,6 +24,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 [] From 1eae46514833fe60072819914cb29224478169b8 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Thu, 16 Sep 2021 15:50:08 +1000 Subject: [PATCH 2/4] Change to -isystem --- lib/python/qmk/cli/generate/compilation_database.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index 1276a83e61c7..4e37509a7b31 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -65,7 +65,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' From 99b6549163d675970c9a718277d63da40301e0cc Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Thu, 16 Sep 2021 16:49:27 +1000 Subject: [PATCH 3/4] qmk format-python --- lib/python/qmk/cli/generate/compilation_database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index 4e37509a7b31..c74e1c28d270 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -27,7 +27,7 @@ def system_libs(binary: str) -> List[Path]: # 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') + result = cli.run([binary, '-E', '-Wp,-v', '-'], capture_output=True, check=True, input='\n') paths = [] for line in result.stderr.splitlines(): if line.startswith(" "): From a7f3dc62215f2d8ab578f6b00f329148d0891287 Mon Sep 17 00:00:00 2001 From: Nick Brassel Date: Thu, 16 Sep 2021 16:54:46 +1000 Subject: [PATCH 4/4] tests --- lib/python/qmk/cli/generate/compilation_database.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/python/qmk/cli/generate/compilation_database.py b/lib/python/qmk/cli/generate/compilation_database.py index c74e1c28d270..602635270c66 100755 --- a/lib/python/qmk/cli/generate/compilation_database.py +++ b/lib/python/qmk/cli/generate/compilation_database.py @@ -1,7 +1,6 @@ """Creates a compilation database for the given keyboard build. """ -import itertools import json import os import re