Refactor FindPreludeFiles into InstallPaths (#4268)

From the driver's perspective, `FindPreludeFiles` is closely tied to
`compile`. This makes it difficult to refactor commands without
affecting the test dependencies on `FindPreludeFiles`. `InstallPaths`
seems like a decent home since it is responsible for the install
structure.

I'm switching to an `Error` return to allow callers to choose how to
handle it (e.g., in file tests, we typically don't want the direct error
stream).
This commit is contained in:
Jon Ross-Perkins
2024-09-04 22:22:48 +00:00
committed by GitHub
parent 1412ecd3f4
commit e382e6fd97
12 changed files with 124 additions and 83 deletions
+2 -13
View File
@@ -9,6 +9,7 @@
#include "testing/base/global_exe_path.h"
#include "testing/base/source_gen.h"
#include "toolchain/driver/driver.h"
#include "toolchain/install/install_paths_test_helpers.h"
namespace Carbon::Testing {
namespace {
@@ -22,19 +23,7 @@ class CompileBenchmark {
CompileBenchmark()
: installation_(InstallPaths::MakeForBazelRunfiles(GetExePath())),
driver_(fs_, &installation_, llvm::outs(), llvm::errs()) {
// Load the prelude into our VFS.
//
// TODO: Factor this and analogous code in file_test into a Driver helper.
auto prelude =
Driver::FindPreludeFiles(installation_.core_package(), llvm::errs());
CARBON_CHECK(!prelude.empty());
for (const auto& path : prelude) {
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> file =
llvm::MemoryBuffer::getFile(path);
CARBON_CHECK(file) << file.getError().message();
CARBON_CHECK(fs_.addFile(path, /*ModificationTime=*/0, std::move(*file)))
<< "Duplicate file: " << path;
}
AddPreludeFilesToVfs(installation_, &fs_);
}
// Setup a set of source files in the VFS for the driver. Each string input is