-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build system: add compile-commands target to generate compile_commands.json #16129
Conversation
I'm using this:
... saved as "bmake" in the path, which makes use of |
I also tried |
Personally I don't like that this is writing files in the source directories instead of the binary build dir. I tend to want to avoid having any generated files mixed in with the sources. Also, this also implies that running builds for multiple platforms (native + board) will cause the compile commands to change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments on the implementation.
I did not test this, but I have a feeling that the word-splitting in Makefile approach will fail on quoted spaces, e.g. CFLAGS=-DMY_APPLICATION_DESCRIPTION="My cool IoT project"
I partially agree. But note that placing I originally intended to build them completely independent of the build process with a fake board that provides all features and performing dependency resolution for each module separately. That would result in only the include paths actually needed to be added - and to uncover missing dependencies. And it would also allow to quickly generate a With bundling the generation with the compile process anyway, it should now be possible to generate a singe
You're right. There are two easy solutions to it: a) Don't use spaces in values defined via the command line I don't think I want to handle this in a Makefile. There is IMO not really a use case that justifies the effort and option b) can be used to work around this limitation, if one really wants spaces. |
4537be4
to
77cb24b
Compare
@jnohlgard: It was impossible to generate a single So I began from scratch and now the The generation is no longer intermixed with the build. Running |
For the intended use case of code completion and linting, |
I think this is now functionally complete and reasonably well documented. For me, it works like a charm. May I squash? |
The Python linter in static tests still has some open comments. |
0af6ed9
to
8a46825
Compare
Addressed and rebased to fix the merge conflict in |
I think that my use case is also fine with something that's good enough for linting and completing, but I'm experimenting with this PR to get more precision on what I actually need. Given that all on-code comments are addressed, I wouldn't mind this being squashed. (And if something steals the time I like to take for reviewing this for practical applications, don't let a lack of follow-up from me stop this PR's progress). |
What I found I miss from the compile commands are all the Are they missed, or excluded for a reason? |
I guess they're in the generated |
They are there, but I also pluck them out to make flag decisions on the Rust side. No biggie if I have to peek into riotbuild.h for them if that's where they are going on the long run, but it's a difference in the CFLAGS I get from the environment and those I can pick from the compile-commands. |
Whoopsy! (Did this to confirm that defines with spaces now work properly)
Speaking of which:
CFLAGS += '-DTHREAD_STACKSIZE_MAIN=(THREAD_STACKSIZE_DEFAULT + 1400)'
causes shell errors for me which I haven't managed to track down, could
be related.
|
I think the reason is that flags are moved from But since the Back to actual question: Since the -DMODULE_FOO wasn't really part of the compilation command, I think it is actually better to peek into |
a031bd0
to
f23d58b
Compare
I've done some experimentation with what can be passed around how in make, I find it impossible-so-far to run something like For those reasons it's probably worth having one place in RIOT that produces clang-equivalent CFLAGS for a build. If, on the long run, we manage to do better (dunno, maybe pass |
As they haven't been cross-linked yet: Closes #16002 |
This only needs squashing? |
I actually wanted to re-write this and heavily modify the build system. But since soft feature freeze is now, I think I really favor a sub-optimal version of this rather than no version at all. But I think it makes sense to have all the info dumped by the build system in a single file, e.g. an entire file just for the compile name seems a bit wasteful and raises the bar to add more details. |
The last updated changes the following:
It is still minimally invasive into the build system, so it should be IMO possible to get this in even during soft feature freeze. |
May I squash? |
Please squash. |
760d50f
to
7ebd22a
Compare
I've run some tests with the squashed version and ran into one last issue: On native with GCC as toolchain, the compile commands contain The
In contrast, when building for an nrf52840, it shows:
|
@chrysn does your latest comments mean this PR is not ready to merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes; things worked before but now (after latest fixes and squashing) don't. I tried before to set my status to "still has open comments" but that didn't work, trying again after having self-requested a review...
Sorry, I didn't test on native. I think this should work now. I don't have 32/64 bit multlib installed, so cannot really test, tough. |
Running the tests again I ran into another issue (sorry, could have run through ignoring the first one right away): Whereas on a clean checkout
(Same for For my use cases it doesn't make much of a difference whether pkgs are in there or not (so just continuing on absence is fine, as the Makefile would have complained if files should be created but couldn't); if that works for the IDE use cases too (well, no help for pkg includes I guess, can still be added later) that'd be the easiest way around. |
Fixed. The script now will only consider folders in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage tests with bindgen pass now for all architectures I can currently test. Thanks, please squash.
By running make compile-commands a `compile_commands.json` in the RIOT base directory. With the environment variable `COMPILE_COMMANDS` the path of this file can be changed to a custom location. The `compile_commands.json` will contain the exact compile command, but as additional flag `-I/usr/$(TARGET)/include` is added to work around `clangd` not being able to locate the newlib system headers. The additional includes can be overwritten using the environment variable `COMPILE_COMMANDS_EXTRA_INCLUDES`.
d4f3078
to
a07dac9
Compare
All green. And I think this shouldn't interfere with any other stuff, so IMO this could be considered for merge during soft feature freeze. |
With Kaspar having announced the soft freeze and having thumbs-upped this, merging. [edit: and agreeing on "This does not interfere"] |
Thanks! :-) |
Is it possible to place |
The destination can actually be controlled via a Makefile variable. Typically this is used for clangd and typically one doesn't specify the path to Since placing it in RIOT's base dir works out of the box for all scenarios, this is the current default. It may actually be better for application developers (who are likely to set their application as working dir for the editor) to place it in the app dir by default, as the don't have to run |
Contribution description
By running make compile-commands a
compile_commands.json
in the RIOT basedirectory. With the environment variable
COMPILE_COMMANDS
the path ofthis file can be changed to a custom location.
The
compile_commands.json
will contain the exact compile command, butas additional flag
-I/usr/$(TARGET)/include
is added to work aroundclangd
not being able to locate the newlib system headers. Theadditional includes can be overwritten using the environment variable
COMPILE_COMMANDS_EXTRA_INCLUDES
.Testing procedure
Now, a
compile_commands.json
should be placed in$(RIOTBASE)
.Issues/PRs references
None