forked from carbon-language/carbon-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor FindPreludeFiles into InstallPaths (carbon-language#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).
- Loading branch information
Showing
12 changed files
with
124 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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.FindPreludeFiles(); | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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 | ||
|
||
#ifndef CARBON_TOOLCHAIN_INSTALL_INSTALL_PATHS_TEST_HELPERS_H_ | ||
#define CARBON_TOOLCHAIN_INSTALL_INSTALL_PATHS_TEST_HELPERS_H_ | ||
|
||
#include "llvm/Support/VirtualFileSystem.h" | ||
#include "toolchain/install/install_paths.h" | ||
|
||
namespace Carbon::Testing { | ||
|
||
// Prepares the VFS with prelude files from the real filesystem. | ||
auto AddPreludeFilesToVfs(InstallPaths install_paths, | ||
llvm::vfs::InMemoryFileSystem* vfs) -> void; | ||
|
||
} // namespace Carbon::Testing | ||
|
||
#endif // CARBON_TOOLCHAIN_INSTALL_INSTALL_PATHS_TEST_HELPERS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters