diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2022-11-29 18:39:10 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2022-12-06 15:39:29 (GMT) |
commit | 232467eb1c0dab9156cd8c4af56aad3959cbee4b (patch) | |
tree | 2772b01850c143598e642282966401cb976dd421 /Source/cmNinjaTargetGenerator.cxx | |
parent | 7ea665b74da322e96dd3e7f90075143c2957728c (diff) | |
download | CMake-232467eb1c0dab9156cd8c4af56aad3959cbee4b.zip CMake-232467eb1c0dab9156cd8c4af56aad3959cbee4b.tar.gz CMake-232467eb1c0dab9156cd8c4af56aad3959cbee4b.tar.bz2 |
clang-tidy: add <LANG>_CLANG_TIDY_EXPORT_FIXES_DIR property
Fixes: #21362
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 85a6fc2..f2f719d 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 { @@ -932,8 +951,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( @@ -1314,6 +1349,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, |