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
@@ -10,6 +10,7 @@
#include "common/set.h"
#include "testing/base/global_exe_path.h"
#include "toolchain/driver/driver.h"
#include "toolchain/install/install_paths_test_helpers.h"
namespace Carbon::Testing {
namespace {
@@ -147,19 +148,7 @@ auto TestCompile(llvm::StringRef source) -> bool {
InstallPaths::MakeForBazelRunfiles(Testing::GetExePath()));
Driver 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);
fs.addFile("test.carbon", /*ModificationTime=*/0,
llvm::MemoryBuffer::getMemBuffer(source));