mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 06:54:44 +01:00
Add support for forcing a rebuild of runtimes (#6537)
This is useful during development, testing, and will also be useful for a more bazel-integrated build step. Also clean up the path management when creating runtimes: - Teach the main runtimes code to handle making a relative path absolute - Separate out methods for _creating_ a runtimes tree vs. opening an existing one. Teach the creation path to create intervening directories as needed. This provides a more useful and less surprising set of behaviors. Last but not least, also clean up a bunch of comments in the runtimes cache code to talk generically about components -- these APIs are no longer specific to the resource directory.
This commit is contained in:
@@ -28,11 +28,23 @@
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto Runtimes::Make(std::filesystem::path path, llvm::raw_ostream* vlog_stream)
|
||||
-> ErrorOr<Runtimes> {
|
||||
static auto MakeAbsolute(std::filesystem::path path)
|
||||
-> ErrorOr<std::filesystem::path> {
|
||||
if (!path.is_absolute()) {
|
||||
return Error("Runtimes require an absolute path");
|
||||
std::error_code ec;
|
||||
path = std::filesystem::absolute(path, ec);
|
||||
if (ec) {
|
||||
return Error(llvm::formatv("Unable to compute an absolute path: {0}",
|
||||
ec.message()));
|
||||
}
|
||||
}
|
||||
return std::move(path);
|
||||
}
|
||||
|
||||
auto Runtimes::OpenExisting(std::filesystem::path path,
|
||||
llvm::raw_ostream* vlog_stream)
|
||||
-> ErrorOr<Runtimes> {
|
||||
CARBON_ASSIGN_OR_RETURN(path, MakeAbsolute(std::move(path)));
|
||||
|
||||
CARBON_ASSIGN_OR_RETURN(
|
||||
Filesystem::Dir dir,
|
||||
@@ -40,6 +52,15 @@ auto Runtimes::Make(std::filesystem::path path, llvm::raw_ostream* vlog_stream)
|
||||
return Runtimes(std::move(path), std::move(dir), {}, {}, vlog_stream);
|
||||
}
|
||||
|
||||
auto Runtimes::Make(std::filesystem::path path, llvm::raw_ostream* vlog_stream)
|
||||
-> ErrorOr<Runtimes> {
|
||||
CARBON_ASSIGN_OR_RETURN(path, MakeAbsolute(std::move(path)));
|
||||
|
||||
CARBON_ASSIGN_OR_RETURN(Filesystem::Dir dir,
|
||||
Filesystem::Cwd().CreateDirectories(path));
|
||||
return Runtimes(std::move(path), std::move(dir), {}, {}, vlog_stream);
|
||||
}
|
||||
|
||||
auto Runtimes::Destroy() -> void {
|
||||
// Release the lock on the runtimes and close the lock file.
|
||||
flock_ = {};
|
||||
@@ -66,6 +87,11 @@ auto Runtimes::Build(Component component)
|
||||
return BuildImpl(component, BuildLockDeadline, BuildLockPollInterval);
|
||||
}
|
||||
|
||||
auto Runtimes::Remove(Component component) -> ErrorOr<Success> {
|
||||
CARBON_RETURN_IF_ERROR(base_dir_.Rmtree(ComponentPath(component)));
|
||||
return Success();
|
||||
}
|
||||
|
||||
auto Runtimes::BuildImpl(Component component, Filesystem::Duration deadline,
|
||||
Filesystem::Duration poll_interval)
|
||||
-> ErrorOr<std::variant<std::filesystem::path, Builder>> {
|
||||
|
||||
Reference in New Issue
Block a user