diff --git a/HISTORY.rst b/HISTORY.rst index f66848c2..657a429b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -22,6 +22,8 @@ test-driven methodologies, and modern toolchains for unrivaled success. 6.1.19 (2025-??-??) ~~~~~~~~~~~~~~~~~~~ +* Fixed a regression issue where custom build flags were not properly reflected in the `compile_commands.json `__ file, ensuring accurate compilation database generation + 6.1.18 (2025-03-11) ~~~~~~~~~~~~~~~~~~~ diff --git a/platformio/builder/tools/piobuild.py b/platformio/builder/tools/piobuild.py index e1a310bd..8ef2522c 100644 --- a/platformio/builder/tools/piobuild.py +++ b/platformio/builder/tools/piobuild.py @@ -58,8 +58,8 @@ def GetBuildType(env): def BuildProgram(env): - env.ProcessCompileDbToolchainOption() env.ProcessProgramDeps() + env.ProcessCompileDbToolchainOption() env.ProcessProjectDeps() # append into the beginning a main LD script @@ -91,26 +91,6 @@ def BuildProgram(env): return program -def ProcessCompileDbToolchainOption(env): - if "compiledb" not in COMMAND_LINE_TARGETS: - return - # Resolve absolute path of toolchain - for cmd in ("CC", "CXX", "AS"): - if cmd not in env: - continue - if os.path.isabs(env[cmd]) or '"' in env[cmd]: - continue - env[cmd] = where_is_program(env.subst("$%s" % cmd), env.subst("${ENV['PATH']}")) - if " " in env[cmd]: # issue #4998: Space in compilator path - env[cmd] = f'"{env[cmd]}"' - - if env.get("COMPILATIONDB_INCLUDE_TOOLCHAIN"): - print("Warning! `COMPILATIONDB_INCLUDE_TOOLCHAIN` is scoping") - for scope, includes in env.DumpIntegrationIncludes().items(): - if scope in ("toolchain",): - env.Append(CPPPATH=includes) - - def ProcessProgramDeps(env): def _append_pio_macros(): core_version = pepver_to_semver(__version__) @@ -148,6 +128,27 @@ def ProcessProgramDeps(env): env.ProcessUnFlags(env.get("BUILD_UNFLAGS")) +def ProcessCompileDbToolchainOption(env): + if "compiledb" not in COMMAND_LINE_TARGETS: + return + + # Resolve absolute path of toolchain + for cmd in ("CC", "CXX", "AS"): + if cmd not in env: + continue + if os.path.isabs(env[cmd]) or '"' in env[cmd]: + continue + env[cmd] = where_is_program(env.subst("$%s" % cmd), env.subst("${ENV['PATH']}")) + if " " in env[cmd]: # issue #4998: Space in compilator path + env[cmd] = f'"{env[cmd]}"' + + if env.get("COMPILATIONDB_INCLUDE_TOOLCHAIN"): + print("Warning! `COMPILATIONDB_INCLUDE_TOOLCHAIN` is scoping") + for scope, includes in env.DumpIntegrationIncludes().items(): + if scope in ("toolchain",): + env.Append(CPPPATH=includes) + + def ProcessProjectDeps(env): plb = env.ConfigureProjectLibBuilder()