Files
carbon-lang/toolchain/install/install_paths_test_helpers.cpp
T
Jon Ross-Perkins 6311552fcc Generate and use a manifest for prelude files. (#4291)
This removes the directory crawl because bazel doesn't remove files from
execroot when the rule generating them would no longer generate them.

Fixes #4288
2024-09-10 20:59:49 +00:00

30 lines
1.1 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/install/install_paths_test_helpers.h"
#include "testing/base/global_exe_path.h"
namespace Carbon::Testing {
// Prepares the VFS with prelude files from the real filesystem. Primarily for
// tests.
auto AddPreludeFilesToVfs(InstallPaths install_paths,
llvm::vfs::InMemoryFileSystem* vfs) -> void {
// Load the prelude into the test VFS.
auto real_fs = llvm::vfs::getRealFileSystem();
auto prelude = install_paths.ReadPreludeManifest();
CARBON_CHECK(prelude.ok()) << prelude.error();
for (const auto& path : *prelude) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> file =
real_fs->getBufferForFile(path);
CARBON_CHECK(file) << "Error getting file: " << file.getError().message();
bool added = vfs->addFile(path, /*ModificationTime=*/0, std::move(*file));
CARBON_CHECK(added) << "Duplicate file: " << path;
}
}
} // namespace Carbon::Testing