File indexing completed on 2024-05-19 05:42:01
0001 // ct_lvtclp_filesystemscanner.h -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #ifndef INCLUDED_CT_LVTCLP_FILESYSTEMSCANNER 0021 #define INCLUDED_CT_LVTCLP_FILESYSTEMSCANNER 0022 0023 //@PURPOSE: Scan the filesystem for package groups, packages, and componenets 0024 // 0025 //@CLASSES: 0026 // lvtclp::FilesystemScanner 0027 0028 #include <lvtclp_export.h> 0029 0030 #include <filesystem> 0031 #include <functional> 0032 #include <memory> 0033 #include <string> 0034 #include <unordered_set> 0035 #include <vector> 0036 0037 #include <llvm/Support/GlobPattern.h> 0038 0039 namespace Codethink::lvtmdb { 0040 class ObjectStore; 0041 } 0042 namespace Codethink::lvtmdb { 0043 class PackageObject; 0044 } 0045 0046 namespace Codethink::lvtclp { 0047 0048 class LvtCompilationDatabase; 0049 0050 struct PackageHelper { 0051 std::string parentRepositoryName; 0052 std::string qualifiedName; 0053 std::string filePath; 0054 }; 0055 0056 struct RepositoryHelper { 0057 std::string qualifiedName; 0058 std::string path; 0059 }; 0060 0061 class LVTCLP_EXPORT FilesystemScanner { 0062 private: 0063 // PRIVATE TYPES 0064 struct Private; 0065 0066 // DATA 0067 std::unique_ptr<Private> d; 0068 0069 public: 0070 // CREATORS 0071 explicit FilesystemScanner(lvtmdb::ObjectStore& memDb, 0072 const std::filesystem::path& prefix, 0073 const LvtCompilationDatabase& cdb, 0074 std::function<void(const std::string&, long)> messageCallback, 0075 bool catchCodeAnalysisOutput, 0076 std::vector<std::filesystem::path> nonLakosianDirs, 0077 std::vector<llvm::GlobPattern> ignoreGlobs); 0078 // cdb and memDb must live at least as long as this FilesystemScanner 0079 0080 ~FilesystemScanner() noexcept; 0081 0082 // TYPES 0083 struct IncrementalResult { 0084 std::vector<std::string> newFiles; 0085 std::vector<std::string> modifiedFiles; 0086 std::vector<std::string> deletedFiles; 0087 0088 // In the main code we only care about files, but these are useful for 0089 // testing 0090 std::vector<std::string> newPkgs; 0091 std::vector<std::string> deletedPkgs; 0092 }; 0093 0094 // MANIPULATORS 0095 IncrementalResult scanCompilationDb(); 0096 // Scan compilation database: adding source files, components, 0097 // packages, and package groups to the database. 0098 0099 private: 0100 // MANIPULATORS 0101 void scanPath(const std::filesystem::path& path); 0102 void scanHeader(const std::filesystem::path& path); 0103 0104 void addSourceFile(const std::filesystem::path& path, const std::string& package); 0105 0106 std::string addSourcePackage(const std::filesystem::path& path, const std::string& parent, bool isStandalone); 0107 // returns the qualified name of the package 0108 0109 IncrementalResult addToDatabase(); 0110 0111 lvtmdb::PackageObject *addPackage(IncrementalResult& out, 0112 std::unordered_set<lvtmdb::PackageObject *>& existingPkgs, 0113 const std::string& qualifiedName, 0114 const std::string& parentName, 0115 const std::string& filePath, 0116 const std::string& repositoryName); 0117 }; 0118 0119 } // namespace Codethink::lvtclp 0120 0121 #endif // INCLUDED_CT_LVTCLP_FILESYSTEMSCANNER