Differential D11136 Diff 28958 plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp
Changeset View
Changeset View
Standalone View
Standalone View
plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp
Show All 30 Lines | |||||
31 | #include <interfaces/iruntime.h> | 31 | #include <interfaces/iruntime.h> | ||
32 | #include <interfaces/iruntimecontroller.h> | 32 | #include <interfaces/iruntimecontroller.h> | ||
33 | #include <interfaces/iproject.h> | 33 | #include <interfaces/iproject.h> | ||
34 | #include <project/projectmodel.h> | 34 | #include <project/projectmodel.h> | ||
35 | 35 | | |||
36 | #include <KLocalizedString> | 36 | #include <KLocalizedString> | ||
37 | #include <QStandardPaths> | 37 | #include <QStandardPaths> | ||
38 | #include <QDir> | 38 | #include <QDir> | ||
39 | #include <iprojectcontroller.h> | ||||
mwolff: move up, add interfaces/ | |||||
40 | #include <interfaces/ibuildsystemmanager.h> | ||||
39 | 41 | | |||
40 | using namespace KDevelop; | 42 | using namespace KDevelop; | ||
41 | 43 | | |||
42 | namespace | 44 | namespace | ||
43 | { | 45 | { | ||
44 | class NoCompiler : public ICompiler | 46 | class NoCompiler : public ICompiler | ||
45 | { | 47 | { | ||
46 | public: | 48 | public: | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 94 | if (targetDirectory.isParentOf(itemPath)) { | |||
96 | } | 98 | } | ||
97 | } | 99 | } | ||
98 | } | 100 | } | ||
99 | 101 | | |||
100 | return config; | 102 | return config; | ||
101 | } | 103 | } | ||
102 | } | 104 | } | ||
103 | 105 | | |||
106 | ProjectTargetItem* findCompiledTarget(ProjectBaseItem* item) | ||||
107 | { | ||||
108 | for(auto item: item->targetList()) { | ||||
109 | if (item->type() == ProjectBaseItem::ExecutableTarget || item->type() == ProjectBaseItem::LibraryTarget) { | ||||
110 | return item; | ||||
111 | } | ||||
112 | } | ||||
113 | | ||||
114 | for(auto folder: item->folderList()) { | ||||
115 | auto target = findCompiledTarget(folder); | ||||
116 | if (target) | ||||
117 | return target; | ||||
118 | } | ||||
119 | return nullptr; | ||||
120 | } | ||||
121 | | ||||
104 | CompilerProvider::CompilerProvider( SettingsManager* settings, QObject* parent ) | 122 | CompilerProvider::CompilerProvider( SettingsManager* settings, QObject* parent ) | ||
105 | : QObject( parent ) | 123 | : QObject( parent ) | ||
106 | , m_settings(settings) | 124 | , m_settings(settings) | ||
107 | { | 125 | { | ||
108 | m_factories.append(CompilerFactoryPointer(new GccFactory())); | 126 | m_factories.append(CompilerFactoryPointer(new GccFactory())); | ||
109 | m_factories.append(CompilerFactoryPointer(new ClangFactory())); | 127 | m_factories.append(CompilerFactoryPointer(new ClangFactory())); | ||
110 | #ifdef _WIN32 | 128 | #ifdef _WIN32 | ||
111 | m_factories.append(CompilerFactoryPointer(new MsvcFactory())); | 129 | m_factories.append(CompilerFactoryPointer(new MsvcFactory())); | ||
Show All 9 Lines | 138 | #ifdef _WIN32 | |||
121 | if (!QStandardPaths::findExecutable("cl.exe").isEmpty()) { | 139 | if (!QStandardPaths::findExecutable("cl.exe").isEmpty()) { | ||
122 | m_factories[2]->registerDefaultCompilers(this); | 140 | m_factories[2]->registerDefaultCompilers(this); | ||
123 | } | 141 | } | ||
124 | #endif | 142 | #endif | ||
125 | 143 | | |||
126 | registerCompiler(createDummyCompiler()); | 144 | registerCompiler(createDummyCompiler()); | ||
127 | retrieveUserDefinedCompilers(); | 145 | retrieveUserDefinedCompilers(); | ||
128 | 146 | | |||
129 | connect(ICore::self()->runtimeController(), &IRuntimeController::currentRuntimeChanged, this, [this]() { m_defaultProvider.clear(); }); | 147 | connect(ICore::self()->runtimeController(), &IRuntimeController::currentRuntimeChanged, this, [this]() { | ||
148 | m_defaultProvider.clear(); | ||||
149 | | ||||
150 | for (auto p : ICore::self()->projectController()->projects()) { | ||||
151 | const auto target = findCompiledTarget(p->projectItem()); | ||||
152 | if (!target) | ||||
153 | continue; | ||||
154 | | ||||
155 | auto path = p->buildSystemManager()->findCompiler(target); | ||||
I find it odd that this is the only place where this new API is being used, no? shouldn't it also be used elswhere? like, when we don't really use runtimes at all? mwolff: I find it odd that this is the only place where this new API is being used, no? shouldn't it… | |||||
156 | qCDebug(DEFINESANDINCLUDES) << "found compiler" << path; | ||||
157 | if (!path.isEmpty() || !QDir::isAbsolutePath(path.toLocalFile())) | ||||
this isAbsolutePath check - shouldn't it be an assertion? the BSM should sanitize and produce absolute paths, I'd say (like, based on the build/source dir) mwolff: this isAbsolutePath check - shouldn't it be an assertion? the BSM should sanitize and produce… | |||||
the ! is wrong, no? otherwise you only run the code below when the path is empty, which sounds odd mwolff: the ! is wrong, no? otherwise you only run the code below when the path is empty, which sounds… | |||||
158 | continue; | ||||
159 | | ||||
160 | const auto pathString = path.toLocalFile(); | ||||
161 | bool alreadyPresent = false; | ||||
162 | for ( const CompilerPointer& compiler : m_compilers ) { | ||||
for (const auto& compiler : m_compilers) or better yet: if (std::any_of(m_compilers.begin(), m_compilers.end(), [pathString](const auto& compiler) { compiler->path() == pathString; }) { continue; } mwolff: `for (const auto& compiler : m_compilers)`
or better yet:
```
if (std::any_of(m_compilers. | |||||
163 | if (compiler->path() == pathString) { | ||||
164 | alreadyPresent = true; | ||||
165 | break; | ||||
166 | } | ||||
167 | } | ||||
168 | if (alreadyPresent) | ||||
mwolff: no need for the else + indentation, you continue above | |||||
169 | continue; | ||||
170 | //we need to search, sdk compiler names are weird: arm-linux-androideabi-g++ | ||||
171 | int factory = path.lastPathSegment().contains(QLatin1String("clang")) ? 1 : 0; | ||||
this looks weird to me - this shouldn't be hardcoded like this, no? it should go through all factories and find a match. I.e. on windows we may need to use the msvc factory? mwolff: this looks weird to me - this shouldn't be hardcoded like this, no? it should go through all… | |||||
172 | auto compiler = m_factories[factory]->createCompiler(path.lastPathSegment(), pathString); | ||||
173 | registerCompiler(compiler); | ||||
174 | | ||||
175 | qCDebug(DEFINESANDINCLUDES) << "using compiler" << compiler; | ||||
176 | m_defaultProvider = compiler; | ||||
177 | } | ||||
178 | }, Qt::QueuedConnection); | ||||
130 | } | 179 | } | ||
131 | 180 | | |||
132 | CompilerProvider::~CompilerProvider() = default; | 181 | CompilerProvider::~CompilerProvider() = default; | ||
133 | 182 | | |||
134 | QHash<QString, QString> CompilerProvider::defines( const QString& path ) const | 183 | QHash<QString, QString> CompilerProvider::defines( const QString& path ) const | ||
135 | { | 184 | { | ||
136 | auto config = configForItem(nullptr); | 185 | auto config = configForItem(nullptr); | ||
137 | auto languageType = Utils::languageType(path, config.parserArguments.parseAmbiguousAsCPP); | 186 | auto languageType = Utils::languageType(path, config.parserArguments.parseAmbiguousAsCPP); | ||
138 | // If called on files that we can't compile, return an empty set of defines. | 187 | // If called on files that we can't compile, return an empty set of defines. | ||
139 | if (languageType == Utils::Other) { | 188 | if (languageType == Utils::Other) { | ||
140 | return {}; | 189 | return {}; | ||
141 | } | 190 | } | ||
142 | 191 | | |||
143 | return config.compiler->defines(languageType, config.parserArguments[languageType]); | 192 | return config.compiler->defines(languageType, config.parserArguments[languageType]); | ||
144 | } | 193 | } | ||
145 | 194 | | |||
146 | QHash<QString, QString> CompilerProvider::defines( ProjectBaseItem* item ) const | 195 | QHash<QString, QString> CompilerProvider::defines( ProjectBaseItem* item ) const | ||
147 | { | 196 | { | ||
148 | auto config = configForItem(item); | 197 | auto config = configForItem(item); | ||
149 | auto languageType = Utils::Cpp; | 198 | auto languageType = Utils::Cpp; | ||
mwolff: join next line | |||||
150 | if (item) { | 199 | if (item) { | ||
151 | languageType = Utils::languageType(item->path().path(), config.parserArguments.parseAmbiguousAsCPP); | 200 | languageType = Utils::languageType(item->path().path(), config.parserArguments.parseAmbiguousAsCPP); | ||
152 | } | 201 | } | ||
153 | // If called on files that we can't compile, return an empty set of defines. | 202 | // If called on files that we can't compile, return an empty set of defines. | ||
154 | if (languageType == Utils::Other) { | 203 | if (languageType == Utils::Other) { | ||
155 | return {}; | 204 | return {}; | ||
156 | } | 205 | } | ||
157 | 206 | | |||
▲ Show 20 Lines • Show All 123 Lines • Show Last 20 Lines |
move up, add interfaces/