forked from Andersbakken/rtags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IndexerJob.cpp
163 lines (148 loc) · 5.29 KB
/
IndexerJob.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* This file is part of RTags (http://rtags.net).
RTags is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RTags is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RTags. If not, see <http://www.gnu.org/licenses/>. */
#include "IndexerJob.h"
#include "CompilerManager.h"
#include "Project.h"
#include "rct/Process.h"
#include "RTagsClang.h"
#include "Server.h"
uint64_t IndexerJob::sNextId = 1;
IndexerJob::IndexerJob(const Source &s,
Flags<Flag> f,
const std::shared_ptr<Project> &p,
const UnsavedFiles &u)
: id(0), source(s), sourceFile(s.sourceFile()), flags(f),
project(p->path()), priority(0), unsavedFiles(u), crashCount(0)
{
acquireId();
if (flags & Dirty)
++priority;
Server *server = Server::instance();
assert(server);
if (server->isActiveBuffer(source.fileId)) {
priority += 4;
} else {
for (uint32_t dep : p->dependencies(source.fileId, Project::ArgDependsOn)) {
if (server->isActiveBuffer(dep)) {
priority += 2;
break;
}
}
}
visited.insert(s.fileId);
}
IndexerJob::~IndexerJob()
{
destroyed(this);
}
void IndexerJob::acquireId()
{
id = sNextId++;
}
String IndexerJob::encode() const
{
String ret;
{
Serializer serializer(ret);
serializer.write("1234", sizeof(int)); // for size
std::shared_ptr<Project> proj = Server::instance()->project(project);
const Server::Options &options = Server::instance()->options();
Source copy = source;
if (options.options & (Server::Weverything|Server::Wall) && source.arguments.contains("-Werror")) {
for (const auto &arg : options.defaultArguments) {
if (arg != "-Wall" && arg != "-Weverything")
copy.arguments << arg;
}
} else {
copy.arguments << options.defaultArguments;
}
if (!(options.options & Server::AllowPedantic)) {
const int idx = copy.arguments.indexOf("-Wpedantic");
if (idx != -1) {
copy.arguments.removeAt(idx);
}
}
if (options.options & Server::EnableCompilerManager)
CompilerManager::applyToSource(copy, false, true);
for (const String &blocked : options.blockedArguments) {
if (blocked.endsWith("=")) {
int i = 0;
while (i<copy.arguments.size()) {
if (copy.arguments.at(i).startsWith(blocked)) {
// error() << "Removing" << copy.arguments.at(i);
copy.arguments.remove(i, 1);
} else if (!strncmp(blocked.constData(), copy.arguments.at(i).constData(), blocked.size() - 1)) {
const int count = i + 1 < copy.arguments.size() ? 2 : 1;
// error() << "Removing" << copy.arguments.mid(i, count);
copy.arguments.remove(i, count);
} else {
++i;
}
}
} else {
copy.arguments.remove(blocked);
}
}
for (const auto &inc : options.includePaths) {
copy.includePaths << inc;
}
copy.defines << options.defines;
if (!(options.options & Server::EnableNDEBUG)) {
copy.defines.remove(Source::Define("NDEBUG"));
}
assert(!sourceFile.isEmpty());
serializer << static_cast<uint16_t>(RTags::DatabaseVersion)
<< id
<< options.socketFile
<< project
<< copy
<< sourceFile
<< flags
<< static_cast<uint32_t>(options.rpVisitFileTimeout)
<< static_cast<uint32_t>(options.rpIndexDataMessageTimeout)
<< static_cast<uint32_t>(options.rpConnectTimeout)
<< static_cast<uint32_t>(options.rpConnectAttempts)
<< static_cast<int32_t>(options.rpNiceValue)
<< options.options
<< unsavedFiles
<< options.dataDir
<< options.debugLocations;
assert(proj);
proj->encodeVisitedFiles(serializer);
}
const uint32_t size = ret.size() - sizeof(int);
memcpy(&ret[0], &size, sizeof(size));
return ret;
}
String IndexerJob::dumpFlags(Flags<Flag> flags)
{
List<String> ret;
if (flags & Dirty) {
ret += "Dirty";
}
if (flags & Compile) {
ret += "Compile";
}
if (flags & Running) {
ret += "Running";
}
if (flags & Crashed) {
ret += "Crashed";
}
if (flags & Aborted) {
ret += "Aborted";
}
if (flags & Complete) {
ret += "Complete";
}
return String::join(ret, ", ");
}