Differential D5447 Diff 57676 plugins/custom-definesandincludes/compilerprovider/compilerfactories.cpp
Changeset View
Changeset View
Standalone View
Standalone View
plugins/custom-definesandincludes/compilerprovider/compilerfactories.cpp
Show All 21 Lines | |||||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include "compilerfactories.h" | 24 | #include "compilerfactories.h" | ||
25 | #include "compilerprovider.h" | 25 | #include "compilerprovider.h" | ||
26 | 26 | | |||
27 | #include "gcclikecompiler.h" | 27 | #include "gcclikecompiler.h" | ||
28 | #include "msvccompiler.h" | 28 | #include "msvccompiler.h" | ||
29 | 29 | | |||
30 | #include <QStandardPaths> | ||||
31 | | ||||
30 | QString ClangFactory::name() const | 32 | QString ClangFactory::name() const | ||
31 | { | 33 | { | ||
32 | return QStringLiteral("Clang"); | 34 | return QStringLiteral("Clang"); | ||
33 | } | 35 | } | ||
34 | 36 | | |||
35 | bool ClangFactory::isSupported(const KDevelop::Path& path) const | 37 | bool ClangFactory::isSupported(const KDevelop::Path& path) const | ||
36 | { | 38 | { | ||
37 | const auto filename = path.lastPathSegment(); | 39 | const auto filename = path.lastPathSegment(); | ||
38 | return filename.contains(QLatin1String("clang")) && !filename.contains(QLatin1String("clang-cl")); | 40 | return filename.contains(QLatin1String("clang")) && !filename.contains(QLatin1String("clang-cl")); | ||
39 | } | 41 | } | ||
40 | 42 | | |||
41 | CompilerPointer ClangFactory::createCompiler(const QString& name, const QString& path, bool editable ) const | 43 | CompilerPointer ClangFactory::createCompiler(const QString& name, const QString& path, bool editable ) const | ||
42 | { | 44 | { | ||
43 | return CompilerPointer(new GccLikeCompiler(name, path, editable, this->name())); | 45 | return CompilerPointer(new GccLikeCompiler(name, path, editable, this->name())); | ||
44 | } | 46 | } | ||
45 | 47 | | |||
46 | void ClangFactory::registerDefaultCompilers(CompilerProvider* provider) const | 48 | void ClangFactory::registerDefaultCompilers(CompilerProvider* provider) const | ||
47 | { | 49 | { | ||
48 | const QString clang = QStringLiteral("clang"); | 50 | // no need to check the result, we already do this is CompilerProvider::CompilerProvider() | ||
51 | const QString clang = QStandardPaths::findExecutable(QStringLiteral("clang")); | ||||
mwolff: shouldn't be required, we find the executable internally by name after all | |||||
Hmm. But the second arg of createCompiler is called path, and whole this patch is about passing a full path there. Probably, in presence of such thing as runtimes, we need to revise Compiler's API and do something about path() method? arrowd: Hmm. But the second arg of `createCompiler` is called `path`, and whole this patch is about… | |||||
afaik it's called path since it can be a user-provided absolute path. But the builtin compiler defaults all want to do dynamic lookups. so no, I think it's fine to keep the API but again - don't hardcode an absolute path in the host here - it should be a name that's checked in either the runtime or the host mwolff: afaik it's called path since it can be a user-provided absolute path. But the builtin compiler… | |||||
arrowd: So, this hunk and other `ditto`s should be completely reversed? | |||||
mwolff: yes exactly | |||||
49 | 52 | | |||
50 | auto compiler = createCompiler(name(), clang, false); | 53 | auto compiler = createCompiler(name(), clang, false); | ||
51 | provider->registerCompiler(compiler); | 54 | provider->registerCompiler(compiler); | ||
52 | } | 55 | } | ||
53 | 56 | | |||
54 | QString GccFactory::name() const | 57 | QString GccFactory::name() const | ||
55 | { | 58 | { | ||
56 | return QStringLiteral("GCC"); | 59 | return QStringLiteral("GCC"); | ||
57 | } | 60 | } | ||
58 | 61 | | |||
59 | bool GccFactory::isSupported(const KDevelop::Path& path) const | 62 | bool GccFactory::isSupported(const KDevelop::Path& path) const | ||
60 | { | 63 | { | ||
61 | return path.lastPathSegment().contains(QLatin1String("gcc")) || path.lastPathSegment().contains(QLatin1String("g++")); | 64 | return path.lastPathSegment().contains(QLatin1String("gcc")) || path.lastPathSegment().contains(QLatin1String("g++")); | ||
62 | } | 65 | } | ||
63 | 66 | | |||
64 | CompilerPointer GccFactory::createCompiler(const QString& name, const QString& path, bool editable ) const | 67 | CompilerPointer GccFactory::createCompiler(const QString& name, const QString& path, bool editable ) const | ||
65 | { | 68 | { | ||
66 | return CompilerPointer(new GccLikeCompiler(name, path, editable, this->name())); | 69 | return CompilerPointer(new GccLikeCompiler(name, path, editable, this->name())); | ||
67 | } | 70 | } | ||
68 | 71 | | |||
69 | void GccFactory::registerDefaultCompilers(CompilerProvider* provider) const | 72 | void GccFactory::registerDefaultCompilers(CompilerProvider* provider) const | ||
70 | { | 73 | { | ||
71 | const QString gcc = QStringLiteral("gcc"); | 74 | const QString gcc = QStandardPaths::findExecutable(QStringLiteral("gcc")); | ||
mwolff: dito | |||||
72 | 75 | | |||
73 | auto compiler = createCompiler(name(), gcc, false); | 76 | auto compiler = createCompiler(name(), gcc, false); | ||
74 | provider->registerCompiler(compiler); | 77 | provider->registerCompiler(compiler); | ||
75 | } | 78 | } | ||
76 | 79 | | |||
77 | QString MsvcFactory::name() const | 80 | QString MsvcFactory::name() const | ||
78 | { | 81 | { | ||
79 | return QStringLiteral("MSVC"); | 82 | return QStringLiteral("MSVC"); | ||
80 | } | 83 | } | ||
81 | 84 | | |||
82 | CompilerPointer MsvcFactory::createCompiler(const QString& name, const QString& path, bool editable ) const | 85 | CompilerPointer MsvcFactory::createCompiler(const QString& name, const QString& path, bool editable ) const | ||
83 | { | 86 | { | ||
84 | return CompilerPointer(new MsvcCompiler(name, path, editable, this->name())); | 87 | return CompilerPointer(new MsvcCompiler(name, path, editable, this->name())); | ||
85 | } | 88 | } | ||
86 | 89 | | |||
87 | void MsvcFactory::registerDefaultCompilers(CompilerProvider* provider) const | 90 | void MsvcFactory::registerDefaultCompilers(CompilerProvider* provider) const | ||
88 | { | 91 | { | ||
89 | provider->registerCompiler(createCompiler(name(), QStringLiteral("cl.exe"), false)); | 92 | provider->registerCompiler(createCompiler(name(), QStandardPaths::findExecutable(QStringLiteral("cl.exe")), false)); | ||
mwolff: dito | |||||
90 | } | 93 | } | ||
91 | 94 | | |||
92 | bool MsvcFactory::isSupported(const KDevelop::Path& path) const | 95 | bool MsvcFactory::isSupported(const KDevelop::Path& path) const | ||
93 | { | 96 | { | ||
94 | return path.lastPathSegment() == QLatin1String("cl.exe") || path.lastPathSegment().contains(QLatin1String("clang-cl")); | 97 | return path.lastPathSegment() == QLatin1String("cl.exe") || path.lastPathSegment().contains(QLatin1String("clang-cl")); | ||
95 | } | 98 | } |
shouldn't be required, we find the executable internally by name after all