[clang-tools-extra] ff8b4c8 - [clang-tidy][NFC] Minor cleanup in ClangTidyMain.cpp
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 15 23:18:57 PDT 2023
Author: Piotr Zegar
Date: 2023-09-16T06:17:57Z
New Revision: ff8b4c8b2c9cce0e70e6e05ca9f0d4399d670236
URL: https://github.com/llvm/llvm-project/commit/ff8b4c8b2c9cce0e70e6e05ca9f0d4399d670236
DIFF: https://github.com/llvm/llvm-project/commit/ff8b4c8b2c9cce0e70e6e05ca9f0d4399d670236.diff
LOG: [clang-tidy][NFC] Minor cleanup in ClangTidyMain.cpp
Extracted some code from a clangTidyMain function into
separate functions.
Added:
Modified:
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index dd7f8141a694e2a..0d2593e74f052b9 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -525,6 +525,31 @@ static bool verifyFileExtensions(
return AnyInvalid;
}
+static SmallString<256> makeAbsolute(llvm::StringRef Input) {
+ if (Input.empty())
+ return {};
+ SmallString<256> AbsolutePath(Input);
+ if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
+ llvm::errs() << "Can't make absolute path from " << Input << ": "
+ << EC.message() << "\n";
+ }
+ return AbsolutePath;
+}
+
+static llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> createBaseFS() {
+ llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS(
+ new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
+
+ if (!VfsOverlay.empty()) {
+ IntrusiveRefCntPtr<vfs::FileSystem> VfsFromFile =
+ getVfsFromFile(VfsOverlay, BaseFS);
+ if (!VfsFromFile)
+ return nullptr;
+ BaseFS->pushOverlay(std::move(VfsFromFile));
+ }
+ return BaseFS;
+}
+
int clangTidyMain(int argc, const char **argv) {
llvm::InitLLVM X(argc, argv);
@@ -540,34 +565,16 @@ int clangTidyMain(int argc, const char **argv) {
return 1;
}
- llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS(
- new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
-
- if (!VfsOverlay.empty()) {
- IntrusiveRefCntPtr<vfs::FileSystem> VfsFromFile =
- getVfsFromFile(VfsOverlay, BaseFS);
- if (!VfsFromFile)
- return 1;
- BaseFS->pushOverlay(std::move(VfsFromFile));
- }
+ llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS = createBaseFS();
+ if (!BaseFS)
+ return 1;
auto OwningOptionsProvider = createOptionsProvider(BaseFS);
auto *OptionsProvider = OwningOptionsProvider.get();
if (!OptionsProvider)
return 1;
- auto MakeAbsolute = [](const std::string &Input) -> SmallString<256> {
- if (Input.empty())
- return {};
- SmallString<256> AbsolutePath(Input);
- if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) {
- llvm::errs() << "Can't make absolute path from " << Input << ": "
- << EC.message() << "\n";
- }
- return AbsolutePath;
- };
-
- SmallString<256> ProfilePrefix = MakeAbsolute(StoreCheckProfile);
+ SmallString<256> ProfilePrefix = makeAbsolute(StoreCheckProfile);
StringRef FileName("dummy");
auto PathList = OptionsParser->getSourcePathList();
@@ -575,9 +582,9 @@ int clangTidyMain(int argc, const char **argv) {
FileName = PathList.front();
}
- SmallString<256> FilePath = MakeAbsolute(std::string(FileName));
-
+ SmallString<256> FilePath = makeAbsolute(FileName);
ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath);
+
std::vector<std::string> EnabledChecks =
getCheckNames(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers);
More information about the cfe-commits
mailing list