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

Ensure all commands in compilation_commands.json use absolute paths. #3415

Merged
merged 2 commits into from
Mar 17, 2020

Conversation

mincrmatt12
Copy link
Contributor

By placing the where_is_program call into this function, all references to the compiler will be made absolute, instead of just ones in the top environment. For example, previously all references to the compiler for user source code would not use the full path in the compilation database, which broke clangd's detection of system includes.

By placing the `where_is_program` call into this function, all references to the compiler will be made absolute, instead of just ones in the top environment. Previously, all references to the compiler for user source code would not use the full path in the compilation database, which broke `clangd`'s detection of system includes.
@CLAassistant
Copy link

CLAassistant commented Mar 13, 2020

CLA assistant check
All committers have signed the CLA.

@ivankravets
Copy link
Member

Could you provide a simple project or steps how to reproduce this issue?

@ivankravets ivankravets added this to the 4.3.0 milestone Mar 14, 2020
@mincrmatt12
Copy link
Contributor Author

Sure. To recreate the issue:

  1. Create a new project with any IDE and (for example) the megaatmega2560 board (although any board/framework I've tested has had similar results)
  2. Create an empty main.cpp file in the src folder.
  3. Create a compilation database with pio run -t compiledb

The generated file will end with an entry for src/main.cpp, and will incorrectly set the command to something like
"command": "avr-g++ -o .pio/build/megaatmega2560/src/main.cpp.o -c -fno-exceptions -fno-threadsafe-statics <...other stuff...> src/main.cpp", failing to expand the full path of avr-g++.

The rest of the entries (for library code / framework code) correctly have entries like
"command": "/root/.platformio/packages/toolchain-atmelavr/bin/avr-g++ -o .pio/build/megaatmega2560/FrameworkArduino/new.cpp.o -c -fno-exceptions -fno-threadsafe-statics <...other stuff...> /root/.platformio/packages/framework-arduino-avr/cores/arduino/new.cpp"

(the strange paths are because I did this in a docker container, but the issue still occurs outside of one)

@ivankravets ivankravets merged commit f81b0b2 into platformio:develop Mar 17, 2020
@ivankravets
Copy link
Member

Thank you so much!

@ivankravets
Copy link
Member

What is your use case for compilation_commands.json?

@mincrmatt12
Copy link
Contributor Author

I use it for completion with vim and clangd (ccls didn't work for other projects)

@ivankravets
Copy link
Member

Does it work well?

@mincrmatt12
Copy link
Contributor Author

mincrmatt12 commented Mar 17, 2020

With this patch, and the appropriate command line flags (-query-driver=/path/to/g++/in/.platformio/folder, otherwise it doesn't find the standard library headers, although it supports globs so something like -query-driver=~/.platformio/packages/**/bin/*-g++ would probably work too) it works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants