Differential D8634 Diff 22980 plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp
Changeset View
Changeset View
Standalone View
Standalone View
plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp
Show All 28 Lines | |||||
29 | 29 | | |||
30 | #include <KConfig> | 30 | #include <KConfig> | ||
31 | #include <KConfigGroup> | 31 | #include <KConfigGroup> | ||
32 | 32 | | |||
33 | #include <interfaces/iproject.h> | 33 | #include <interfaces/iproject.h> | ||
34 | #include <interfaces/icore.h> | 34 | #include <interfaces/icore.h> | ||
35 | #include <project/projectmodel.h> | 35 | #include <project/projectmodel.h> | ||
36 | 36 | | |||
37 | #include <algorithm> | ||||
38 | | ||||
37 | #include "compilerprovider.h" | 39 | #include "compilerprovider.h" | ||
38 | 40 | | |||
39 | using namespace KDevelop; | 41 | using namespace KDevelop; | ||
40 | 42 | | |||
41 | namespace { | 43 | namespace { | ||
44 | constexpr Utils::LanguageType configurableLanguageTypes[] = | ||||
mwolff: make this const | |||||
aaronpuchert: Maybe even constexpr? | |||||
45 | { Utils::C, Utils::Cpp, Utils::OpenCl, Utils::Cuda }; | ||||
46 | | ||||
42 | namespace ConfigConstants { | 47 | namespace ConfigConstants { | ||
43 | const QString configKey = QStringLiteral( "CustomDefinesAndIncludes" ); | 48 | const QString configKey = QStringLiteral( "CustomDefinesAndIncludes" ); | ||
44 | const QString definesKey = QStringLiteral( "Defines" ); | 49 | const QString definesKey = QStringLiteral( "Defines" ); | ||
45 | const QString includesKey = QStringLiteral( "Includes" ); | 50 | const QString includesKey = QStringLiteral( "Includes" ); | ||
46 | const QString projectPathPrefix = QStringLiteral( "ProjectPath" ); | 51 | const QString projectPathPrefix = QStringLiteral( "ProjectPath" ); | ||
47 | const QString projectPathKey = QStringLiteral( "Path" ); | 52 | const QString projectPathKey = QStringLiteral( "Path" ); | ||
48 | 53 | | |||
49 | const QString customBuildSystemGroup = QStringLiteral( "CustomBuildSystem" ); | 54 | const QString customBuildSystemGroup = QStringLiteral( "CustomBuildSystem" ); | ||
50 | const QString definesAndIncludesGroup = QStringLiteral( "Defines And Includes" ); | 55 | const QString definesAndIncludesGroup = QStringLiteral( "Defines And Includes" ); | ||
51 | 56 | | |||
52 | const QString compilersGroup = QStringLiteral( "Compilers" ); | 57 | const QString compilersGroup = QStringLiteral( "Compilers" ); | ||
53 | const QString compilerNameKey = QStringLiteral( "Name" ); | 58 | const QString compilerNameKey = QStringLiteral( "Name" ); | ||
54 | const QString compilerPathKey = QStringLiteral( "Path" ); | 59 | const QString compilerPathKey = QStringLiteral( "Path" ); | ||
55 | const QString compilerTypeKey = QStringLiteral( "Type" ); | 60 | const QString compilerTypeKey = QStringLiteral( "Type" ); | ||
56 | 61 | | |||
57 | QString parserArgumentsCPP() | 62 | QString parserArgumentsKey(Utils::LanguageType languageType) | ||
mwolff: rename to `configKey` or such? | |||||
That's already used in line 45. I could name it parserArgumentsKey. aaronpuchert: That's already used in line 45. I could name it `parserArgumentsKey`. | |||||
58 | { | 63 | { | ||
64 | switch (languageType) { | ||||
65 | case Utils::C: | ||||
66 | return QStringLiteral("parserArgumentsC"); | ||||
67 | case Utils::Cpp: | ||||
59 | return QStringLiteral("parserArguments"); | 68 | return QStringLiteral("parserArguments"); | ||
69 | case Utils::OpenCl: | ||||
70 | return QStringLiteral("parserArgumentsOpenCL"); | ||||
71 | case Utils::Cuda: | ||||
72 | return QStringLiteral("parserArgumentsCuda"); | ||||
73 | default: | ||||
make this Utils::Other, such that we get a compile warning when we extend the enum later mwolff: make this Utils::Other, such that we get a compile warning when we extend the enum later | |||||
74 | Q_UNREACHABLE(); | ||||
60 | } | 75 | } | ||
61 | | ||||
62 | QString parserArgumentsC() | | |||
63 | { | | |||
64 | return QStringLiteral("parserArgumentsC"); | | |||
65 | } | 76 | } | ||
66 | 77 | | |||
67 | QString parseAmbiguousAsCPP() | 78 | QString parseAmbiguousAsCPP() | ||
68 | { | 79 | { | ||
69 | return QStringLiteral("parseAmbiguousAsCPP"); | 80 | return QStringLiteral("parseAmbiguousAsCPP"); | ||
70 | } | 81 | } | ||
71 | } | 82 | } | ||
move this down, such that the anon namespace includes all util functions, esp. the ones you are touching. mwolff: move this down, such that the anon namespace includes all util functions, esp. the ones you are… | |||||
This closes the ConfigConstants namespace, so I guess I'm going to leave it there. The anonymous namespace is closed on line 266. aaronpuchert: This closes the `ConfigConstants` namespace, so I guess I'm going to leave it there.
The… | |||||
72 | 83 | | |||
73 | // the grouplist is randomly sorted b/c it uses QSet internally | 84 | // the grouplist is randomly sorted b/c it uses QSet internally | ||
74 | // we sort the keys here, as the structure is properly defined for us | 85 | // we sort the keys here, as the structure is properly defined for us | ||
75 | QStringList sorted(QStringList list) | 86 | QStringList sorted(QStringList list) | ||
76 | { | 87 | { | ||
77 | std::sort(list.begin(), list.end()); | 88 | std::sort(list.begin(), list.end()); | ||
78 | return list; | 89 | return list; | ||
79 | } | 90 | } | ||
80 | 91 | | |||
81 | ParserArguments defaultArguments() | 92 | ParserArguments createDefaultArguments() | ||
82 | { | 93 | { | ||
83 | const static ParserArguments arguments{ | 94 | ParserArguments arguments; | ||
84 | QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c99"), | 95 | arguments[Utils::C] = QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c99"); | ||
85 | QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11"), | 96 | arguments[Utils::Cpp] = QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11"); | ||
86 | QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=CL1.1"), | 97 | arguments[Utils::OpenCl] = QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -cl-std=CL1.1"); | ||
87 | QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11"), | 98 | arguments[Utils::Cuda] = QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11"); | ||
88 | true | 99 | arguments[Utils::ObjC] = QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c99"); | ||
89 | }; | 100 | arguments.parseAmbiguousAsCPP = true; | ||
101 | | ||||
102 | return arguments; | ||||
103 | } | ||||
90 | 104 | | |||
105 | const ParserArguments& defaultArguments() | ||||
106 | { | ||||
107 | static ParserArguments arguments = createDefaultArguments(); | ||||
91 | return arguments; | 108 | return arguments; | ||
92 | } | 109 | } | ||
93 | 110 | | |||
94 | CompilerPointer createCompilerFromConfig(KConfigGroup& cfg) | 111 | CompilerPointer createCompilerFromConfig(KConfigGroup& cfg) | ||
95 | { | 112 | { | ||
96 | auto grp = cfg.group("Compiler"); | 113 | auto grp = cfg.group("Compiler"); | ||
97 | auto name = grp.readEntry( ConfigConstants::compilerNameKey, QString() ); | 114 | auto name = grp.readEntry( ConfigConstants::compilerNameKey, QString() ); | ||
98 | if (name.isEmpty()) { | 115 | if (name.isEmpty()) { | ||
Show All 20 Lines | |||||
119 | } | 136 | } | ||
120 | 137 | | |||
121 | void doWriteSettings( KConfigGroup grp, const QVector<ConfigEntry>& paths ) | 138 | void doWriteSettings( KConfigGroup grp, const QVector<ConfigEntry>& paths ) | ||
122 | { | 139 | { | ||
123 | int pathIndex = 0; | 140 | int pathIndex = 0; | ||
124 | for ( const auto& path : paths ) { | 141 | for ( const auto& path : paths ) { | ||
125 | KConfigGroup pathgrp = grp.group( ConfigConstants::projectPathPrefix + QString::number( pathIndex++ ) ); | 142 | KConfigGroup pathgrp = grp.group( ConfigConstants::projectPathPrefix + QString::number( pathIndex++ ) ); | ||
126 | pathgrp.writeEntry(ConfigConstants::projectPathKey, path.path); | 143 | pathgrp.writeEntry(ConfigConstants::projectPathKey, path.path); | ||
127 | pathgrp.writeEntry(ConfigConstants::parserArgumentsCPP(), path.parserArguments.cppArguments); | 144 | for (Utils::LanguageType type : configurableLanguageTypes) { | ||
mwolff: auto? | |||||
128 | pathgrp.writeEntry(ConfigConstants::parserArgumentsC(), path.parserArguments.cArguments); | 145 | pathgrp.writeEntry(ConfigConstants::parserArgumentsKey(type), path.parserArguments[type]); | ||
146 | } | ||||
mwolff: add braces please | |||||
129 | pathgrp.writeEntry(ConfigConstants::parseAmbiguousAsCPP(), path.parserArguments.parseAmbiguousAsCPP); | 147 | pathgrp.writeEntry(ConfigConstants::parseAmbiguousAsCPP(), path.parserArguments.parseAmbiguousAsCPP); | ||
130 | 148 | | |||
131 | { | 149 | { | ||
132 | int index = 0; | 150 | int index = 0; | ||
133 | KConfigGroup includes(pathgrp.group(ConfigConstants::includesKey)); | 151 | KConfigGroup includes(pathgrp.group(ConfigConstants::includesKey)); | ||
134 | for( auto it = path.includes.begin() ; it != path.includes.end(); ++it){ | 152 | for( auto it = path.includes.begin() ; it != path.includes.end(); ++it){ | ||
135 | includes.writeEntry(QString::number(++index), *it); | 153 | includes.writeEntry(QString::number(++index), *it); | ||
136 | } | 154 | } | ||
Show All 15 Lines | 169 | { | |||
152 | QVector<ConfigEntry> paths; | 170 | QVector<ConfigEntry> paths; | ||
153 | for( const QString &grpName : sorted(grp.groupList()) ) { | 171 | for( const QString &grpName : sorted(grp.groupList()) ) { | ||
154 | if ( !grpName.startsWith( ConfigConstants::projectPathPrefix ) ) { | 172 | if ( !grpName.startsWith( ConfigConstants::projectPathPrefix ) ) { | ||
155 | continue; | 173 | continue; | ||
156 | } | 174 | } | ||
157 | KConfigGroup pathgrp = grp.group( grpName ); | 175 | KConfigGroup pathgrp = grp.group( grpName ); | ||
158 | 176 | | |||
159 | ConfigEntry path; | 177 | ConfigEntry path; | ||
160 | path.path = pathgrp.readEntry( ConfigConstants::projectPathKey, "" ); | 178 | path.path = pathgrp.readEntry( ConfigConstants::projectPathKey, "" ); | ||
161 | path.parserArguments.cppArguments = pathgrp.readEntry(ConfigConstants::parserArgumentsCPP(), defaultArguments().cppArguments); | 179 | for (Utils::LanguageType type : configurableLanguageTypes) { | ||
mwolff: dito | |||||
mwolff: auto? | |||||
162 | path.parserArguments.cArguments = pathgrp.readEntry(ConfigConstants::parserArgumentsC(), defaultArguments().cArguments); | 180 | path.parserArguments[type] = pathgrp.readEntry(ConfigConstants::parserArgumentsKey(type), defaultArguments()[type]); | ||
181 | } | ||||
163 | path.parserArguments.parseAmbiguousAsCPP = pathgrp.readEntry(ConfigConstants::parseAmbiguousAsCPP(), defaultArguments().parseAmbiguousAsCPP); | 182 | path.parserArguments.parseAmbiguousAsCPP = pathgrp.readEntry(ConfigConstants::parseAmbiguousAsCPP(), defaultArguments().parseAmbiguousAsCPP); | ||
164 | 183 | | |||
165 | if (path.parserArguments.cppArguments.isEmpty()) { | 184 | for (Utils::LanguageType type : configurableLanguageTypes) { | ||
mwolff: auto? | |||||
166 | path.parserArguments.cppArguments = defaultArguments().cppArguments; | 185 | if (path.parserArguments[type].isEmpty()) { | ||
186 | path.parserArguments[type] = defaultArguments()[type]; | ||||
167 | } | 187 | } | ||
168 | | ||||
169 | if (path.parserArguments.cArguments.isEmpty()) { | | |||
170 | path.parserArguments.cArguments = defaultArguments().cArguments; | | |||
171 | } | 188 | } | ||
172 | 189 | | |||
173 | { // defines | 190 | { // defines | ||
174 | // Backwards compatibility with old config style | 191 | // Backwards compatibility with old config style | ||
175 | if(pathgrp.hasKey(ConfigConstants::definesKey)) { | 192 | if(pathgrp.hasKey(ConfigConstants::definesKey)) { | ||
176 | QByteArray tmp = pathgrp.readEntry( ConfigConstants::definesKey, QByteArray() ); | 193 | QByteArray tmp = pathgrp.readEntry( ConfigConstants::definesKey, QByteArray() ); | ||
177 | QDataStream s( tmp ); | 194 | QDataStream s( tmp ); | ||
178 | s.setVersion( QDataStream::Qt_4_5 ); | 195 | s.setVersion( QDataStream::Qt_4_5 ); | ||
Show All 39 Lines | |||||
218 | } | 235 | } | ||
219 | 236 | | |||
220 | path.compiler = createCompilerFromConfig(pathgrp); | 237 | path.compiler = createCompilerFromConfig(pathgrp); | ||
221 | 238 | | |||
222 | if ( remove ) { | 239 | if ( remove ) { | ||
223 | pathgrp.deleteGroup(); | 240 | pathgrp.deleteGroup(); | ||
224 | } | 241 | } | ||
225 | 242 | | |||
226 | Q_ASSERT(!path.parserArguments.cppArguments.isEmpty()); | 243 | Q_ASSERT(!path.parserArguments.isAnyEmpty()); | ||
227 | Q_ASSERT(!path.parserArguments.cArguments.isEmpty()); | | |||
228 | paths << path; | 244 | paths << path; | ||
229 | } | 245 | } | ||
230 | 246 | | |||
231 | return paths; | 247 | return paths; | ||
232 | } | 248 | } | ||
233 | 249 | | |||
234 | /** | 250 | /** | ||
235 | * Reads and converts paths from old (Custom Build System's) format to the current one. | 251 | * Reads and converts paths from old (Custom Build System's) format to the current one. | ||
▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Line(s) | 432 | if (mimeType == QStringLiteral("text/x-c++src") || | |||
417 | mimeType == QStringLiteral("text/x-c++hdr") ) { | 433 | mimeType == QStringLiteral("text/x-c++hdr") ) { | ||
418 | return Cpp; | 434 | return Cpp; | ||
419 | } | 435 | } | ||
420 | 436 | | |||
421 | if (mimeType == QStringLiteral("text/x-objcsrc")) { | 437 | if (mimeType == QStringLiteral("text/x-objcsrc")) { | ||
422 | return ObjC; | 438 | return ObjC; | ||
423 | } | 439 | } | ||
424 | 440 | | |||
425 | if (mimeType == QStringLiteral("text/x-opencl-src")) { | 441 | if (mimeType == QStringLiteral("text/x-opencl-src")) { | ||
mwolff: this should probably be a separate patch | |||||
Done. aaronpuchert: [Done](https://phabricator.kde.org/D8644). | |||||
426 | return OpenCl; | 442 | return OpenCl; | ||
427 | } | 443 | } | ||
428 | 444 | | |||
429 | return Other; | 445 | return Other; | ||
430 | } | 446 | } | ||
431 | } | 447 | } | ||
448 | | ||||
449 | bool ParserArguments::isAnyEmpty() const | ||||
450 | { | ||||
451 | return std::any_of(std::begin(arguments), std::end(arguments), | ||||
452 | [](const QString& args) { return args.isEmpty(); } | ||||
453 | ); | ||||
454 | } |
make this const