[clang] 58825d2 - [clang][ExtractAPI] Add multiple file support to --extract-api-ignores

via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 13 05:39:11 PDT 2023


Author: Ankur
Date: 2023-03-13T18:05:16+05:30
New Revision: 58825d2cf947d0b4fb6590c17212c388cd3ff5cf

URL: https://github.com/llvm/llvm-project/commit/58825d2cf947d0b4fb6590c17212c388cd3ff5cf
DIFF: https://github.com/llvm/llvm-project/commit/58825d2cf947d0b4fb6590c17212c388cd3ff5cf.diff

LOG: [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

Added: 
    clang/test/ExtractAPI/ignored-symbols-multifile.c

Modified: 
    clang/include/clang/Driver/Options.td
    clang/include/clang/ExtractAPI/APIIgnoresList.h
    clang/include/clang/Frontend/FrontendOptions.h
    clang/lib/ExtractAPI/APIIgnoresList.cpp
    clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 52f58f045e8c..5c49450914a6 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<Action_G
   HelpText<"Extract API information">;
 def product_name_EQ: Joined<["--"], "product-name=">, Flags<[CC1Option]>,
   MarshallingInfoString<FrontendOpts<"ProductName">>;
-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<FrontendOpts<"ExtractAPIIgnoresFile">>;
+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<FrontendOpts<"ExtractAPIIgnoresFileList">>;
 def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group<Link_Group>;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group<f_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 43c546102a2d..3eee8e336cb6 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<IgnoresFileNotFound> {
 /// 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<std::string>;
+
+  /// The API to use for generating from the files at \p IgnoresFilePathList.
   ///
   /// \returns an initialized APIIgnoresList or an Error.
-  static llvm::Expected<APIIgnoresList> create(llvm::StringRef IgnoresFilePath,
-                                               FileManager &FM);
+  static llvm::Expected<APIIgnoresList>
+  create(const FilePathList &IgnoresFilePathList, FileManager &FM);
 
   APIIgnoresList() = default;
 
@@ -58,14 +60,14 @@ struct APIIgnoresList {
 
 private:
   using SymbolNameList = llvm::SmallVector<llvm::StringRef, 32>;
+  using BufferList = llvm::SmallVector<std::unique_ptr<llvm::MemoryBuffer>>;
 
-  APIIgnoresList(SymbolNameList SymbolsToIgnore,
-                 std::unique_ptr<llvm::MemoryBuffer> 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<llvm::MemoryBuffer> Buffer;
+  BufferList Buffers;
 };
 
 } // namespace extractapi

diff  --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h
index 6efe3cdd5802..ef04f3b236d8 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -453,8 +453,9 @@ class FrontendOptions {
   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<std::string> ExtractAPIIgnoresFileList;
 
   /// Args to pass to the plugins
   std::map<std::string, std::vector<std::string>> PluginArgs;

diff  --git a/clang/lib/ExtractAPI/APIIgnoresList.cpp b/clang/lib/ExtractAPI/APIIgnoresList.cpp
index 1d65ae2b8e31..d6bbc6692d2b 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> APIIgnoresList::create(StringRef IgnoresFilePath,
-                                                FileManager &FM) {
-  auto BufferOrErr = FM.getBufferForFile(IgnoresFilePath);
-  if (!BufferOrErr)
-    return make_error<IgnoresFileNotFound>(IgnoresFilePath);
-
-  auto Buffer = std::move(BufferOrErr.get());
+Expected<APIIgnoresList>
+APIIgnoresList::create(const FilePathList &IgnoresFilePathList,
+                       FileManager &FM) {
   SmallVector<StringRef, 32> 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<IgnoresFileNotFound>(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 644845efb819..c1e47b10a39f 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 000000000000..d4a4c3dde125
--- /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


        


More information about the cfe-commits mailing list