From f81b0b2a847c26bb8c180447f1cb792d03a1d5ba Mon Sep 17 00:00:00 2001 From: Matthew Mirvish Date: Tue, 17 Mar 2020 10:30:28 -0400 Subject: [PATCH] Ensure all commands in compilation_commands.json use absolute paths. (#3415) * Fix resolving of absolute path for toolchain By placing the `where_is_program` call into this function, all references to the compiler will be made absolute, instead of just ones in the top environment. Previously, all references to the compiler for user source code would not use the full path in the compilation database, which broke `clangd`'s detection of system includes. * Linting issue --- platformio/builder/tools/compilation_db.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/platformio/builder/tools/compilation_db.py b/platformio/builder/tools/compilation_db.py index 2226f825..52463e83 100644 --- a/platformio/builder/tools/compilation_db.py +++ b/platformio/builder/tools/compilation_db.py @@ -76,6 +76,16 @@ def makeEmitCompilationDbEntry(comstr): :return: target(s), source(s) """ + # Resolve absolute path of toolchain + for cmd in ("CC", "CXX", "AS"): + if cmd not in env: + continue + if os.path.isabs(env[cmd]): + continue + env[cmd] = where_is_program( + env.subst("$%s" % cmd), env.subst("${ENV['PATH']}") + ) + dbtarget = __CompilationDbNode(source) entry = env.__COMPILATIONDB_Entry( @@ -195,14 +205,6 @@ def generate(env, **kwargs): ) def CompilationDatabase(env, target): - # Resolve absolute path of toolchain - for cmd in ("CC", "CXX", "AS"): - if cmd not in env: - continue - env[cmd] = where_is_program( - env.subst("$%s" % cmd), env.subst("${ENV['PATH']}") - ) - result = env.__COMPILATIONDB_Database(target=target, source=[]) env.AlwaysBuild(result)