-
-
Notifications
You must be signed in to change notification settings - Fork 323
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
Can we export compile_commands.json
?
#3355
Comments
Hey - Yes, this would be a great feature to have in mainline SCons. Meanwhile, In the MongoDB source code, we implemented our own site_tool to do it. It is (unlike most of the rest of that codebase) Apache 2 licensed:
Relevant snippets to demonstrate usage:
The implementation could probably use some cleanup, but maybe it is close enough that we could work on getting it upstreamed someday? |
Great! |
If you close this, how does it get taken care of? Instead maybe rebrand it as a feature request? |
OK. I reopen this issue. After the feature is finished, then I close it. :-P |
Bill doesn't favor bugs which did not have discussion on the mailing list, you might want to post a note there. Personally I have never heard of this compilation-database stuff, so it might be good to explain the benefits (and how they might fit into scons). |
I'm sorry I haven't read the mailing list yet. Next time before I ask a question, I should search what I want in mailing list first. For the background about compilation database, this page describes in detail. It comes from |
Did you not see the request in the bug template that you bring your issue there first? (Or is that not working?) |
I'm sorry, but I didn't see the contents because I accidentally erased them when I entered the issue on my mobile phone. So how should we deal with this issue? Sorry again for the trouble. |
I'll mark it an enhancement. |
Thanks very much. Hope you have a good day. |
compile_commands.json
?compile_commands.json
?
We are working on Godot and are interested in getting this supported. We're speaking about scons at GodotCon and would really appreciate a discussion to implement this in the future. Can you please let us know if someone at scons could assist us? Thanks |
If you drop a comment onto the scons-dev mailing list we can see where it goes. Meanwhile, can you make use of the "external" implementation referenced above, as a proof of concept if nothing else? Since you make the third project that has some interest in this it seems like there's an audience. |
@mwichmann - We would be happy to see about upstreaming our implementation. It can surely be improved but it works for us pretty well and is reasonably fast. @RevoluPowered - the version in the MongoDB library is Apache 2 licensed so you you may well be able to just use it: https://github.com/mongodb/mongo/blob/master/site_scons/site_tools/compilation_db.py |
I would really appreciate that being upstreamed @acmorrow if that could be arranged that would be great. I'll pop a email on the scons mailinglist too when we are finished |
@acmorrow we updated the script to handle xcode and objectivec files automatically. |
@RevoluPowered @acmorrow - can you work together on a pull request. Please don't forget to update CHANGES.txt, add tests, and update docs. |
There is currently a limitation with this, which I have not solved, msvc compiler on our toolchain is not able to generate the compilation database. msvc builders seem to behave differently and not work with this custom tool. not getting any errors as such just an empty compilation database. Clang and gcc are working fine with little overhead too. (they even work fine on windows with this, seems literally just msvc which has this issue) |
@RevoluPowered - a little more information would be useful. Do you get zero output in compilation db? Can you provide a small reproducer for that? |
@RevoluPowered - Yes, more details are definitely necessary. I just tried this out locally on a VS 2019 machine in the MongoDB tree and I definitely get a populated |
@acmorrow thanks so much for your work. We also at @platformio are interested in this feature. Currently, we just copied the source file from mongo repo and modified it a little bit https://github.com/platformio/platformio-core/blob/develop/platformio/builder/tools/compilation_db.py Is it possible to make it configurable without the original source code modification? For example, to have support for Assembly files, see https://github.com/platformio/platformio-core/blob/develop/platformio/builder/tools/compilation_db.py#L170 Thanks in advance! |
I believe you possibly could do this with our version, we modified it so that objective-c files are added to the compilation database automatically on OSX, and when you do not have the tool available it will not be in the file. This change should also apply to assembly files. (I could be wrong, but it may work and worth testing). You could try this and it may just work, it might not though. |
The compilation database is useful for code browsing. The actual change is copied from SCons/scons#3355
@acmorrow what do you mean by 'some cleanup'? I tried to apply the compilation_db.py to my Scons project just like that is done in Mongo project. But I got nothing but only empty bracket in compile_commands.json. I guess I missed something. I do the same with @vmiheer's commit db616e3 except that my source tree has a slightly difference. It's like the scons command is like In addition, I added some prints to compilation_db.py for debugging so that I confirm that the compilation_db tool is triggered but no one entry is generated during the compliation. |
I have got no time to add support for this to scons. Can someone else create the PR? |
I wrote a pip package to generate compile_commands.json: https://github.com/pinetr2e/scons-compiledb It might be useful until the SCons mainline supports it or for the old version of SCons. |
All. I've started work on creating a PR based on MongoDB's latest master branch as of today. |
@ivankravets so to summarize:
Anything else? |
@bdbaddog you are right!
These changes come from our community. People use PlatformIO's Compilation database compile_commands.json for IDEs and editors. They generate |
@ivankravets - WRT assembly files, any reason to only define for static objects? (why exclude shared?) |
@bdbaddog it is our specific case, we do not use |
@ivankravets - lastly. Your copy of the code is Apache Licensed. MongoDB recently relicensed the code to MIT to make it compatible with SCons. Can you do that for your copy of compilation_db? |
I also found a more detailed answer for absolute paths => platformio/platformio-core@f81b0b2
What should be done from our side? The main reason for that code that it is compatible with Python 2 & 3. We would be happy to switch to native SCons P.S: We also plan to drop Python 2 next year. We plan to show warning to our customers soon. |
@ivankravets - I beleive if you change the license header in your copy of compilation_db.py to match what's in the current master on mongodb's repo: https://github.com/mongodb/mongo/blob/master/site_scons/site_tools/compilation_db.py#L1 That should take care of the license issue. |
Do you mean this platformio/platformio-core@099e3c7 ? |
@ivankravets - Yup. That should do it. Thanks! |
FYI - I'm working on a pull request for this now. |
@ivankravets - thus far I've added an env variable to enable/disable absolute paths for target/source. I'm not sure if doing the same for tools is safe as if the path has a space in it, that can cause issues with the current logic which spawns processes. For tools (cc,cxx,as) it seems like if the user want absolute paths to them they should do that outside of the CompilationDatabase().. Thoughts? |
@bdbaddog I think you are right. SCons is neutral to any toolchain and end-user or integrator is responsible for PATH or full resolving. We can do the next on our side when the user calls
|
@ivankravets - o.k. in that case I'll push a PR today. Tests and docs not yet complete, but perhaps you can give the code a try? |
@bdbaddog, sorry for the delay. I've finally got time to switch PlatformIO to your SCons dev-version. A default I see generated JSON but a path to compiler is not absolute. [
{
"command": "avr-g++ -o /private/tmp/pio-workspaces/wiring-blink-632516cf26/build/uno/FrameworkArduino/CDC.cpp.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -DPLATFORMIO=40304 -DARDUINO_AVR_UNO -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=10808 -I/Users/ikravets/.platformio/packages/framework-arduino-avr/cores/arduino -I/Users/ikravets/.platformio/packages/framework-arduino-avr/variants/standard /Users/ikravets/.platformio/packages/framework-arduino-avr/cores/arduino/CDC.cpp",
"directory": "/Users/ikravets/Projects/PlatformIO/Development/core/examples/wiring-blink",
"file": "/private/tmp/pio-workspaces/wiring-blink-632516cf26/build/uno/FrameworkArduino/CDC.cpp",
"target": "/private/tmp/pio-workspaces/wiring-blink-632516cf26/build/uno/FrameworkArduino/CDC.cpp.o"
},
{
"command": "avr-g++ -o /private/tmp/pio-workspaces/wiring-blink-632516cf26/build/uno/FrameworkArduino/HardwareSerial.cpp.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -DPLATFORMIO=40304 -DARDUINO_AVR_UNO -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=10808 -I/Users/ikravets/.platformio/packages/framework-arduino-avr/cores/arduino -I/Users/ikravets/.platformio/packages/framework-arduino-avr/variants/standard /Users/ikravets/.platformio/packages/framework-arduino-avr/cores/arduino/HardwareSerial.cpp",
"directory": "/Users/ikravets/Projects/PlatformIO/Development/core/examples/wiring-blink",
"file": "/private/tmp/pio-workspaces/wiring-blink-632516cf26/build/uno/FrameworkArduino/HardwareSerial.cpp",
"target": "/private/tmp/pio-workspaces/wiring-blink-632516cf26/build/uno/FrameworkArduino/HardwareSerial.cpp.o"
},
{
"command": "avr-g++ -o /private/tmp/pio-workspaces/wiring-blink-632516cf26/build/uno/FrameworkArduino/HardwareSerial0.cpp.o -c -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++11 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega328p -DPLATFORMIO=40304 -DARDUINO_AVR_UNO -DF_CPU=16000000L -DARDUINO_ARCH_AVR -DARDUINO=10808 -I/Users/ikravets/.platformio/packages/framework-arduino-avr/cores/arduino -I/Users/ikravets/.platformio/packages/framework-arduino-avr/variants/standard /Users/ikravets/.platformio/packages/framework-arduino-avr/cores/arduino/HardwareSerial0.cpp",
"directory": "/Users/ikravets/Projects/PlatformIO/Development/core/examples/wiring-blink",
"file": "/private/tmp/pio-workspaces/wiring-blink-632516cf26/build/uno/FrameworkArduino/HardwareSerial0.cpp",
"target": "/private/tmp/pio-workspaces/wiring-blink-632516cf26/build/uno/FrameworkArduino/HardwareSerial0.cpp.o"
}
]
|
@ivankravets - re tool abs path. As we discussed above. Exercise left for user. Actually would have been better to comment on the Pull request.. #3662 |
Add compilation db for use by clang tools and cquery (fix issue #3355)
It is convenient for me to use
cquery
withcompile_commands.json
. It works quiet well for most of the c++ projects.CMAKE_EXPORT_COMPILE_COMMANDS
option to exportcompile_commands.json
compile_commands.json
So can we export
compile_commands.json
when usingSCons
? Thank you very much!The text was updated successfully, but these errors were encountered: