/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/apinotes-test/APINotesTest.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- APINotesTest.cpp - API Notes Testing Tool ------------------ C++ --===// |
2 | | // |
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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | |
9 | | #include "clang/APINotes/APINotesYAMLCompiler.h" |
10 | | #include "llvm/Support/CommandLine.h" |
11 | | #include "llvm/Support/Signals.h" |
12 | | #include "llvm/Support/ToolOutputFile.h" |
13 | | #include "llvm/Support/WithColor.h" |
14 | | |
15 | | static llvm::cl::list<std::string> APINotes(llvm::cl::Positional, |
16 | | llvm::cl::desc("[<apinotes> ...]"), |
17 | | llvm::cl::Required); |
18 | | |
19 | | static llvm::cl::opt<std::string> |
20 | | OutputFileName("o", llvm::cl::desc("output filename"), |
21 | | llvm::cl::value_desc("filename"), llvm::cl::init("-")); |
22 | | |
23 | 2 | int main(int argc, const char **argv) { |
24 | 2 | const bool DisableCrashReporting = true; |
25 | 2 | llvm::sys::PrintStackTraceOnErrorSignal(argv[0], DisableCrashReporting); |
26 | 2 | llvm::cl::ParseCommandLineOptions(argc, argv); |
27 | | |
28 | 0 | auto Error = [](const llvm::Twine &Msg) { |
29 | 0 | llvm::WithColor::error(llvm::errs(), "apinotes-test") << Msg << '\n'; |
30 | 0 | }; |
31 | | |
32 | 2 | std::error_code EC; |
33 | 2 | auto Out = std::make_unique<llvm::ToolOutputFile>(OutputFileName, EC, |
34 | 2 | llvm::sys::fs::OF_None); |
35 | 2 | if (EC) { |
36 | 0 | Error("failed to open '" + OutputFileName + "': " + EC.message()); |
37 | 0 | return EXIT_FAILURE; |
38 | 0 | } |
39 | | |
40 | 2 | for (const std::string &Notes : APINotes) { |
41 | 2 | llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> NotesOrError = |
42 | 2 | llvm::MemoryBuffer::getFileOrSTDIN(Notes); |
43 | 2 | if (std::error_code EC = NotesOrError.getError()) { |
44 | 0 | llvm::errs() << EC.message() << '\n'; |
45 | 0 | return EXIT_FAILURE; |
46 | 0 | } |
47 | | |
48 | 2 | clang::api_notes::parseAndDumpAPINotes((*NotesOrError)->getBuffer(), |
49 | 2 | Out->os()); |
50 | 2 | } |
51 | | |
52 | 2 | return EXIT_SUCCESS; |
53 | 2 | } |