From: Ankur Date: Mon, 13 Mar 2023 12:28:39 +0000 (+0530) Subject: [clang][ExtractAPI] Add multiple file support to --extract-api-ignores X-Git-Tag: upstream/17.0.6~15056 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=58825d2cf947d0b4fb6590c17212c388cd3ff5cf;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 52f58f0..5c49450 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1167,9 +1167,9 @@ def extract_api : Flag<["-"], "extract-api">, Flags<[CC1Option]>, Group; def product_name_EQ: Joined<["--"], "product-name=">, Flags<[CC1Option]>, MarshallingInfoString>; -def extract_api_ignores_EQ: Joined<["--"], "extract-api-ignores=">, Flags<[CC1Option]>, - HelpText<"File containing a new line separated list of API symbols to ignore when extracting API information.">, - MarshallingInfoString>; +def extract_api_ignores_EQ: CommaJoined<["--"], "extract-api-ignores=">, Flags<[CC1Option]>, + HelpText<"Comma separated list of files containing a new line separated list of API symbols to ignore when extracting API information.">, + MarshallingInfoStringVector>; def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group; def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group, Flags<[CC1Option]>, HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">, diff --git a/clang/include/clang/ExtractAPI/APIIgnoresList.h b/clang/include/clang/ExtractAPI/APIIgnoresList.h index 43c5461..3eee8e3 100644 --- a/clang/include/clang/ExtractAPI/APIIgnoresList.h +++ b/clang/include/clang/ExtractAPI/APIIgnoresList.h @@ -7,7 +7,7 @@ //===----------------------------------------------------------------------===// /// /// \file This file defines APIIgnoresList which is a type that allows querying -/// a file containing symbols to ignore when extracting API information. +/// files containing symbols to ignore when extracting API information. /// //===----------------------------------------------------------------------===// @@ -44,11 +44,13 @@ struct IgnoresFileNotFound : public llvm::ErrorInfo { /// A type that provides access to a new line separated list of symbol names to /// ignore when extracting API information. struct APIIgnoresList { - /// The API to use for generating from the file at \p IgnoresFilePath. + using FilePathList = std::vector; + + /// The API to use for generating from the files at \p IgnoresFilePathList. /// /// \returns an initialized APIIgnoresList or an Error. - static llvm::Expected create(llvm::StringRef IgnoresFilePath, - FileManager &FM); + static llvm::Expected + create(const FilePathList &IgnoresFilePathList, FileManager &FM); APIIgnoresList() = default; @@ -58,14 +60,14 @@ struct APIIgnoresList { private: using SymbolNameList = llvm::SmallVector; + using BufferList = llvm::SmallVector>; - APIIgnoresList(SymbolNameList SymbolsToIgnore, - std::unique_ptr Buffer) - : SymbolsToIgnore(std::move(SymbolsToIgnore)), Buffer(std::move(Buffer)) { - } + APIIgnoresList(SymbolNameList SymbolsToIgnore, BufferList Buffers) + : SymbolsToIgnore(std::move(SymbolsToIgnore)), + Buffers(std::move(Buffers)) {} SymbolNameList SymbolsToIgnore; - std::unique_ptr Buffer; + BufferList Buffers; }; } // namespace extractapi diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h index 6efe3cd..ef04f3b 100644 --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -453,8 +453,9 @@ public: std::string ProductName; // Currently this is only used as part of the `-extract-api` action. - /// The file providing a list of APIs to ignore when extracting documentation - std::string ExtractAPIIgnoresFile; + // A comma seperated list of files providing a list of APIs to + // ignore when extracting documentation. + std::vector ExtractAPIIgnoresFileList; /// Args to pass to the plugins std::map> PluginArgs; diff --git a/clang/lib/ExtractAPI/APIIgnoresList.cpp b/clang/lib/ExtractAPI/APIIgnoresList.cpp index 1d65ae2..d6bbc66 100644 --- a/clang/lib/ExtractAPI/APIIgnoresList.cpp +++ b/clang/lib/ExtractAPI/APIIgnoresList.cpp @@ -31,20 +31,29 @@ std::error_code IgnoresFileNotFound::convertToErrorCode() const { return llvm::inconvertibleErrorCode(); } -Expected APIIgnoresList::create(StringRef IgnoresFilePath, - FileManager &FM) { - auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath); - if (!BufferOrErr) - return make_error(IgnoresFilePath); - - auto Buffer = std::move(BufferOrErr.get()); +Expected +APIIgnoresList::create(const FilePathList &IgnoresFilePathList, + FileManager &FM) { SmallVector Lines; - Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, /*KeepEmpty*/ false); - // Symbol names don't have spaces in them, let's just remove these in case the - // input is slighlty malformed. + BufferList symbolBufferList; + + for (const auto &CurrentIgnoresFilePath : IgnoresFilePathList) { + auto BufferOrErr = FM.getBufferForFile(CurrentIgnoresFilePath); + + if (!BufferOrErr) + return make_error(CurrentIgnoresFilePath); + + auto Buffer = std::move(BufferOrErr.get()); + Buffer->getBuffer().split(Lines, '\n', /*MaxSplit*/ -1, + /*KeepEmpty*/ false); + symbolBufferList.push_back(std::move(Buffer)); + } + + // Symbol names don't have spaces in them, let's just remove these in case + // the input is slighlty malformed. transform(Lines, Lines.begin(), [](StringRef Line) { return Line.trim(); }); sort(Lines); - return APIIgnoresList(std::move(Lines), std::move(Buffer)); + return APIIgnoresList(std::move(Lines), std::move(symbolBufferList)); } bool APIIgnoresList::shouldIgnore(StringRef SymbolName) const { diff --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp index 644845e..c1e47b1 100644 --- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp +++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp @@ -339,9 +339,9 @@ ExtractAPIAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { Policy.AnonymousTagLocations = false; CI.getASTContext().setPrintingPolicy(Policy); - if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) { + if (!CI.getFrontendOpts().ExtractAPIIgnoresFileList.empty()) { llvm::handleAllErrors( - APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile, + APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFileList, CI.getFileManager()) .moveInto(IgnoresList), [&CI](const IgnoresFileNotFound &Err) { diff --git a/clang/test/ExtractAPI/ignored-symbols-multifile.c b/clang/test/ExtractAPI/ignored-symbols-multifile.c new file mode 100644 index 0000000..d4a4c3d --- /dev/null +++ b/clang/test/ExtractAPI/ignored-symbols-multifile.c @@ -0,0 +1,44 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t +// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \ +// RUN: --extract-api-ignores=%t/ignores-list1,%t/ignores-list2,%t/ignores-list3 \ +// RUN: -x c-header %t/input.h -verify -o - | FileCheck %t/input.h + +//--- input.h +#define IGNORED_6_FILE1 6 +#define IGNORED_2_FILE1 2 +#define IGNORED_5_FILE1 5 + +#define IGNORED_4_FILE2 4 +#define IGNORED_3_FILE2 3 + +typedef double IGNORED_1_FILE3; +typedef int IGNORED_7_FILE3; + +typedef float NonIgnored; + +// CHECK-NOT: IGNORED_6_FILE1 +// CHECK-NOT: IGNORED_2_FILE1 +// CHECK-NOT: IGNORED_5_FILE1 + +// CHECK-NOT: IGNORED_4_FILE2 +// CHECK-NOT: IGNORED_3_FILE2 + +// CHECK-NOT: IGNORED_1_FILE3 +// CHECK-NOT: IGNORED_7_FILE3 +// CHECK: NonIgnored + +// expected-no-diagnostics + +//--- ignores-list1 +IGNORED_6_FILE1 +IGNORED_2_FILE1 +IGNORED_5_FILE1 + +//--- ignores-list2 +IGNORED_4_FILE2 +IGNORED_3_FILE2 + +//--- ignores-list3 +IGNORED_1_FILE3 +IGNORED_7_FILE3