@@ -78,7 +78,7 @@ ProcessExecutor::ProcessExecutor(const std::list<FileWithDetails> &files, const
78
78
namespace {
79
79
class PipeWriter : public ErrorLogger {
80
80
public:
81
- enum PipeSignal : std::uint8_t {REPORT_OUT=' 1' ,REPORT_ERROR=' 2' , CHILD_END=' 5' };
81
+ enum PipeSignal : std::uint8_t {REPORT_OUT=' 1' ,REPORT_ERROR=' 2' ,REPORT_SUPPR_INLINE= ' 3 ' , CHILD_END=' 5' };
82
82
83
83
explicit PipeWriter (int pipe) : mWpipe(pipe) {}
84
84
@@ -90,11 +90,32 @@ namespace {
90
90
writeToPipe (REPORT_ERROR, msg.serialize ());
91
91
}
92
92
93
+ void writeSuppr (const SuppressionList &supprs) const {
94
+ for (const auto & suppr : supprs.getSuppressions ())
95
+ {
96
+ if (!suppr.isInline )
97
+ continue ;
98
+
99
+ writeToPipe (REPORT_SUPPR_INLINE, suppressionToString (suppr));
100
+ }
101
+ // TODO: update suppression states?
102
+ }
103
+
93
104
void writeEnd (const std::string& str) const {
94
105
writeToPipe (CHILD_END, str);
95
106
}
96
107
97
108
private:
109
+ static std::string suppressionToString (const SuppressionList::Suppression &suppr)
110
+ {
111
+ std::string suppr_str = suppr.toString ();
112
+ suppr_str += " ;" ;
113
+ suppr_str += suppr.checked ? " 1" : " 0" ;
114
+ suppr_str += " ;" ;
115
+ suppr_str += suppr.matched ? " 1" : " 0" ;
116
+ return suppr_str;
117
+ }
118
+
98
119
// TODO: how to log file name in error?
99
120
void writeToPipeInternal (PipeSignal type, const void * data, std::size_t to_write) const
100
121
{
@@ -124,7 +145,7 @@ namespace {
124
145
writeToPipeInternal (type, &len, l_size);
125
146
}
126
147
127
- if (len > 0 )
148
+ if (len > 0 ) // TODO: unexpected - write a warning?
128
149
writeToPipeInternal (type, data.c_str (), len);
129
150
}
130
151
@@ -155,7 +176,10 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
155
176
std::exit (EXIT_FAILURE);
156
177
}
157
178
158
- if (type != PipeWriter::REPORT_OUT && type != PipeWriter::REPORT_ERROR && type != PipeWriter::CHILD_END) {
179
+ if (type != PipeWriter::REPORT_OUT &&
180
+ type != PipeWriter::REPORT_ERROR &&
181
+ type != PipeWriter::REPORT_SUPPR_INLINE &&
182
+ type != PipeWriter::CHILD_END) {
159
183
std::cerr << " #### ThreadExecutor::handleRead(" << filename << " ) invalid type " << int (type) << std::endl;
160
184
std::exit (EXIT_FAILURE);
161
185
}
@@ -174,7 +198,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
174
198
}
175
199
176
200
std::string buf (len, ' \0 ' );
177
- if (len > 0 ) {
201
+ if (len > 0 ) { // TODO: unexpected - write a warning?
178
202
char *data_start = &buf[0 ];
179
203
bytes_to_read = len;
180
204
do {
@@ -206,6 +230,29 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
206
230
207
231
if (hasToLog (msg))
208
232
mErrorLogger .reportErr (msg);
233
+ } else if (type == PipeWriter::REPORT_SUPPR_INLINE) {
234
+ if (!buf.empty ()) {
235
+ // TODO: avoid string splitting
236
+ auto parts = splitString (buf, ' ;' );
237
+ if (parts.size () != 3 )
238
+ {
239
+ // TODO: make this non-fatal
240
+ std::cerr << " #### ThreadExecutor::handleRead(" << filename << " ) adding of inline suppression failed - insufficient data" << std::endl;
241
+ std::exit (EXIT_FAILURE);
242
+ }
243
+ auto suppr = SuppressionList::parseLine (parts[0 ]);
244
+ suppr.isInline = true ;
245
+ suppr.checked = parts[1 ] == " 1" ;
246
+ suppr.matched = parts[2 ] == " 1" ;
247
+ const std::string err = mSuppressions .nomsg .addSuppression (suppr);
248
+ if (!err.empty ()) {
249
+ // TODO: only update state if it doesn't exist - otherwise propagate error
250
+ mSuppressions .nomsg .updateSuppressionState (suppr); // TODO: check result
251
+ // TODO: make this non-fatal
252
+ // std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") adding of inline suppression failed - " << err << std::endl;
253
+ // std::exit(EXIT_FAILURE);
254
+ }
255
+ }
209
256
} else if (type == PipeWriter::CHILD_END) {
210
257
result += std::stoi (buf);
211
258
res = false ;
@@ -297,6 +344,8 @@ unsigned int ProcessExecutor::check()
297
344
// TODO: call analyseClangTidy()?
298
345
}
299
346
347
+ pipewriter.writeSuppr (mSuppressions .nomsg );
348
+
300
349
pipewriter.writeEnd (std::to_string (resultOfCheck));
301
350
std::exit (EXIT_SUCCESS);
302
351
}
0 commit comments