install_paths_test_helpers.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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 <memory>
  6. #include <utility>
  7. #include "testing/base/global_exe_path.h"
  8. namespace Carbon::Testing {
  9. // Prepares the VFS with prelude files from the real filesystem. Primarily for
  10. // tests.
  11. auto AddPreludeFilesToVfs(
  12. InstallPaths install_paths,
  13. llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>& vfs) -> void {
  14. // Load the prelude into the test VFS.
  15. auto real_fs = llvm::vfs::getRealFileSystem();
  16. auto prelude = install_paths.ReadPreludeManifest();
  17. CARBON_CHECK(prelude.ok(), "{0}", prelude.error());
  18. for (const auto& path : *prelude) {
  19. llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> file =
  20. real_fs->getBufferForFile(path);
  21. CARBON_CHECK(file, "Error getting file: {0}", file.getError().message());
  22. bool added = vfs->addFile(path, /*ModificationTime=*/0, std::move(*file));
  23. CARBON_CHECK(added, "Duplicate file: {0}", path);
  24. }
  25. }
  26. } // namespace Carbon::Testing