Differential D1047 Diff 2606 languages/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp
Changeset View
Changeset View
Standalone View
Standalone View
languages/plugins/custom-definesandincludes/compilerprovider/settingsmanager.cpp
Show All 20 Lines | |||||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "settingsmanager.h" | 23 | #include "settingsmanager.h" | ||
24 | 24 | | |||
25 | #include <QDataStream> | 25 | #include <QDataStream> | ||
26 | #include <QDebug> | 26 | #include <QDebug> | ||
27 | #include <QThread> | 27 | #include <QThread> | ||
28 | #include <QCoreApplication> | 28 | #include <QCoreApplication> | ||
29 | #include <QMimeDatabase> | ||||
29 | 30 | | |||
30 | #include <KConfig> | 31 | #include <KConfig> | ||
31 | #include <KConfigGroup> | 32 | #include <KConfigGroup> | ||
32 | 33 | | |||
33 | #include <interfaces/iproject.h> | 34 | #include <interfaces/iproject.h> | ||
34 | #include <interfaces/icore.h> | 35 | #include <interfaces/icore.h> | ||
35 | #include <interfaces/iplugincontroller.h> | 36 | #include <interfaces/iplugincontroller.h> | ||
36 | #include <project/projectmodel.h> | 37 | #include <project/projectmodel.h> | ||
Show All 13 Lines | |||||
50 | const QString customBuildSystemGroup = QLatin1String( "CustomBuildSystem" ); | 51 | const QString customBuildSystemGroup = QLatin1String( "CustomBuildSystem" ); | ||
51 | const QString definesAndIncludesGroup = QLatin1String( "Defines And Includes" ); | 52 | const QString definesAndIncludesGroup = QLatin1String( "Defines And Includes" ); | ||
52 | 53 | | |||
53 | const QString compilersGroup = QLatin1String( "Compilers" ); | 54 | const QString compilersGroup = QLatin1String( "Compilers" ); | ||
54 | const QString compilerNameKey = QLatin1String( "Name" ); | 55 | const QString compilerNameKey = QLatin1String( "Name" ); | ||
55 | const QString compilerPathKey = QLatin1String( "Path" ); | 56 | const QString compilerPathKey = QLatin1String( "Path" ); | ||
56 | const QString compilerTypeKey = QLatin1String( "Type" ); | 57 | const QString compilerTypeKey = QLatin1String( "Type" ); | ||
57 | 58 | | |||
58 | QString parserArguments() | 59 | QString parserArgumentsCPP() | ||
59 | { | 60 | { | ||
60 | return QStringLiteral("parserArguments"); | 61 | return QStringLiteral("parserArguments"); | ||
mwolff: this breaks backwards compatibility for those that already use the kdevelop 5 beta. could we… | |||||
61 | } | 62 | } | ||
62 | 63 | | |||
64 | QString parserArgumentsC() | ||||
65 | { | ||||
66 | return QStringLiteral("parserArgumentsC"); | ||||
67 | } | ||||
68 | | ||||
69 | QString parseAmbiguousAsCPP() | ||||
70 | { | ||||
71 | return QStringLiteral("parseAmbiguousAsCPP"); | ||||
72 | } | ||||
63 | } | 73 | } | ||
64 | 74 | | |||
65 | // the grouplist is randomly sorted b/c it uses QSet internally | 75 | // the grouplist is randomly sorted b/c it uses QSet internally | ||
66 | // we sort the keys here, as the structure is properly defined for us | 76 | // we sort the keys here, as the structure is properly defined for us | ||
67 | QStringList sorted(QStringList list) | 77 | QStringList sorted(QStringList list) | ||
68 | { | 78 | { | ||
69 | std::sort(list.begin(), list.end()); | 79 | std::sort(list.begin(), list.end()); | ||
70 | return list; | 80 | return list; | ||
71 | } | 81 | } | ||
72 | 82 | | |||
73 | QString defaultArguments() | 83 | ParserArguments defaultArguments() | ||
84 | { | ||||
85 | const static ParserArguments arguments | ||||
kfunk: Initialize in ctor? | |||||
74 | { | 86 | { | ||
75 | return QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11"); | 87 | QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c99"), | ||
88 | QStringLiteral("-ferror-limit=100 -fspell-checking -Wdocumentation -Wunused-parameter -Wunreachable-code -Wall -std=c++11"), | ||||
89 | true | ||||
90 | }; | ||||
91 | | ||||
92 | return arguments; | ||||
76 | } | 93 | } | ||
77 | 94 | | |||
78 | CompilerPointer createCompilerFromConfig(KConfigGroup& cfg) | 95 | CompilerPointer createCompilerFromConfig(KConfigGroup& cfg) | ||
79 | { | 96 | { | ||
80 | auto grp = cfg.group("Compiler"); | 97 | auto grp = cfg.group("Compiler"); | ||
81 | auto name = grp.readEntry( ConfigConstants::compilerNameKey, QString() ); | 98 | auto name = grp.readEntry( ConfigConstants::compilerNameKey, QString() ); | ||
82 | if (name.isEmpty()) { | 99 | if (name.isEmpty()) { | ||
83 | return SettingsManager::globalInstance()->provider()->checkCompilerExists({}); | 100 | return SettingsManager::globalInstance()->provider()->checkCompilerExists({}); | ||
Show All 19 Lines | |||||
103 | } | 120 | } | ||
104 | 121 | | |||
105 | void doWriteSettings( KConfigGroup grp, const QList<ConfigEntry>& paths ) | 122 | void doWriteSettings( KConfigGroup grp, const QList<ConfigEntry>& paths ) | ||
106 | { | 123 | { | ||
107 | int pathIndex = 0; | 124 | int pathIndex = 0; | ||
108 | for ( const auto& path : paths ) { | 125 | for ( const auto& path : paths ) { | ||
109 | KConfigGroup pathgrp = grp.group( ConfigConstants::projectPathPrefix + QString::number( pathIndex++ ) ); | 126 | KConfigGroup pathgrp = grp.group( ConfigConstants::projectPathPrefix + QString::number( pathIndex++ ) ); | ||
110 | pathgrp.writeEntry(ConfigConstants::projectPathKey, path.path); | 127 | pathgrp.writeEntry(ConfigConstants::projectPathKey, path.path); | ||
111 | pathgrp.writeEntry(ConfigConstants::parserArguments(), path.parserArguments); | 128 | pathgrp.writeEntry(ConfigConstants::parserArgumentsCPP(), path.parserArguments.cppArguments); | ||
129 | pathgrp.writeEntry(ConfigConstants::parserArgumentsC(), path.parserArguments.cArguments); | ||||
130 | pathgrp.writeEntry(ConfigConstants::parseAmbiguousAsCPP(), path.parserArguments.parseAmbiguousAsCPP); | ||||
112 | 131 | | |||
113 | { | 132 | { | ||
114 | int index = 0; | 133 | int index = 0; | ||
115 | KConfigGroup includes(pathgrp.group(ConfigConstants::includesKey)); | 134 | KConfigGroup includes(pathgrp.group(ConfigConstants::includesKey)); | ||
116 | for( auto it = path.includes.begin() ; it != path.includes.end(); ++it){ | 135 | for( auto it = path.includes.begin() ; it != path.includes.end(); ++it){ | ||
117 | includes.writeEntry(QString::number(++index), *it); | 136 | includes.writeEntry(QString::number(++index), *it); | ||
118 | } | 137 | } | ||
119 | 138 | | |||
Show All 15 Lines | 152 | { | |||
135 | for( const QString &grpName : sorted(grp.groupList()) ) { | 154 | for( const QString &grpName : sorted(grp.groupList()) ) { | ||
136 | if ( !grpName.startsWith( ConfigConstants::projectPathPrefix ) ) { | 155 | if ( !grpName.startsWith( ConfigConstants::projectPathPrefix ) ) { | ||
137 | continue; | 156 | continue; | ||
138 | } | 157 | } | ||
139 | KConfigGroup pathgrp = grp.group( grpName ); | 158 | KConfigGroup pathgrp = grp.group( grpName ); | ||
140 | 159 | | |||
141 | ConfigEntry path; | 160 | ConfigEntry path; | ||
142 | path.path = pathgrp.readEntry( ConfigConstants::projectPathKey, "" ); | 161 | path.path = pathgrp.readEntry( ConfigConstants::projectPathKey, "" ); | ||
143 | path.parserArguments = pathgrp.readEntry(ConfigConstants::parserArguments(), defaultArguments()); | 162 | path.parserArguments.cppArguments = pathgrp.readEntry(ConfigConstants::parserArgumentsCPP(), defaultArguments().cppArguments); | ||
163 | path.parserArguments.cArguments = pathgrp.readEntry(ConfigConstants::parserArgumentsC(), defaultArguments().cArguments); | ||||
164 | path.parserArguments.parseAmbiguousAsCPP = pathgrp.readEntry(ConfigConstants::parseAmbiguousAsCPP(), defaultArguments().parseAmbiguousAsCPP); | ||||
165 | | ||||
166 | if (path.parserArguments.cppArguments.isEmpty()) { | ||||
167 | path.parserArguments.cppArguments = defaultArguments().cppArguments; | ||||
168 | } | ||||
144 | 169 | | |||
145 | if (path.parserArguments.isEmpty()) { | 170 | if (path.parserArguments.cArguments.isEmpty()) { | ||
146 | path.parserArguments = defaultArguments(); | 171 | path.parserArguments.cArguments = defaultArguments().cArguments; | ||
147 | } | 172 | } | ||
148 | 173 | | |||
149 | { // defines | 174 | { // defines | ||
150 | // Backwards compatibility with old config style | 175 | // Backwards compatibility with old config style | ||
151 | if(pathgrp.hasKey(ConfigConstants::definesKey)) { | 176 | if(pathgrp.hasKey(ConfigConstants::definesKey)) { | ||
152 | QByteArray tmp = pathgrp.readEntry( ConfigConstants::definesKey, QByteArray() ); | 177 | QByteArray tmp = pathgrp.readEntry( ConfigConstants::definesKey, QByteArray() ); | ||
153 | QDataStream s( tmp ); | 178 | QDataStream s( tmp ); | ||
154 | s.setVersion( QDataStream::Qt_4_5 ); | 179 | s.setVersion( QDataStream::Qt_4_5 ); | ||
Show All 39 Lines | |||||
194 | } | 219 | } | ||
195 | 220 | | |||
196 | path.compiler = createCompilerFromConfig(pathgrp); | 221 | path.compiler = createCompilerFromConfig(pathgrp); | ||
197 | 222 | | |||
198 | if ( remove ) { | 223 | if ( remove ) { | ||
199 | pathgrp.deleteGroup(); | 224 | pathgrp.deleteGroup(); | ||
200 | } | 225 | } | ||
201 | 226 | | |||
202 | Q_ASSERT(!path.parserArguments.isEmpty()); | 227 | Q_ASSERT(!path.parserArguments.cppArguments.isEmpty()); | ||
228 | Q_ASSERT(!path.parserArguments.cArguments.isEmpty()); | ||||
203 | paths << path; | 229 | paths << path; | ||
204 | } | 230 | } | ||
205 | 231 | | |||
206 | return paths; | 232 | return paths; | ||
207 | } | 233 | } | ||
208 | 234 | | |||
209 | /** | 235 | /** | ||
210 | * Reads and converts paths from old (Custom Build System's) format to the current one. | 236 | * Reads and converts paths from old (Custom Build System's) format to the current one. | ||
▲ Show 20 Lines • Show All 133 Lines • ▼ Show 20 Line(s) | 369 | if (f->name() == type) { | |||
344 | auto compiler = f->createCompiler(name, path); | 370 | auto compiler = f->createCompiler(name, path); | ||
345 | compilers.append(compiler); | 371 | compilers.append(compiler); | ||
346 | } | 372 | } | ||
347 | } | 373 | } | ||
348 | } | 374 | } | ||
349 | return compilers; | 375 | return compilers; | ||
350 | } | 376 | } | ||
351 | 377 | | |||
352 | QString SettingsManager::defaultParserArguments() const | 378 | ParserArguments SettingsManager::defaultParserArguments() const | ||
353 | { | 379 | { | ||
354 | return defaultArguments(); | 380 | return defaultArguments(); | ||
355 | } | 381 | } | ||
356 | 382 | | |||
357 | ConfigEntry::ConfigEntry(const QString& path) | 383 | ConfigEntry::ConfigEntry(const QString& path) | ||
358 | : path(path) | 384 | : path(path) | ||
359 | , compiler(SettingsManager::globalInstance()->provider()->checkCompilerExists({})) | 385 | , compiler(SettingsManager::globalInstance()->provider()->checkCompilerExists({})) | ||
360 | , parserArguments(defaultArguments()) | 386 | , parserArguments(defaultArguments()) | ||
361 | {} | 387 | {} | ||
388 | | ||||
389 | namespace Utils { | ||||
390 | LanguageType languageType(const KDevelop::Path& path, bool treatAmbiguousAsCPP) | ||||
391 | { | ||||
392 | QMimeDatabase db; | ||||
393 | const auto mimeType = db.mimeTypeForFile(path.path()).name(); | ||||
394 | if (mimeType == QStringLiteral("text/x-csrc") || | ||||
395 | mimeType == QStringLiteral("text/x-chdr") ) { | ||||
396 | if (treatAmbiguousAsCPP) { | ||||
397 | if (path.lastPathSegment().endsWith(QLatin1String(".h"), Qt::CaseInsensitive)) { | ||||
398 | return Cpp; | ||||
399 | } | ||||
400 | } | ||||
401 | | ||||
402 | return C; | ||||
403 | } | ||||
404 | | ||||
405 | if (mimeType == QStringLiteral("text/x-c++src") || | ||||
406 | mimeType == QStringLiteral("text/x-c++hdr") ) { | ||||
407 | return Cpp; | ||||
408 | } | ||||
409 | | ||||
410 | if (mimeType == QStringLiteral("text/x-objcsrc")) { | ||||
411 | return ObjC; | ||||
412 | } | ||||
413 | | ||||
414 | return Other; | ||||
415 | } | ||||
416 | } |
this breaks backwards compatibility for those that already use the kdevelop 5 beta. could we stick to the old name for Cpp, and only introduce a new key for the two other args?