10#include "llvm/ADT/STLExtras.h"
11#include "llvm/ADT/SmallVector.h"
12#include "llvm/Support/CommandLine.h"
13#include "llvm/Support/DynamicLibrary.h"
14#include "llvm/Support/Error.h"
15#include "llvm/Support/FormatVariadic.h"
16#include "llvm/Support/Path.h"
17#include "llvm/Support/Process.h"
18#include "llvm/Support/WithColor.h"
19#include "llvm/Support/raw_ostream.h"
27namespace path = llvm::sys::path;
31llvm::StringRef ToolName;
32llvm::StringRef ToolVersion;
34void printVersion(llvm::raw_ostream &OS) {
35 OS << ToolName <<
" " << ToolVersion <<
"\n";
42SerializationFormat *getFormatForExtension(llvm::StringRef Extension) {
48 static llvm::SmallVector<
49 std::pair<std::string, std::unique_ptr<SerializationFormat>>, 4>
53 auto ReversedList = llvm::reverse(ExtensionFormatList);
54 auto It = llvm::find_if(ReversedList, [&](
const auto &Entry) {
57 if (It != ReversedList.end()) {
58 return It->second.get();
66 SerializationFormat *
Result = Format.get();
68 "makeFormat must return non-null for a registered extension");
70 ExtensionFormatList.emplace_back(Extension, std::move(Format));
80 llvm::WithColor::error(llvm::errs(), ToolName) << Msg <<
"\n";
81 llvm::sys::Process::Exit(1);
85 std::string Message = llvm::toString(std::move(Err));
90 for (
const std::string &PluginPath : Paths) {
92 if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(PluginPath.c_str(),
100 llvm::cl::OptionCategory &Category,
101 llvm::StringRef ToolHeading) {
103 ToolName = path::stem(argv[0]);
106 ToolVersion = Version;
109 llvm::cl::HideUnrelatedOptions(Category);
112 llvm::cl::SetVersionPrinter(printVersion);
115 std::string Overview = (ToolHeading +
"\n").str();
116 llvm::cl::ParseCommandLineOptions(argc, argv, Overview);
120 llvm::StringRef Extension = path::extension(
Path);
121 if (Extension.empty()) {
126 Extension = Extension.drop_front();
129 std::string BadExtension =
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
constexpr const char * ExtensionNotSupplied
constexpr const char * CannotValidateSummary
constexpr const char * NoFormatForExtension
constexpr const char * FailedToLoadPlugin
llvm::StringRef getToolName()
Returns the name of the running tool, as set by initTool().
std::unique_ptr< SerializationFormat > makeFormat(llvm::StringRef FormatName)
Try to instantiate a SerializationFormat with a given name.
void fail(const char *Msg)
void initTool(int argc, const char **argv, llvm::StringRef Version, llvm::cl::OptionCategory &Category, llvm::StringRef ToolHeading)
Sets ToolName, ToolVersion, and the version printer, hides unrelated command-line options,...
bool isFormatRegistered(llvm::StringRef FormatName)
Check if a SerializationFormat was registered with a given name.
void loadPlugins(llvm::ArrayRef< std::string > Paths)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
SerializationFormat * Format
static SummaryFile fromPath(llvm::StringRef Path)
Constructs a SummaryFile by resolving the serialization format from the file extension.