Path: blob/main/contrib/llvm-project/clang/lib/Serialization/ModuleCache.cpp
213764 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "clang/Serialization/ModuleCache.h"910#include "clang/Serialization/InMemoryModuleCache.h"11#include "clang/Serialization/ModuleFile.h"12#include "llvm/Support/FileSystem.h"13#include "llvm/Support/LockFileManager.h"14#include "llvm/Support/Path.h"1516using namespace clang;1718namespace {19class CrossProcessModuleCache : public ModuleCache {20InMemoryModuleCache InMemory;2122public:23void prepareForGetLock(StringRef ModuleFilename) override {24// FIXME: Do this in LockFileManager and only if the directory doesn't25// exist.26StringRef Dir = llvm::sys::path::parent_path(ModuleFilename);27llvm::sys::fs::create_directories(Dir);28}2930std::unique_ptr<llvm::AdvisoryLock>31getLock(StringRef ModuleFilename) override {32return std::make_unique<llvm::LockFileManager>(ModuleFilename);33}3435std::time_t getModuleTimestamp(StringRef ModuleFilename) override {36std::string TimestampFilename =37serialization::ModuleFile::getTimestampFilename(ModuleFilename);38llvm::sys::fs::file_status Status;39if (llvm::sys::fs::status(TimestampFilename, Status) != std::error_code{})40return 0;41return llvm::sys::toTimeT(Status.getLastModificationTime());42}4344void updateModuleTimestamp(StringRef ModuleFilename) override {45// Overwrite the timestamp file contents so that file's mtime changes.46std::error_code EC;47llvm::raw_fd_ostream OS(48serialization::ModuleFile::getTimestampFilename(ModuleFilename), EC,49llvm::sys::fs::OF_TextWithCRLF);50if (EC)51return;52OS << "Timestamp file\n";53OS.close();54OS.clear_error(); // Avoid triggering a fatal error.55}5657InMemoryModuleCache &getInMemoryModuleCache() override { return InMemory; }58const InMemoryModuleCache &getInMemoryModuleCache() const override {59return InMemory;60}61};62} // namespace6364IntrusiveRefCntPtr<ModuleCache> clang::createCrossProcessModuleCache() {65return llvm::makeIntrusiveRefCnt<CrossProcessModuleCache>();66}676869