Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:56

0001 //===- InstallAPI/DirectoryScanner.h ----------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// The DirectoryScanner for collecting library files on the file system.
0010 ///
0011 //===----------------------------------------------------------------------===//
0012 #ifndef LLVM_CLANG_INSTALLAPI_DIRECTORYSCANNER_H
0013 #define LLVM_CLANG_INSTALLAPI_DIRECTORYSCANNER_H
0014 
0015 #include "clang/Basic/FileManager.h"
0016 #include "clang/InstallAPI/Library.h"
0017 
0018 namespace clang::installapi {
0019 
0020 enum ScanMode {
0021   /// Scanning Framework directory.
0022   ScanFrameworks,
0023   /// Scanning Dylib directory.
0024   ScanDylibs,
0025 };
0026 
0027 class DirectoryScanner {
0028 public:
0029   DirectoryScanner(FileManager &FM, ScanMode Mode = ScanMode::ScanFrameworks)
0030       : FM(FM), Mode(Mode) {}
0031 
0032   /// Scan for all input files throughout directory.
0033   ///
0034   /// \param Directory Path of input directory.
0035   llvm::Error scan(StringRef Directory);
0036 
0037   /// Take over ownership of stored libraries.
0038   std::vector<Library> takeLibraries() { return std::move(Libraries); };
0039 
0040   /// Get all the header files in libraries.
0041   ///
0042   /// \param Libraries Reference of collection of libraries.
0043   static HeaderSeq getHeaders(ArrayRef<Library> Libraries);
0044 
0045 private:
0046   /// Collect files for dylibs in usr/(local)/lib within directory.
0047   llvm::Error scanForUnwrappedLibraries(StringRef Directory);
0048 
0049   /// Collect files for any frameworks within directory.
0050   llvm::Error scanForFrameworks(StringRef Directory);
0051 
0052   /// Get a library from the libraries collection.
0053   Library &getOrCreateLibrary(StringRef Path, std::vector<Library> &Libs) const;
0054 
0055   /// Collect multiple frameworks from directory.
0056   llvm::Error scanMultipleFrameworks(StringRef Directory,
0057                                      std::vector<Library> &Libs) const;
0058   /// Collect files from nested frameworks.
0059   llvm::Error scanSubFrameworksDirectory(StringRef Directory,
0060                                          std::vector<Library> &Libs) const;
0061 
0062   /// Collect files from framework path.
0063   llvm::Error scanFrameworkDirectory(StringRef Path, Library &Framework) const;
0064 
0065   /// Collect header files from path.
0066   llvm::Error scanHeaders(StringRef Path, Library &Lib, HeaderType Type,
0067                           StringRef BasePath,
0068                           StringRef ParentPath = StringRef()) const;
0069 
0070   /// Collect files from Version directories inside Framework directories.
0071   llvm::Error scanFrameworkVersionsDirectory(StringRef Path,
0072                                              Library &Lib) const;
0073   FileManager &FM;
0074   ScanMode Mode;
0075   StringRef RootPath;
0076   std::vector<Library> Libraries;
0077 };
0078 
0079 } // namespace clang::installapi
0080 
0081 #endif // LLVM_CLANG_INSTALLAPI_DIRECTORYSCANNER_H