Skip to content
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

[Feature] Generate compilation database with compilation commands #272

Open
matthijskooijman opened this issue May 2, 2018 · 8 comments
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement

Comments

@matthijskooijman
Copy link
Collaborator

It would be interesting if arduino-builder could generate a "compilation database", as a side effect of building a sketch. This is a JSON file containing the gcc commands used to compile each file in the project. Third party tools can use such a database to figure out the compilation flags used, to simplify analysis of the source code, or to easily support code completion in a third-party editor.

For docs, see http://clang.llvm.org/docs/JSONCompilationDatabase.html According to the YouCompleteMe docs, this file is customary called compilation_commands.json: https://github.com/Valloric/YouCompleteMe#option-1-use-a-compilation-database

Generating such a file is not entirely trivial, especially since files are currently compiled from a temporary directory (so the commands should probably be slightly faked using the original filenames) and because .ino files are preprocessed before being compiled (but for the purposes of completion, it might be sufficient if the flags for each .ino file can be read separatey).

This might need some further thought, but I wanted to create this issue to track any discussion around this topic.

@ghost
Copy link

ghost commented Jun 2, 2018

this would be really nice but this project seems somewhat dead?

@matthijskooijman
Copy link
Collaborator Author

Which project?

@ghost
Copy link

ghost commented Jun 3, 2018

arduino builder, last commit one year ago

edited:
ah I see, got confused by that one:
5fd49b6

@rsora rsora added the type: enhancement Proposed improvement label Sep 22, 2021
@per1234 per1234 added the topic: code Related to content of the project itself label Oct 14, 2021
@IPlayZed
Copy link

Is this feature something which is being considered to be in development? SonarLint would require this as described here and this would integrate really well with the Arduino VSCode plugin.

@matthijskooijman
Copy link
Collaborator Author

arduino-builder is no longer developed, relevant code has been moved to arduino-cli instead, and that has a basic implementation of this feature implemented already. There's still stuff left for improvement, see e.g. arduino/arduino-cli#849 (comment) for a (possibly) outdated list of some points.

@per1234
Copy link
Contributor

per1234 commented Apr 15, 2022

Thanks @matthijskooijman. What do you suggest be done with this issue?

@per1234 per1234 added the status: waiting for information More information must be provided before work can proceed label Apr 15, 2022
@matthijskooijman
Copy link
Collaborator Author

I was mostly ignoring it because arduino-builder isn't really relevant anymore, but I guess arduino-builder is actually still used in the java IDE to run the build code from arduino-cli, right? I wonder if that means that this compilation database is actually generated by the Java IDE now as well?

In any case, I guess we can close as wontfix, since any usecases that need the compilation database, like the vscode plugin suggested above, are likely going to be using arduino-cli anyway?

@per1234
Copy link
Contributor

per1234 commented Apr 15, 2022

I was mostly ignoring it because arduino-builder isn't really relevant anymore, but I guess arduino-builder is actually still used in the java IDE to run the build code from arduino-cli, right?

That is correct, so probably not quite ready to be considered irrelevant yet since it is very much in use by many people.

It is certainly not under active development, but on the other hand it doesn't need much development because at this point it is pretty much just a wrapper around Arduino CLI used to translate the arduino-builder interface.

I wonder if that means that this compilation database is actually generated by the Java IDE now as well?

It is not:

$ arduino_debug --version
Loading configuration...
Initializing packages...
Preparing boards...
Arduino: 1.8.19

$ BUILD_PATH="/tmp/arduino-build-path"

$ mkdir "$BUILD_PATH"

$ arduino_debug --verify --board arduino:avr:uno --pref build.path="$BUILD_PATH" Foo.ino
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

$ ls -1 "$BUILD_PATH"
Foo.ino.eep
Foo.ino.elf
Foo.ino.hex
Foo.ino.with_bootloader.bin
Foo.ino.with_bootloader.hex
build.options.json
core/
includes.cache
libraries/
preproc/
sketch/

The reason is because arduino-builder is missing this:
https://github.com/arduino/arduino-cli/blob/60c1c98ef90cab5fb5c278c2a33e4e4edde85fd7/commands/compile/compile.go#L153-L155

	builderCtx.CompilationDatabase = bldr.NewCompilationDatabase(
		builderCtx.BuildPath.Join("compile_commands.json"),
	)

The required change to arduino-builder:

--- a/main.go
+++ b/main.go
@@ -45,6 +45,7 @@ import (
        "syscall"

        "github.com/arduino/arduino-builder/grpc"
+       bldr "github.com/arduino/arduino-cli/arduino/builder"
        "github.com/arduino/arduino-cli/arduino/cores"
        "github.com/arduino/arduino-cli/legacy/builder"
        "github.com/arduino/arduino-cli/legacy/builder/i18n"
@@ -258,6 +259,10 @@ func main() {
                ctx.BuildPath, _ = buildPath.Abs()
        }

+       ctx.CompilationDatabase = bldr.NewCompilationDatabase(
+               ctx.BuildPath.Join("compile_commands.json"),
+       )
+
        // FLAG_BUILD_CACHE
        if *buildCachePathFlag != "" {
                buildCachePathUnquoted, err := unquote(*buildCachePathFlag)

So it seems that this issue is still not resolved. It is also arduino-builder specific and thus not appropriate for transfer to the Arduino CLI repo.

I don't feel knowledgeable enough about the subject matter to determine whether or not it should be considered "wontfix". I'll leave that decision up to you or one of the other maintainers.

@per1234 per1234 removed the status: waiting for information More information must be provided before work can proceed label Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

6 participants