Bug 15147 - Feature request: Make devtool create compile_commands.json files for clangd
Summary: Feature request: Make devtool create compile_commands.json files for clangd
Status: NEW
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: devtools / tool chain (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Medium enhancement
Target Milestone: 5.99
Assignee: Unassigned
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2023-06-20 08:36 UTC by Jan Claussen
Modified: 2026-08-12 19:12 UTC (History)
4 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Yes (doc changes required)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Claussen 2023-06-20 08:36:38 UTC
This feature would be great for developers that rely on clangd or use Vim as their main development environment. Usually after running make you can create a compile_commands.json file using bear or compiledb

https://github.com/rizsotto/Bear
https://github.com/nickdiego/compiledb

The kernel also provides its own script for this

https://github.com/torvalds/linux/blob/master/scripts/clang-tools/gen_compile_commands.py

and CMake supports it as well

https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

The problem is that in order to get these commands, the code have been fully built, so the location of all libraries are known. It is easy to do this manually for small applications. Just check out the workspace with devtool, source the toolchain, compile and generate the compile_commands.json. For more complex programs like the kernel, which can need defconfig and .scc files etc. from the meta-layer, this can get quite complex. 

So it would be nice if this could be automated by devtool somehow. Bitbake knows where all the libraries and config files are located and with its help the compile_commands.json could be generated and copied into the workspace.
Comment 1 Randy MacLeod 2023-06-22 14:35:40 UTC
An interesting idea but rather specific to the tools involved. Nice to have but not urgent.
Comment 2 Jan Claussen 2023-07-06 11:50:39 UTC
Sure, this has no priority. I would try implementing it myself if you could give me some ideas where to start off. I tried playing around with the make command in the do_compile.log, but did not have any success. 

I think it would also be good to do this with an installed SDK and use its headers, because afaik otherwise the workdirs are being cleaned up after a package is successfully built and with it all the header files, aren't they?
Comment 3 Randy MacLeod 2023-10-24 14:24:21 UTC
Bulk move from 4.99 or 0.00 to 5.99
Comment 4 Adrian Freihofer 2026-08-12 19:12:06 UTC
This is solved for some use cases. meson always did that by default. cmake does this as well since a few Yocto releases: https://git.openembedded.org/openembedded-core/tree/meta/classes-recipe/cmake.bbclass#n261.

This leads to the question if devtool is the best place for this feature. Probably not, because devtool should be needed to setup the SDK and then the build-tool should provide what ever is needed for the development workflow, just what meson and cmake do.