install_paths_test_helpers.cpp 1.1 KB

123456789101112131415161718192021222324252627282930
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/install/install_paths_test_helpers.h"
  5. #include "testing/base/global_exe_path.h"
  6. namespace Carbon::Testing {
  7. // Prepares the VFS with prelude files from the real filesystem. Primarily for
  8. // tests.
  9. auto AddPreludeFilesToVfs(
  10. InstallPaths install_paths,
  11. llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>& vfs) -> void {
  12. // Load the prelude into the test VFS.
  13. auto real_fs = llvm::vfs::getRealFileSystem();
  14. auto prelude = install_paths.ReadPreludeManifest();
  15. CARBON_CHECK(prelude.ok(), "{0}", prelude.error());
  16. for (const auto& path : *prelude) {
  17. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> file =
  18. real_fs->getBufferForFile(path);
  19. CARBON_CHECK(file, "Error getting file: {0}", file.getError().message());
  20. bool added = vfs->addFile(path, /*ModificationTime=*/0, std::move(*file));
  21. CARBON_CHECK(added, "Duplicate file: {0}", path);
  22. }
  23. }
  24. } // namespace Carbon::Testing