Skip to content

Commit

Permalink
Ensure all commands in compilation_commands.json use absolute paths. (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
mincrmatt12 authored Mar 17, 2020
1 parent 314f634 commit f81b0b2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions platformio/builder/tools/compilation_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ def EmitCompilationDbEntry(target, source, env):
: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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f81b0b2

Please sign in to comment.