-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolChainResolver.cpp
More file actions
72 lines (56 loc) · 1.91 KB
/
Copy pathToolChainResolver.cpp
File metadata and controls
72 lines (56 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "run/ToolChainResolver.h"
#include "settings/SettingsService.h"
#include <QFileInfo>
#include <QStandardPaths>
namespace cold {
namespace {
bool isExecutableFile(const QString& path) {
if (path.isEmpty()) {
return false;
}
QFileInfo info(path);
return info.isFile() && info.isExecutable();
}
} // namespace
QString ToolChainResolver::resolve(SettingsService& settings, const QString& toolKey) {
QString stored = settings.toolPath(toolKey);
if (isExecutableFile(stored)) {
return stored;
}
QString found = QStandardPaths::findExecutable(toolKey);
if (isExecutableFile(found)) {
return found;
}
return {};
}
bool ToolChainResolver::isAvailable(SettingsService& settings, const QString& toolKey) {
return !resolve(settings, toolKey).isEmpty();
}
NativeCompiler ToolChainResolver::compilerForFile(const QString& filePath,
SettingsService& settings) {
const QString suffix = QFileInfo(filePath).suffix().toLower();
NativeCompiler result;
if (suffix == QStringLiteral("c")) {
result.program = resolve(settings, QStringLiteral("gcc"));
if (!result.program.isEmpty()) {
result.isClang = false;
return result;
}
result.program = resolve(settings, QStringLiteral("clang"));
result.isClang = !result.program.isEmpty();
return result;
}
if (suffix == QStringLiteral("cpp") || suffix == QStringLiteral("cc") ||
suffix == QStringLiteral("cxx")) {
result.program = resolve(settings, QStringLiteral("g++"));
if (!result.program.isEmpty()) {
result.isClang = false;
return result;
}
result.program = resolve(settings, QStringLiteral("clang++"));
result.isClang = !result.program.isEmpty();
return result;
}
return result;
}
} // namespace cold