//===----------------- ModulesBuilder.cpp ------------------------*- C++-*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "ModulesBuilder.h" #include "Compiler.h" #include "support/Logger.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/FrontendActions.h" #include "clang/Serialization/ASTReader.h" namespace clang { namespace clangd { namespace { // Create a path to store module files. Generally it should be: // // {TEMP_DIRS}/clangd/module_files/{hashed-file-name}-%%-%%-%%-%%-%%-%%/. // // {TEMP_DIRS} is the temporary directory for the system, e.g., "/var/tmp" // or "C:/TEMP". // // '%%' means random value to make the generated path unique. // // \param MainFile is used to get the root of the project from global // compilation database. // // TODO: Move these module fils out of the temporary directory if the module // files are persistent. llvm::SmallString<256> getUniqueModuleFilesPath(PathRef MainFile) { … } // Get a unique module file path under \param ModuleFilesPrefix. std::string getModuleFilePath(llvm::StringRef ModuleName, PathRef ModuleFilesPrefix) { … } // FailedPrerequisiteModules - stands for the PrerequisiteModules which has // errors happened during the building process. class FailedPrerequisiteModules : public PrerequisiteModules { … }; struct ModuleFile { … }; bool IsModuleFileUpToDate( PathRef ModuleFilePath, const PrerequisiteModules &RequisiteModules) { … } bool IsModuleFilesUpToDate( llvm::SmallVector<PathRef> ModuleFilePaths, const PrerequisiteModules &RequisiteModules) { … } // StandalonePrerequisiteModules - stands for PrerequisiteModules for which all // the required modules are built successfully. All the module files // are owned by the StandalonePrerequisiteModules class. // // Any of the built module files won't be shared with other instances of the // class. So that we can avoid worrying thread safety. // // We don't need to worry about duplicated module names here since the standard // guarantees the module names should be unique to a program. class StandalonePrerequisiteModules : public PrerequisiteModules { … }; // Build a module file for module with `ModuleName`. The information of built // module file are stored in \param BuiltModuleFiles. llvm::Error buildModuleFile(llvm::StringRef ModuleName, const GlobalCompilationDatabase &CDB, const ThreadsafeFS &TFS, ProjectModules &MDB, PathRef ModuleFilesPrefix, StandalonePrerequisiteModules &BuiltModuleFiles) { … } } // namespace std::unique_ptr<PrerequisiteModules> ModulesBuilder::buildPrerequisiteModulesFor(PathRef File, const ThreadsafeFS &TFS) const { … } bool StandalonePrerequisiteModules::canReuse( const CompilerInvocation &CI, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) const { … } } // namespace clangd } // namespace clang