Differential D11136 Diff 29096 plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp
Changeset View
Changeset View
Standalone View
Standalone View
plugins/custom-definesandincludes/compilerprovider/compilerprovider.cpp
Show All 25 Lines | |||||
26 | #include "debug.h" | 26 | #include "debug.h" | ||
27 | #include "qtcompat_p.h" | 27 | #include "qtcompat_p.h" | ||
28 | #include "compilerfactories.h" | 28 | #include "compilerfactories.h" | ||
29 | #include "settingsmanager.h" | 29 | #include "settingsmanager.h" | ||
30 | 30 | | |||
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 <interfaces/iprojectcontroller.h> | ||||
35 | #include <interfaces/ibuildsystemmanager.h> | ||||
34 | #include <project/projectmodel.h> | 36 | #include <project/projectmodel.h> | ||
35 | 37 | | |||
36 | #include <KLocalizedString> | 38 | #include <KLocalizedString> | ||
37 | #include <QStandardPaths> | 39 | #include <QStandardPaths> | ||
38 | #include <QDir> | 40 | #include <QDir> | ||
39 | 41 | | |||
mwolff: move up, add interfaces/ | |||||
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: | ||
47 | NoCompiler(): | 49 | NoCompiler(): | ||
▲ Show 20 Lines • Show All 48 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 10 Lines | 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]() { m_defaultProvider.clear(); }); | ||
148 | connect(ICore::self()->projectController(), &IProjectController::projectConfigurationChanged, this, &CompilerProvider::projectChanged); | ||||
149 | connect(ICore::self()->projectController(), &IProjectController::projectOpened, this, &CompilerProvider::projectChanged); | ||||
130 | } | 150 | } | ||
131 | 151 | | |||
132 | CompilerProvider::~CompilerProvider() = default; | 152 | CompilerProvider::~CompilerProvider() = default; | ||
133 | 153 | | |||
154 | void CompilerProvider::projectChanged(KDevelop::IProject* p) | ||||
155 | { | ||||
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 | const auto target = findCompiledTarget(p->projectItem()); | ||||
157 | if (!target) | ||||
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 | return; | ||||
159 | | ||||
160 | auto path = p->buildSystemManager()->compiler(target); | ||||
161 | qCDebug(DEFINESANDINCLUDES) << "found compiler" << path; | ||||
162 | if (path.isEmpty()) | ||||
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 | return; | ||||
164 | | ||||
165 | Q_ASSERT(QDir::isAbsolutePath(path.toLocalFile())); | ||||
166 | const auto pathString = path.toLocalFile(); | ||||
167 | auto it = std::find_if(m_compilers.begin(), m_compilers.end(), | ||||
168 | [pathString](const CompilerPointer& compiler) { return compiler->path() == pathString; }); | ||||
mwolff: no need for the else + indentation, you continue above | |||||
169 | if (it != m_compilers.end()) { | ||||
mwolff: join next line | |||||
170 | m_defaultProvider = *it; | ||||
171 | return; | ||||
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 | } | ||||
173 | | ||||
174 | //we need to search, sdk compiler names are weird: arm-linux-androideabi-g++ | ||||
175 | for (auto factory : m_factories) { | ||||
176 | if (factory->isSupported(path)) { | ||||
177 | auto compiler = factory->createCompiler(path.lastPathSegment(), pathString); | ||||
178 | const auto registered = registerCompiler(compiler); | ||||
179 | m_defaultProvider = compiler; | ||||
180 | } | ||||
181 | } | ||||
182 | | ||||
183 | qCDebug(DEFINESANDINCLUDES) << "using compiler" << m_defaultProvider << path; | ||||
184 | } | ||||
185 | | ||||
134 | QHash<QString, QString> CompilerProvider::defines( const QString& path ) const | 186 | QHash<QString, QString> CompilerProvider::defines( const QString& path ) const | ||
135 | { | 187 | { | ||
136 | auto config = configForItem(nullptr); | 188 | auto config = configForItem(nullptr); | ||
137 | auto languageType = Utils::languageType(path, config.parserArguments.parseAmbiguousAsCPP); | 189 | auto languageType = Utils::languageType(path, config.parserArguments.parseAmbiguousAsCPP); | ||
138 | // If called on files that we can't compile, return an empty set of defines. | 190 | // If called on files that we can't compile, return an empty set of defines. | ||
139 | if (languageType == Utils::Other) { | 191 | if (languageType == Utils::Other) { | ||
140 | return {}; | 192 | return {}; | ||
141 | } | 193 | } | ||
▲ Show 20 Lines • Show All 139 Lines • Show Last 20 Lines |
move up, add interfaces/