Skip to content

Commit 58825d2

Browse files
committedMar 13, 2023
[clang][ExtractAPI] Add multiple file support to --extract-api-ignores
- Modify -extract-api-ignores command line option to accept multiple arguments - Update APIIgnoresList to operate on a file list instead of a single file - Add new test verifying the functionality - fix #61242 on GitHub issue tracker Reviewed By: dang Differential Revision: https://reviews.llvm.org/D145869
1 parent 5a0ad86 commit 58825d2

File tree

6 files changed

+83
-27
lines changed

6 files changed

+83
-27
lines changed
 

‎clang/include/clang/Driver/Options.td

+3-3
Original file line numberDiff line numberDiff line change
@@ -1167,9 +1167,9 @@ def extract_api : Flag<["-"], "extract-api">, Flags<[CC1Option]>, Group<Action_G
11671167
HelpText<"Extract API information">;
11681168
def product_name_EQ: Joined<["--"], "product-name=">, Flags<[CC1Option]>,
11691169
MarshallingInfoString<FrontendOpts<"ProductName">>;
1170-
def extract_api_ignores_EQ: Joined<["--"], "extract-api-ignores=">, Flags<[CC1Option]>,
1171-
HelpText<"File containing a new line separated list of API symbols to ignore when extracting API information.">,
1172-
MarshallingInfoString<FrontendOpts<"ExtractAPIIgnoresFile">>;
1170+
def extract_api_ignores_EQ: CommaJoined<["--"], "extract-api-ignores=">, Flags<[CC1Option]>,
1171+
HelpText<"Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.">,
1172+
MarshallingInfoStringVector<FrontendOpts<"ExtractAPIIgnoresFileList">>;
11731173
def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group<Link_Group>;
11741174
def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group<f_Group>, Flags<[CC1Option]>,
11751175
HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,

‎clang/include/clang/ExtractAPI/APIIgnoresList.h

+11-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88
///
99
/// \file This file defines APIIgnoresList which is a type that allows querying
10-
/// a file containing symbols to ignore when extracting API information.
10+
/// files containing symbols to ignore when extracting API information.
1111
///
1212
//===----------------------------------------------------------------------===//
1313

@@ -44,11 +44,13 @@ struct IgnoresFileNotFound : public llvm::ErrorInfo<IgnoresFileNotFound> {
4444
/// A type that provides access to a new line separated list of symbol names to
4545
/// ignore when extracting API information.
4646
struct APIIgnoresList {
47-
/// The API to use for generating from the file at \p IgnoresFilePath.
47+
using FilePathList = std::vector<std::string>;
48+
49+
/// The API to use for generating from the files at \p IgnoresFilePathList.
4850
///
4951
/// \returns an initialized APIIgnoresList or an Error.
50-
static llvm::Expected<APIIgnoresList> create(llvm::StringRef IgnoresFilePath,
51-
FileManager &FM);
52+
static llvm::Expected<APIIgnoresList>
53+
create(const FilePathList &IgnoresFilePathList, FileManager &FM);
5254

5355
APIIgnoresList() = default;
5456

@@ -58,14 +60,14 @@ struct APIIgnoresList {
5860

5961
private:
6062
using SymbolNameList = llvm::SmallVector<llvm::StringRef, 32>;
63+
using BufferList = llvm::SmallVector<std::unique_ptr<llvm::MemoryBuffer>>;
6164

62-
APIIgnoresList(SymbolNameList SymbolsToIgnore,
63-
std::unique_ptr<llvm::MemoryBuffer> Buffer)
64-
: SymbolsToIgnore(std::move(SymbolsToIgnore)), Buffer(std::move(Buffer)) {
65-
}
65+
APIIgnoresList(SymbolNameList SymbolsToIgnore, BufferList Buffers)
66+
: SymbolsToIgnore(std::move(SymbolsToIgnore)),
67+
Buffers(std::move(Buffers)) {}
6668

6769
SymbolNameList SymbolsToIgnore;
68-
std::unique_ptr<llvm::MemoryBuffer> Buffer;
70+
BufferList Buffers;
6971
};
7072

7173
} // namespace extractapi

‎clang/include/clang/Frontend/FrontendOptions.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,9 @@ class FrontendOptions {
453453
std::string ProductName;
454454

455455
// Currently this is only used as part of the `-extract-api` action.
456-
/// The file providing a list of APIs to ignore when extracting documentation
457-
std::string ExtractAPIIgnoresFile;
456+
// A comma seperated list of files providing a list of APIs to
457+
// ignore when extracting documentation.
458+
std::vector<std::string> ExtractAPIIgnoresFileList;
458459

459460
/// Args to pass to the plugins
460461
std::map<std::string, std::vector<std::string>> PluginArgs;

‎clang/lib/ExtractAPI/APIIgnoresList.cpp

+20-11
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,29 @@ std::error_code IgnoresFileNotFound::convertToErrorCode() const {
3131
return llvm::inconvertibleErrorCode();
3232
}
3333

34-
Expected<APIIgnoresList> APIIgnoresList::create(StringRef IgnoresFilePath,
35-
FileManager &FM) {
36-
auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
37-
if (!BufferOrErr)
38-
return make_error<IgnoresFileNotFound>(IgnoresFilePath);
39-
40-
auto Buffer = std::move(BufferOrErr.get());
34+
Expected<APIIgnoresList>
35+
APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
36+
FileManager &FM) {
4137
SmallVector<StringRef, 32> Lines;
42-
Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false);
43-
// Symbol names don't have spaces in them, let's just remove these in case the
44-
// input is slighlty malformed.
38+
BufferList symbolBufferList;
39+
40+
for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) {
41+
auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath);
42+
43+
if (!BufferOrErr)
44+
return make_error<IgnoresFileNotFound>(CurrentIgnoresFilePath);
45+
46+
auto Buffer = std::move(BufferOrErr.get());
47+
Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1,
48+
/*KeepEmpty*/ false);
49+
symbolBufferList.push_back(std::move(Buffer));
50+
}
51+
52+
// Symbol names don't have spaces in them, let's just remove these in case
53+
// the input is slighlty malformed.
4554
transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); });
4655
sort(Lines);
47-
return APIIgnoresList(std::move(Lines), std::move(Buffer));
56+
return APIIgnoresList(std::move(Lines), std::move(symbolBufferList));
4857
}
4958

5059
bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const {

‎clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ ExtractAPIAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
339339
Policy.AnonymousTagLocations = false;
340340
CI.getASTContext().setPrintingPolicy(Policy);
341341

342-
if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) {
342+
if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) {
343343
llvm::handleAllErrors(
344-
APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile,
344+
APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList,
345345
CI.getFileManager())
346346
.moveInto(IgnoresList),
347347
[&CI](const IgnoresFileNotFound &Err) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
4+
// RUN: --extract-api-ignores=%t/ignores-list1,%t/ignores-list2,%t/ignores-list3 \
5+
// RUN: -x c-header %t/input.h -verify -o - | FileCheck %t/input.h
6+
7+
//--- input.h
8+
#define IGNORED_6_FILE1 6
9+
#define IGNORED_2_FILE1 2
10+
#define IGNORED_5_FILE1 5
11+
12+
#define IGNORED_4_FILE2 4
13+
#define IGNORED_3_FILE2 3
14+
15+
typedef double IGNORED_1_FILE3;
16+
typedef int IGNORED_7_FILE3;
17+
18+
typedef float NonIgnored;
19+
20+
// CHECK-NOT: IGNORED_6_FILE1
21+
// CHECK-NOT: IGNORED_2_FILE1
22+
// CHECK-NOT: IGNORED_5_FILE1
23+
24+
// CHECK-NOT: IGNORED_4_FILE2
25+
// CHECK-NOT: IGNORED_3_FILE2
26+
27+
// CHECK-NOT: IGNORED_1_FILE3
28+
// CHECK-NOT: IGNORED_7_FILE3
29+
// CHECK: NonIgnored
30+
31+
// expected-no-diagnostics
32+
33+
//--- ignores-list1
34+
IGNORED_6_FILE1
35+
IGNORED_2_FILE1
36+
IGNORED_5_FILE1
37+
38+
//--- ignores-list2
39+
IGNORED_4_FILE2
40+
IGNORED_3_FILE2
41+
42+
//--- ignores-list3
43+
IGNORED_1_FILE3
44+
IGNORED_7_FILE3

0 commit comments

Comments
 (0)
Please sign in to comment.