summaryrefslogtreecommitdiffstats
path: root/Source/cmNinjaTargetGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-12-07 13:19:44 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-12-07 13:19:53 (GMT)
commit3b4337adc79c3744ad7b78b05035b4b460fb5f48 (patch)
tree9057f7ab5b14df7f35589661016810a12c9dcdc3 /Source/cmNinjaTargetGenerator.cxx
parent6bae244ad2a25a95a90dde1aa9047924b5acc530 (diff)
parent232467eb1c0dab9156cd8c4af56aad3959cbee4b (diff)
downloadCMake-3b4337adc79c3744ad7b78b05035b4b460fb5f48.zip
CMake-3b4337adc79c3744ad7b78b05035b4b460fb5f48.tar.gz
CMake-3b4337adc79c3744ad7b78b05035b4b460fb5f48.tar.bz2
Merge topic 'clang-tidy-export-fixes-dir'
232467eb1c clang-tidy: add <LANG>_CLANG_TIDY_EXPORT_FIXES_DIR property Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7982
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaTargetGenerator.cxx49
1 files changed, 48 insertions, 1 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 3912632..0807a98 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -27,6 +27,7 @@
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
+#include "cmGlobalCommonGenerator.h"
#include "cmGlobalNinjaGenerator.h"
#include "cmLocalGenerator.h"
#include "cmLocalNinjaGenerator.h"
@@ -394,6 +395,24 @@ std::string cmNinjaTargetGenerator::GetObjectFilePath(
return path;
}
+std::string cmNinjaTargetGenerator::GetClangTidyReplacementsFilePath(
+ const std::string& directory, cmSourceFile const* source,
+ const std::string& config) const
+{
+ std::string path = this->LocalGenerator->GetHomeRelativeOutputPath();
+ if (!path.empty()) {
+ path += '/';
+ }
+ path = cmStrCat(directory, '/', path);
+ std::string const& objectName = this->GeneratorTarget->GetObjectName(source);
+ path =
+ cmStrCat(std::move(path),
+ this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
+ this->GetGlobalGenerator()->ConfigDirectory(config), '/',
+ objectName, ".yaml");
+ return path;
+}
+
std::string cmNinjaTargetGenerator::GetPreprocessedFilePath(
cmSourceFile const* source, const std::string& config) const
{
@@ -935,8 +954,24 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang,
} else {
driverMode = lang == "C" ? "gcc" : "g++";
}
+ const bool haveClangTidyExportFixesDir =
+ !this->GeneratorTarget->GetClangTidyExportFixesDirectory(lang)
+ .empty();
+ std::string exportFixes;
+ if (haveClangTidyExportFixesDir) {
+ exportFixes = ";--export-fixes=$CLANG_TIDY_EXPORT_FIXES";
+ }
run_iwyu += this->GetLocalGenerator()->EscapeForShell(
- cmStrCat(*tidy, ";--extra-arg-before=--driver-mode=", driverMode));
+ cmStrCat(*tidy, ";--extra-arg-before=--driver-mode=", driverMode,
+ exportFixes));
+ if (haveClangTidyExportFixesDir) {
+ std::string search = cmStrCat(
+ this->GetLocalGenerator()->GetState()->UseWindowsShell() ? ""
+ : "\\",
+ "$$CLANG_TIDY_EXPORT_FIXES");
+ auto loc = run_iwyu.rfind(search);
+ run_iwyu.replace(loc, search.length(), "$CLANG_TIDY_EXPORT_FIXES");
+ }
}
if (cmNonempty(cpplint)) {
run_iwyu += cmStrCat(
@@ -1317,6 +1352,18 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
}
}
+ std::string d =
+ this->GeneratorTarget->GetClangTidyExportFixesDirectory(language);
+ if (!d.empty()) {
+ this->GlobalCommonGenerator->AddClangTidyExportFixesDir(d);
+ std::string fixesFile =
+ this->GetClangTidyReplacementsFilePath(d, source, config);
+ this->GlobalCommonGenerator->AddClangTidyExportFixesFile(fixesFile);
+ cmSystemTools::MakeDirectory(cmSystemTools::GetFilenamePath(fixesFile));
+ fixesFile = this->ConvertToNinjaPath(fixesFile);
+ vars["CLANG_TIDY_EXPORT_FIXES"] = fixesFile;
+ }
+
if (firstForConfig) {
this->ExportObjectCompileCommand(
language, sourceFilePath, objectDir, objectFileName, objectFileDir,