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

Compilation database support - clang, gcc, mingw #32848

Conversation

RevoluPowered
Copy link
Contributor

@RevoluPowered RevoluPowered commented Oct 15, 2019

This file is from mongodb and the tooling Automatically generates the compilation database across all platforms.

Thanks to acmarrow for a simple solution

SCons/scons#3355

For the uninitiated this supports IDE symbol lookup, refactoring tools, documentation tools:
This means we can support intelisense style technologies with reliable type lookup.

For example:

Known issue:

  • no support for msvc compiler

Co-authored-by: K. S. Ernest (iFire) Lee [email protected]

@RevoluPowered RevoluPowered force-pushed the feature/compilation-database-support branch 3 times, most recently from 229db45 to 628f8c2 Compare October 15, 2019 09:38
@RevoluPowered
Copy link
Contributor Author

Python 2.7 justification for upgrade:

  • Python 2.7 is going to be depreciated very soon in scons. (next release)

Scons would not build without this update with the compilation db on windows, due to a bug they have not fixed.

Simplifies osx path code.

Updated platform install to use sudo to install scons to prevent us having to modify path.

Since the VM image is thrown away this doesn't matter.

.travis.yml Outdated Show resolved Hide resolved
@IAmActuallyCthulhu
Copy link
Contributor

I have tested it on macOS (10.14.6) with CLion (2019.2.4).

While testing I found one issue, Objective-C files found in /platform/osx are not recorded to the compilation database.

CLion error message

I was able to fix it (quick and dirty) by adding , '.mm' to the _CXXSuffixes array.

https://github.com/godotengine/godot/blob/fb8bb2dcd4db1ece6bb25aabd52837b2f363b984/site_scons/site_tools/compilation_db.py#L39


P.S. Thank you @RevoluPowered and @fire for making this PR. I am incredibly grateful, happy, and overall ecstatic to have this.

@Calinou Calinou changed the title Compilation database support acrosss all platforms [needs testing] Compilation database support acrosss all platforms Oct 20, 2019
@IAmActuallyCthulhu
Copy link
Contributor

IAmActuallyCthulhu commented Oct 20, 2019

I have tested it on macOS (10.14.6) with VSCode.

VSCode detected the compile_commands.json and generated the config c_cpp_properties.json. There are no false positives anymore!

However, same Objective-C issues as explained in #32848 (comment).

image

Side Note: I do not know if the generated c_cpp_properties.json file is correct or needs manual changes.

@RevoluPowered
Copy link
Contributor Author

RevoluPowered commented Oct 21, 2019

Hello, I will update the PR tomorrow as we are all returning from GodotCon

Thanks everyone for testing I will merge the objective c support too :)

.travis.yml Outdated Show resolved Hide resolved
.travis.yml Outdated Show resolved Hide resolved
@RevoluPowered RevoluPowered requested a review from Calinou October 21, 2019 21:10
@RevoluPowered RevoluPowered force-pushed the feature/compilation-database-support branch from 887b8ab to 90a1b61 Compare October 22, 2019 11:53
@RevoluPowered
Copy link
Contributor Author

not got access to apple hw, will delay this until tomorrow

@Chaosus Chaosus added this to the 4.0 milestone Oct 26, 2019
@RevoluPowered RevoluPowered force-pushed the feature/compilation-database-support branch from 1c10fe9 to f0ea6c7 Compare November 2, 2019 12:58
@RevoluPowered
Copy link
Contributor Author

RevoluPowered commented Nov 2, 2019

@IAmActuallyCthulhu updated the suffixes properly so should be platform agnostic now

Adding the method to the cxxsuffix as requested would have broken it on windows, so I have made it retrieve this directly from scons, on osx it will make it available and linux, but on windows it will not as this made appveyor break.

@RevoluPowered RevoluPowered force-pushed the feature/compilation-database-support branch from 251b4e4 to 6225d69 Compare November 2, 2019 14:31
@fire fire changed the title Compilation database support acrosss all platforms Compilation database support across all platforms Nov 18, 2019
@Xrayez
Copy link
Contributor

Xrayez commented Jan 9, 2020

Doesn't seem to work on Windows, VS2017, Python 3.6.4, Scons v3.0.5.

[ 96%] Building compilation database compile_commands.json
...
[100%] scons: done building targets.

It simply produces an empty array in compile_commands.json.

scons platform=windows tools=yes target=release_debug bits=64 -j8

Same thing with target=debug debug_symbols=yes.

@RevoluPowered
Copy link
Contributor Author

Doesn't seem to work on Windows, VS2017, Python 3.6.4, Scons v3.0.5.

[ 96%] Building compilation database compile_commands.json
...
[100%] scons: done building targets.

It simply produces an empty array in compile_commands.json.

scons platform=windows tools=yes target=release_debug bits=64 -j8

Same thing with target=debug debug_symbols=yes.

This will only work with scons 3.1.1 the stable release

@RevoluPowered
Copy link
Contributor Author

RevoluPowered commented Jan 16, 2020

vscode currently requires us to reload this compilation_db file manually, I think I can update the behaviour so that vscode just sees this as a file modification rather than the file being unreadable during write.

temp solution is that you can just do Ctrl + Shift + P then run 'Reload window' after a build.

This happens instantly on my computer so it's not a huge priority IMO.

CLion has no issues with this which I can see.

@Calinou Calinou removed their request for review January 21, 2020 00:11
@Thorhian
Copy link

Hi RevoluPowered! I also wanted to suggest adding "compile_commands.json" to the .gitignore file for the project as well. That wouldn't cause any unwanted side effects, would it?

@RevoluPowered
Copy link
Contributor Author

Hi RevoluPowered! I also wanted to suggest adding "compile_commands.json" to the .gitignore file for the project as well. That wouldn't cause any unwanted side effects, would it?

Good suggestion I will test this and see what happens

@clayjohn
Copy link
Member

I have the same issue as Xrayez. I am using Windows 10 and I have scons version 3.1.1 installed. The compilation database just contains an empty array.

@clayjohn
Copy link
Member

Thanks for all your work :)

I plan on running MinGW periodically to update my compilation database in the meantime.

@RevoluPowered
Copy link
Contributor Author

RevoluPowered commented Feb 11, 2020

Thanks for all your work :)

I plan on running MinGW periodically to update my compilation database in the meantime.

Ach, can only take a minor part of credit, was team effort between @fire and I :)

also, acmarrow from mongodb :) and mongodb themselves

@RevoluPowered RevoluPowered reopened this Apr 19, 2020
@RevoluPowered RevoluPowered force-pushed the feature/compilation-database-support branch from e737ace to 11ccf96 Compare April 19, 2020 19:56
@RevoluPowered RevoluPowered changed the title Compilation database support across all platforms Compilation database support - clang, gcc, mingw Apr 19, 2020
This tool is originally from mongodb.

- Updated CPPSUFFIXES to use scons suffixes
- objective-c files will also be loaded into the compilation database where the compiler / tooling is available to compile the files.

Known limitations:

- This will not work with msvc as your compiler.
@akien-mga akien-mga force-pushed the feature/compilation-database-support branch from 11ccf96 to 5a6f275 Compare May 12, 2020 11:08
@akien-mga
Copy link
Member

Force pushed an amend that fixes Python style issues (we now use black for formatting), and moves the script to misc/scons/site_tools as I found a workaround to override the default site_scons path. (Basically reimplementing what SCons' --site-dir command line option would do by using a private method - Thanks Python for not having real private methods :P).

@akien-mga akien-mga added cherrypick:3.x Considered for cherry-picking into a future 3.x release and removed needs testing labels May 12, 2020
@akien-mga akien-mga merged commit 561438c into godotengine:master May 12, 2020
@akien-mga
Copy link
Member

Thanks!

@RevoluPowered
Copy link
Contributor Author

Thanks for your help merging I had little time to pull away from FBX. That's great I am so happy, I use this regularly! <3

@Faless
Copy link
Collaborator

Faless commented May 12, 2020

Getting the following error after this merge:

[ 98%] scons: done building targets.
TypeError: changed_since_last_build_node() missing 1 required positional argument: 'node':
  File "/usr/lib/scons/SCons/Script/Main.py", line 1376:
    _exec_main(parser, values)
  File "/usr/lib/scons/SCons/Script/Main.py", line 1339:
    _main(parser)
  File "/usr/lib/scons/SCons/Script/Main.py", line 1103:
    nodes = _build_targets(fs, options, targets, target_top)
  File "/usr/lib/scons/SCons/Script/Main.py", line 1313:
    jobs.run(postfunc = jobs_postfunc)
  File "/usr/lib/scons/SCons/Job.py", line 111:
    self.job.start()
  File "/usr/lib/scons/SCons/Job.py", line 423:
    task.executed()
  File "/usr/lib/scons/SCons/Script/Main.py", line 237:
    SCons.Taskmaster.OutOfDateTask.executed(self)
  File "/usr/lib/scons/SCons/Taskmaster.py", line 317:
    t.release_target_info()
  File "/usr/lib/scons/SCons/Node/FS.py", line 2980:
    self.changed(allowcache=True)
  File "/usr/lib/scons/SCons/Node/FS.py", line 3223:
    has_changed = SCons.Node.Node.changed(self, node)
  File "/usr/lib/scons/SCons/Node/__init__.py", line 1455:
    if _decider_map[child.changed_since_last_build](child, self, prev_ni):

Tested with both pip version:

SCons by Steven Knight et al.:
	script: v3.1.2.bee7caf9defd6e108fc2998a2520ddb36a967691, 2019-12-17 02:07:09, by bdeegan on octodog
	engine: v3.1.2.bee7caf9defd6e108fc2998a2520ddb36a967691, 2019-12-17 02:07:09, by bdeegan on octodog

and distro version:

SCons by Steven Knight et al.:
	script: v3.0.1.74b2c53bc42290e911b334a6b44f187da698a668, 2017/11/14 13:16:53, by bdbaddog on hpmicrodog
	engine: v3.0.1.74b2c53bc42290e911b334a6b44f187da698a668, 2017/11/14 13:16:53, by bdbaddog on hpmicrodog

@akien-mga
Copy link
Member

@Faless The backtrace is from your distro version (/usr/lib/scons), so make sure that the pip version is not using the wrong SCons lib from the distro.

@akien-mga
Copy link
Member

We should likely increase EnsureSConsVersion to the version needed for the compile DB, or alternatively disable generation of the compile DB on older SCons versions (might be more user-friendly).

@Faless
Copy link
Collaborator

Faless commented May 12, 2020

@akien-mga right, my bash alias tricked me -.- . It works with the pip version, so yeah, scons 3.0.1 doesn't seem to work, scons 3.1.2 is fine.

akien-mga added a commit to akien-mga/godot that referenced this pull request May 18, 2020
There's a builtin `toolpath` option we can use for that, so no need to hack
around a custom `scons_site` path.

The script requires SCons 3.1.1 or later, so we enable it conditionally.

Follow-up to godotengine#32848.
@akien-mga
Copy link
Member

Cherry-picked for 3.2.2. (Together with #38830 to fix build on older SCons versions.)

@akien-mga akien-mga removed the cherrypick:3.x Considered for cherry-picking into a future 3.x release label May 18, 2020
akien-mga added a commit to akien-mga/godot that referenced this pull request May 18, 2020
There's a builtin `toolpath` option we can use for that, so no need to hack
around a custom `scons_site` path.

The script requires SCons 3.1.1 or later, so we enable it conditionally.

Follow-up to godotengine#32848.

(cherry picked from commit 22c718a)
huhund pushed a commit to huhund/godot that referenced this pull request Nov 10, 2020
There's a builtin `toolpath` option we can use for that, so no need to hack
around a custom `scons_site` path.

The script requires SCons 3.1.1 or later, so we enable it conditionally.

Follow-up to godotengine#32848.

(cherry picked from commit 22c718a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.