1 //===- InstallAPI/DirectoryScanner.h ----------------------------*- 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 /// The DirectoryScanner for collecting library files on the file system. 10 /// 11 //===----------------------------------------------------------------------===// 12 #ifndef LLVM_CLANG_INSTALLAPI_DIRECTORYSCANNER_H 13 #define LLVM_CLANG_INSTALLAPI_DIRECTORYSCANNER_H 14 15 #include "clang/Basic/FileManager.h" 16 #include "clang/InstallAPI/Library.h" 17 18 namespace clang::installapi { 19 20 enum ScanMode { 21 /// Scanning Framework directory. 22 ScanFrameworks, 23 /// Scanning Dylib directory. 24 ScanDylibs, 25 }; 26 27 class DirectoryScanner { 28 public: 29 DirectoryScanner(FileManager &FM, ScanMode Mode = ScanMode::ScanFrameworks) FM(FM)30 : FM(FM), Mode(Mode) {} 31 32 /// Scan for all input files throughout directory. 33 /// 34 /// \param Directory Path of input directory. 35 llvm::Error scan(StringRef Directory); 36 37 /// Take over ownership of stored libraries. takeLibraries()38 std::vector<Library> takeLibraries() { return std::move(Libraries); }; 39 40 /// Get all the header files in libraries. 41 /// 42 /// \param Libraries Reference of collection of libraries. 43 static HeaderSeq getHeaders(ArrayRef<Library> Libraries); 44 45 private: 46 /// Collect files for dylibs in usr/(local)/lib within directory. 47 llvm::Error scanForUnwrappedLibraries(StringRef Directory); 48 49 /// Collect files for any frameworks within directory. 50 llvm::Error scanForFrameworks(StringRef Directory); 51 52 /// Get a library from the libraries collection. 53 Library &getOrCreateLibrary(StringRef Path, std::vector<Library> &Libs) const; 54 55 /// Collect multiple frameworks from directory. 56 llvm::Error scanMultipleFrameworks(StringRef Directory, 57 std::vector<Library> &Libs) const; 58 /// Collect files from nested frameworks. 59 llvm::Error scanSubFrameworksDirectory(StringRef Directory, 60 std::vector<Library> &Libs) const; 61 62 /// Collect files from framework path. 63 llvm::Error scanFrameworkDirectory(StringRef Path, Library &Framework) const; 64 65 /// Collect header files from path. 66 llvm::Error scanHeaders(StringRef Path, Library &Lib, HeaderType Type, 67 StringRef BasePath, 68 StringRef ParentPath = StringRef()) const; 69 70 /// Collect files from Version directories inside Framework directories. 71 llvm::Error scanFrameworkVersionsDirectory(StringRef Path, 72 Library &Lib) const; 73 FileManager &FM; 74 ScanMode Mode; 75 StringRef RootPath; 76 std::vector<Library> Libraries; 77 }; 78 79 } // namespace clang::installapi 80 81 #endif // LLVM_CLANG_INSTALLAPI_DIRECTORYSCANNER_H 82