Skip to content

Commit

Permalink
Added a new build variable (COMPILATIONDB_INCLUDE_TOOLCHAIN) to inclu…
Browse files Browse the repository at this point in the history
…de toolchain paths in the compilation database // Resolve #3735
  • Loading branch information
ivankravets committed Apr 9, 2022
1 parent 16f5374 commit 541fcbf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ PlatformIO Core 5
- Show project dependency licenses when building in the verbose mode
- Fixed an issue when `LDF <https://docs.platformio.org/en/latest/librarymanager/ldf.html>`__ ignores the project `lib_deps <https://docs.platformio.org/en/latest/projectconf/section_env_library.html#lib-deps>`__ while resolving library dependencies (`issue #3598 <https://github.com/platformio/platformio-core/issues/3598>`_)

* **Integration**

- Added a new build variable (``COMPILATIONDB_INCLUDE_TOOLCHAIN``) to include toolchain paths in the compilation database (`issue #3735 <https://github.com/platformio/platformio-core/issues/3735>`_)
- Changed default path for compilation database `compile_commands.json <https://docs.platformio.org/en/latest/integration/compile_commands.html>`__ to the root of the project

* **Miscellaneous**

- Improved PIO Remote setup on credit-card sized computers (Raspberry Pi, BeagleBon, etc) (`issue #3865 <https://github.com/platformio/platformio-core/issues/3865>`_)
Expand Down
2 changes: 1 addition & 1 deletion docs
6 changes: 3 additions & 3 deletions platformio/builder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"piolib",
"pioupload",
"piomisc",
"pioide",
"piointegration",
"piosize",
],
toolpath=[os.path.join(fs.get_source_dir(), "builder", "tools")],
Expand All @@ -72,7 +72,7 @@
BUILD_DIR=os.path.join("$PROJECT_BUILD_DIR", "$PIOENV"),
BUILD_SRC_DIR=os.path.join("$BUILD_DIR", "src"),
BUILD_TEST_DIR=os.path.join("$BUILD_DIR", "test"),
COMPILATIONDB_PATH=os.path.join("$BUILD_DIR", "compile_commands.json"),
COMPILATIONDB_PATH=os.path.join("$PROJECT_DIR", "compile_commands.json"),
LIBPATH=["$BUILD_DIR"],
PROGNAME="program",
PROG_PATH=os.path.join("$BUILD_DIR", "$PROGNAME$PROGSUFFIX"),
Expand Down Expand Up @@ -228,7 +228,7 @@
Import("projenv")
except: # pylint: disable=bare-except
projenv = env
data = projenv.DumpIDEData(env)
data = projenv.DumpIntegrationData(env)
# dump to file for the further reading by project.helpers.load_project_ide_data
with open(
projenv.subst(os.path.join("$BUILD_DIR", "idedata.json")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@
from platformio.proc import exec_command, where_is_program


def _dump_includes(env):
includes = {}

includes["build"] = [
env.subst("$PROJECT_INCLUDE_DIR"),
env.subst("$PROJECT_SRC_DIR"),
]
includes["build"].extend(
def DumpIntegrationIncludes(env):
result = dict(build=[], compatlib=[], toolchain=[], unity=[])

result["build"].extend(
[
env.subst("$PROJECT_INCLUDE_DIR"),
env.subst("$PROJECT_SRC_DIR"),
]
)
result["build"].extend(
[os.path.abspath(env.subst(item)) for item in env.get("CPPPATH", [])]
)

# installed libs
includes["compatlib"] = []
for lb in env.GetLibBuilders():
includes["compatlib"].extend(
result["compatlib"].extend(
[os.path.abspath(inc) for inc in lb.get_include_dirs()]
)

# includes from toolchains
p = env.PioPlatform()
includes["toolchain"] = []
for pkg in p.get_installed_packages(with_optional=False):
if p.get_package_type(pkg.metadata.name) != "toolchain":
continue
Expand All @@ -56,10 +56,9 @@ def _dump_includes(env):
os.path.join(toolchain_dir, "*", "include*"),
]
for g in toolchain_incglobs:
includes["toolchain"].extend([os.path.abspath(inc) for inc in glob.glob(g)])
result["toolchain"].extend([os.path.abspath(inc) for inc in glob.glob(g)])

# include Unity framework if there are tests in project
includes["unity"] = []
auto_install_unity = False
test_dir = env.GetProjectConfig().get("platformio", "test_dir")
if os.path.isdir(test_dir) and os.listdir(test_dir) != ["README"]:
Expand All @@ -69,9 +68,9 @@ def _dump_includes(env):
auto_install=auto_install_unity,
)
if unity_dir:
includes["unity"].append(unity_dir)
result["unity"].append(unity_dir)

return includes
return result


def _get_gcc_defines(env):
Expand Down Expand Up @@ -154,14 +153,14 @@ def _subst_cmd(env, cmd):
return " ".join([SCons.Subst.quote_spaces(arg) for arg in args])


def DumpIDEData(env, globalenv):
def DumpIntegrationData(env, globalenv):
"""env here is `projenv`"""

data = {
"env_name": env["PIOENV"],
"libsource_dirs": [env.subst(item) for item in env.GetLibSourceDirs()],
"defines": _dump_defines(env),
"includes": _dump_includes(env),
"includes": env.DumpIntegrationIncludes(),
"cc_path": where_is_program(env.subst("$CC"), env.subst("${ENV['PATH']}")),
"cxx_path": where_is_program(env.subst("$CXX"), env.subst("${ENV['PATH']}")),
"gdb_path": where_is_program(env.subst("$GDB"), env.subst("${ENV['PATH']}")),
Expand Down Expand Up @@ -205,5 +204,6 @@ def exists(_):


def generate(env):
env.AddMethod(DumpIDEData)
env.AddMethod(DumpIntegrationIncludes)
env.AddMethod(DumpIntegrationData)
return env
7 changes: 7 additions & 0 deletions platformio/builder/tools/platformio.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ def _append_pio_macros():
if "__test" in COMMAND_LINE_TARGETS:
env.ConfigureTestTarget()

if "compiledb" in COMMAND_LINE_TARGETS and env.get(
"COMPILATIONDB_INCLUDE_TOOLCHAIN"
):
for scope, includes in env.DumpIntegrationIncludes().items():
if scope in ("toolchain", "unity"):
env.Append(CPPPATH=includes)


def ProcessProjectDeps(env):
project_lib_builder = env.ConfigureProjectLibBuilder()
Expand Down

0 comments on commit 541fcbf

Please sign in to comment.