summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/serve_api/remote/serve_api.hpp7
-rw-r--r--src/buildtool/serve_api/remote/source_tree_client.cpp31
-rw-r--r--src/buildtool/serve_api/remote/source_tree_client.hpp8
3 files changed, 46 insertions, 0 deletions
diff --git a/src/buildtool/serve_api/remote/serve_api.hpp b/src/buildtool/serve_api/remote/serve_api.hpp
index c2ad5353..219fe7ab 100644
--- a/src/buildtool/serve_api/remote/serve_api.hpp
+++ b/src/buildtool/serve_api/remote/serve_api.hpp
@@ -65,6 +65,13 @@ class ServeApi final {
return Instance().stc_->ServeDistdirTree(distfiles, sync_tree);
}
+ [[nodiscard]] static auto RetrieveTreeFromForeignFile(
+ const std::string& content,
+ const std::string& name,
+ bool executable) noexcept -> std::variant<bool, std::string> {
+ return Instance().stc_->ServeForeignFileTree(content, name, executable);
+ }
+
[[nodiscard]] static auto ContentInRemoteCAS(
std::string const& content) noexcept -> bool {
return Instance().stc_->ServeContent(content);
diff --git a/src/buildtool/serve_api/remote/source_tree_client.cpp b/src/buildtool/serve_api/remote/source_tree_client.cpp
index 0cb93a36..b7bfcecb 100644
--- a/src/buildtool/serve_api/remote/source_tree_client.cpp
+++ b/src/buildtool/serve_api/remote/source_tree_client.cpp
@@ -157,6 +157,37 @@ auto SourceTreeClient::ServeDistdirTree(
return response.tree(); // success
}
+auto SourceTreeClient::ServeForeignFileTree(const std::string& content,
+ const std::string& name,
+ bool executable) noexcept
+ -> result_t {
+ justbuild::just_serve::ServeDistdirTreeRequest request{};
+ auto* distfile = request.add_distfiles();
+ distfile->set_name(name);
+ distfile->set_content(content);
+ distfile->set_executable(executable);
+
+ grpc::ClientContext context;
+ justbuild::just_serve::ServeDistdirTreeResponse response;
+ grpc::Status status = stub_->ServeDistdirTree(&context, request, &response);
+
+ if (not status.ok()) {
+ LogStatus(&logger_, LogLevel::Debug, status);
+ return true; // fatal failure
+ }
+ if (response.status() !=
+ ::justbuild::just_serve::ServeDistdirTreeResponse::OK) {
+ logger_.Emit(LogLevel::Debug,
+ "ServeDistdirTree called for foreign file response "
+ "returned with {}",
+ static_cast<int>(response.status()));
+ return /*fatal = */ (
+ response.status() !=
+ ::justbuild::just_serve::ServeDistdirTreeResponse::NOT_FOUND);
+ }
+ return response.tree(); // success
+}
+
auto SourceTreeClient::ServeContent(std::string const& content) noexcept
-> bool {
justbuild::just_serve::ServeContentRequest request{};
diff --git a/src/buildtool/serve_api/remote/source_tree_client.hpp b/src/buildtool/serve_api/remote/source_tree_client.hpp
index 46b17081..2ce89e4b 100644
--- a/src/buildtool/serve_api/remote/source_tree_client.hpp
+++ b/src/buildtool/serve_api/remote/source_tree_client.hpp
@@ -79,6 +79,14 @@ class SourceTreeClient {
distfiles,
bool sync_tree) noexcept -> result_t;
+ /// \brief Retrieve the Git tree of a foreign-file directory, if all content
+ /// blobs are known to the end point and, as a side effect, make that tree
+ /// known to the serve endpoint.
+ [[nodiscard]] auto ServeForeignFileTree(const std::string& content,
+ const std::string& name,
+ bool executable) noexcept
+ -> result_t;
+
/// \brief Make a given content blob available in remote CAS, if known by
/// serve remote.
/// \param[in] content Hash of the archive content to look up.