Pass extra build flags to compiler for parsing.
Needs ReviewPublic

Authored by bungeman on Jul 2 2019, 6:00 PM.

Details

Reviewers
None
Group Reviewers
KDevelop
Summary

Passing all of the extra build flags though to the compiler detection of
includes and defines allows for flags like -nostdinc, -nostdinc++, -std=,
and --sysroot= from the build manager to override what is picked
automatically. The flags from the build manager are sanitized to those
which are known to affect includes and defines and are supported by both
clang and gcc. These sanitized flags go at the end and override any
defaults.

Test Plan

It appears difficult to test anything involving the build manager at the moment.
Let me know if it makes sense to add a TestBuildManager.

Diff Detail

Repository
R32 KDevelop
Branch
nostd (branched from master)
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 13828
Build 13846: arc lint + arc unit
bungeman created this revision.Jul 2 2019, 6:00 PM
Restricted Application added a project: KDevelop. · View Herald TranscriptJul 2 2019, 6:00 PM
Restricted Application added a subscriber: kdevelop-devel. · View Herald Transcript
bungeman requested review of this revision.Jul 2 2019, 6:00 PM
bungeman updated this revision to Diff 61040.Jul 2 2019, 10:54 PM

Work with gcc, still have a few failing tests to investigate.

aaronpuchert added inline comments.
plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
42–45 ↗(On Diff #61040)

I don't think we need this, since later options always overwrite earlier ones. So if the build system should specify the language manually (which is very unlikely, I've never seen that), and we end with something like -xc -xc++, then the latter option overrides the former and the file is read as C++. Both Clang and GCC do that:

$ clang -fsyntax-only -xc -xc++ - <<<'class X {};'
$ gcc -fsyntax-only -xc -xc++ - <<<'class X {};'
75–80 ↗(On Diff #61040)

The same applies here.

118 ↗(On Diff #61040)

This is a substantial change, and it's pretty hard to estimate the impact. I'm not sure we can just pass on all arguments without further looking into them, given what can be done with compiler arguments. This might work for some projects, but break others.

I haven't written this code (although I've worked on it), but I think that if we could just pass the build system arguments one-to-one to the libclang parser, it would have been done that way in the first place.

We'd probably be better of if we continued the whitelisting approach, unless we want to be flooded with bug reports when this hits the shelves.

bungeman updated this revision to Diff 61552.Jul 10 2019, 10:44 PM
bungeman marked 3 inline comments as done.

Moved to whitelist.

bungeman updated this revision to Diff 61553.Jul 10 2019, 10:47 PM

Remove debugging printf.

bungeman edited the summary of this revision. (Show Details)Jul 10 2019, 10:48 PM
bungeman updated this revision to Diff 62089.Jul 19 2019, 10:19 PM

Add rtti flags since they affect defines.

Overall I think this is a good idea, although we need to figure out some details. Could you either remove commented out flags or add a comment why we have them (commented out)?

plugins/custom-definesandincludes/compilerprovider/gcclikecompiler.cpp
100 ↗(On Diff #61040)

Since we pass them to the Clang parser, they need only be supported by Clang, and if supported by both compilers, they should have the same semantics.

102–103 ↗(On Diff #61040)

Clang has these two with a single dash. For GCC I can find only -nostdlib. I didn't try it though.

104 ↗(On Diff #61040)

Clang seems to have -i[[framework]with]sysroot, but not --sysroot.

110 ↗(On Diff #61040)

How does this affect includes?

116 ↗(On Diff #61040)

I haven't seen a build system set this. Why would it do that? The file type is usually inferred from the file ending, so you can just use the proper file ending.

126–127 ↗(On Diff #61040)

Some other -f flags are good candidates, e.g. -fexceptions, -fgnu-keywords, -f[no-]signed-char, -ftrigraphs, -fwritable-strings (although the latter two are perhaps not so important), or those enabling language features, like -fmodules[-ts], -fcoroutines-ts.

145–146 ↗(On Diff #61040)

Why did you break here before the brace?

I've just stumbled into a case where I would need -stdlib=libc++, which this change would solve.