18
18
#include " indexer/AstConsumer.h"
19
19
#include " indexer/CliOptions.h"
20
20
#include " indexer/CompilationDatabase.h"
21
+ #include " indexer/IpcMessages.h"
21
22
#include " indexer/Logging.h"
22
23
#include " indexer/Preprocessing.h"
23
24
#include " indexer/Statistics.h"
@@ -269,6 +270,24 @@ void Worker::sendResult(JobId requestId, IndexJobResult &&result) {
269
270
this ->flushStreams ();
270
271
}
271
272
273
+ Worker::ReceiveStatus Worker::sendRequestAndReceive (
274
+ JobId semaRequestId, std::string_view tuMainFilePath,
275
+ SemanticAnalysisJobResult &&semaResult, IndexJobRequest &emitIndexRequest) {
276
+ this ->sendResult (semaRequestId,
277
+ IndexJobResult{IndexJob::Kind::SemanticAnalysis,
278
+ std::move (semaResult), EmitIndexJobResult{}});
279
+ auto status = this ->waitForRequest (emitIndexRequest);
280
+ if (status != ReceiveStatus::OK) {
281
+ return status;
282
+ }
283
+ if (emitIndexRequest.id == JobId::Shutdown ()) {
284
+ spdlog::warn (" expected EmitIndex request for '{}' but got Shutdown signal" ,
285
+ tuMainFilePath);
286
+ std::exit (EXIT_FAILURE);
287
+ }
288
+ return status;
289
+ }
290
+
272
291
Worker::ReceiveStatus Worker::processTranslationUnitAndRespond (
273
292
IndexJobRequest &&semanticAnalysisRequest) {
274
293
TRACE_EVENT_BEGIN (
@@ -284,6 +303,7 @@ Worker::ReceiveStatus Worker::processTranslationUnitAndRespond(
284
303
Worker::ReceiveStatus innerStatus;
285
304
JobId emitIndexRequestId;
286
305
unsigned callbackInvoked = 0 ;
306
+
287
307
auto callback =
288
308
[this , semaRequestId, &innerStatus, &emitIndexRequestId, &tuMainFilePath,
289
309
&callbackInvoked](SemanticAnalysisJobResult &&semaResult,
@@ -302,21 +322,12 @@ Worker::ReceiveStatus Worker::processTranslationUnitAndRespond(
302
322
}
303
323
return true ;
304
324
}
305
- this ->sendResult (semaRequestId,
306
- IndexJobResult{IndexJob::Kind::SemanticAnalysis,
307
- std::move (semaResult),
308
- EmitIndexJobResult{}});
309
325
IndexJobRequest emitIndexRequest{};
310
- innerStatus = this ->waitForRequest (emitIndexRequest);
326
+ innerStatus = this ->sendRequestAndReceive (
327
+ semaRequestId, tuMainFilePath, std::move (semaResult), emitIndexRequest);
311
328
if (innerStatus != ReceiveStatus::OK) {
312
329
return false ;
313
330
}
314
- if (emitIndexRequest.id == JobId::Shutdown ()) {
315
- spdlog::warn (
316
- " expected EmitIndex request for '{}' but got Shutdown signal" ,
317
- tuMainFilePath);
318
- std::exit (EXIT_FAILURE);
319
- }
320
331
TRACE_EVENT_BEGIN (tracing::indexing, " worker.emitIndex" ,
321
332
perfetto::Flow::Global (emitIndexRequest.id .traceId ()));
322
333
ENFORCE (emitIndexRequest.job .kind == IndexJob::Kind::EmitIndex,
@@ -330,16 +341,38 @@ Worker::ReceiveStatus Worker::processTranslationUnitAndRespond(
330
341
};
331
342
TuIndexingOutput tuIndexingOutput{};
332
343
auto &semaDetails = semanticAnalysisRequest.job .semanticAnalysis ;
344
+ // deliberate copy
345
+ std::vector<std::string> commandLine = semaDetails.command .CommandLine ;
333
346
334
347
scip_clang::exceptionContext =
335
348
fmt::format (" processing {}" , semaDetails.command .Filename );
336
349
this ->processTranslationUnit (std::move (semaDetails), callback,
337
350
tuIndexingOutput);
338
351
scip_clang::exceptionContext = " " ;
339
352
340
- ENFORCE (callbackInvoked == 1 ,
341
- " callbackInvoked = {} for TU with main file '{}'" , callbackInvoked,
342
- tuMainFilePath);
353
+ if (callbackInvoked == 0 ) {
354
+ spdlog::warn (" failed to index '{}' as semantic analysis didn't run; retry "
355
+ " running scip-clang with --show-compiler-diagnostics" ,
356
+ tuMainFilePath);
357
+ for (auto &arg : commandLine) {
358
+ if (arg.starts_with (" $(" ) && arg.ends_with (" )" )) {
359
+ spdlog::info (
360
+ " hint: found unexpanded '{}' in command line arguments for '{}'" ,
361
+ arg, tuMainFilePath);
362
+ }
363
+ }
364
+ // TODO: Add a different result kind indicating semantic analysis failure.
365
+ // Keep going with no-ops so as to not create errors.
366
+ IndexJobRequest emitIndexRequest{};
367
+ innerStatus = this ->sendRequestAndReceive (semaRequestId, tuMainFilePath,
368
+ SemanticAnalysisJobResult{},
369
+ emitIndexRequest);
370
+ emitIndexRequestId = emitIndexRequest.id ;
371
+ } else {
372
+ ENFORCE (callbackInvoked == 1 ,
373
+ " callbackInvoked = {} for TU with main file '{}'" , callbackInvoked,
374
+ tuMainFilePath);
375
+ }
343
376
if (innerStatus != ReceiveStatus::OK) {
344
377
return innerStatus;
345
378
}
0 commit comments