1 //===-- APINotesTest.cpp - API Notes Testing Tool ------------------ C++ --===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "clang/APINotes/APINotesYAMLCompiler.h"
10 #include "llvm/Support/CommandLine.h"
11 #include "llvm/Support/FileSystem.h"
12 #include "llvm/Support/MemoryBuffer.h"
13 #include "llvm/Support/Signals.h"
14 #include "llvm/Support/ToolOutputFile.h"
15 #include "llvm/Support/WithColor.h"
17 static llvm::cl::list
<std::string
> APINotes(llvm::cl::Positional
,
18 llvm::cl::desc("[<apinotes> ...]"),
21 static llvm::cl::opt
<std::string
>
22 OutputFileName("o", llvm::cl::desc("output filename"),
23 llvm::cl::value_desc("filename"), llvm::cl::init("-"));
25 int main(int argc
, const char **argv
) {
26 const bool DisableCrashReporting
= true;
27 llvm::sys::PrintStackTraceOnErrorSignal(argv
[0], DisableCrashReporting
);
28 llvm::cl::ParseCommandLineOptions(argc
, argv
);
30 auto Error
= [](const llvm::Twine
&Msg
) {
31 llvm::WithColor::error(llvm::errs(), "apinotes-test") << Msg
<< '\n';
35 auto Out
= std::make_unique
<llvm::ToolOutputFile
>(OutputFileName
, EC
,
36 llvm::sys::fs::OF_None
);
38 Error("failed to open '" + OutputFileName
+ "': " + EC
.message());
42 for (const std::string
&Notes
: APINotes
) {
43 llvm::ErrorOr
<std::unique_ptr
<llvm::MemoryBuffer
>> NotesOrError
=
44 llvm::MemoryBuffer::getFileOrSTDIN(Notes
);
45 if (std::error_code EC
= NotesOrError
.getError()) {
46 llvm::errs() << EC
.message() << '\n';
50 clang::api_notes::parseAndDumpAPINotes((*NotesOrError
)->getBuffer(),