MCPcopy Create free account
hub / github.com/Kitware/CMake / HandleTidy

Function HandleTidy

Source/cmcmd.cxx:376–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

374}
375
376int HandleTidy(std::string const& runCmd, std::string const& sourceFile,
377 std::string const& /*objectFile*/,
378 std::vector<std::string> const& orig_cmd)
379{
380 cmList tidy_cmd{ runCmd, cmList::EmptyElements::Yes };
381 tidy_cmd.push_back(sourceFile);
382
383 for (auto const& arg : tidy_cmd) {
384 if (cmHasLiteralPrefix(arg, "--export-fixes=")) {
385 cmSystemTools::RemoveFile(arg.substr(cmStrLen("--export-fixes=")));
386 }
387 }
388
389 // clang-tidy supports working out the compile commands from a
390 // compile_commands.json file in a directory given by a "-p" option, or by
391 // passing the compiler command line arguments after --. When the latter
392 // strategy is used and the build is using a compiler other than the system
393 // default, clang-tidy may erroneously use the system default compiler's
394 // headers instead of those from the custom compiler. It doesn't do that if
395 // given a compile_commands.json to work with instead, so prefer to use the
396 // compile_commands.json file when "-p" is present.
397 if (!cm::contains(tidy_cmd.cbegin(), tidy_cmd.cend() - 1, "-p")) {
398 // Construct the clang-tidy command line by taking what was given
399 // and adding our compiler command line. The clang-tidy tool will
400 // automatically skip over the compiler itself and extract the
401 // options. If the compiler is a custom compiler, clang-tidy might
402 // not correctly handle that with this approach.
403 tidy_cmd.emplace_back("--");
404 cm::append(tidy_cmd, orig_cmd);
405 }
406
407 // Run the tidy command line. Capture its stdout and hide its stderr.
408 int ret;
409 std::string stdOut;
410 std::string stdErr;
411 if (!cmSystemTools::RunSingleCommand(tidy_cmd, &stdOut, &stdErr, &ret,
412 nullptr, cmSystemTools::OUTPUT_NONE)) {
413 std::cerr << "Error running '" << tidy_cmd[0] << "': " << stdErr << '\n';
414 return 1;
415 }
416 // Output the stdout from clang-tidy to stderr
417 std::cerr << stdOut;
418 // If clang-tidy exited with an error do the same.
419 if (ret != 0) {
420 std::cerr << stdErr;
421 }
422 return ret;
423}
424
425int HandlePVSStudio(std::string const& runCmd, std::string const& sourceFile,
426 std::string const& objectFile,

Callers

nothing calls this directly

Calls 8

cmHasLiteralPrefixFunction · 0.85
appendFunction · 0.85
push_backMethod · 0.80
cbeginMethod · 0.80
cendMethod · 0.80
emplace_backMethod · 0.80
cmStrLenFunction · 0.70
substrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…