summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/serve_api/remote/TARGETS7
-rw-r--r--src/buildtool/serve_api/remote/serve_api.cpp10
-rw-r--r--src/buildtool/serve_api/remote/serve_api.hpp8
-rw-r--r--src/buildtool/serve_api/remote/source_tree_client.cpp72
-rw-r--r--src/buildtool/serve_api/remote/source_tree_client.hpp18
5 files changed, 113 insertions, 2 deletions
diff --git a/src/buildtool/serve_api/remote/TARGETS b/src/buildtool/serve_api/remote/TARGETS
index 9b038440..2cd24545 100644
--- a/src/buildtool/serve_api/remote/TARGETS
+++ b/src/buildtool/serve_api/remote/TARGETS
@@ -12,6 +12,7 @@
, "srcs": ["source_tree_client.cpp"]
, "deps":
[ ["src/buildtool/common/remote", "port"]
+ , ["src/buildtool/file_system/symlinks_map", "pragma_special"]
, ["src/buildtool/logging", "logging"]
]
, "proto": [["src/buildtool/serve_api/serve_service", "just_serve_proto"]]
@@ -23,7 +24,11 @@
, "name": ["serve_api"]
, "hdrs": ["serve_api.hpp"]
, "srcs": ["serve_api.cpp"]
- , "deps": [["src/buildtool/common/remote", "port"], "source_tree_client"]
+ , "deps":
+ [ ["src/buildtool/common/remote", "port"]
+ , ["src/buildtool/file_system/symlinks_map", "pragma_special"]
+ , "source_tree_client"
+ ]
, "stage": ["src", "buildtool", "serve_api", "remote"]
}
}
diff --git a/src/buildtool/serve_api/remote/serve_api.cpp b/src/buildtool/serve_api/remote/serve_api.cpp
index 0b0493d7..0c5c531c 100644
--- a/src/buildtool/serve_api/remote/serve_api.cpp
+++ b/src/buildtool/serve_api/remote/serve_api.cpp
@@ -29,3 +29,13 @@ auto ServeApi::RetrieveTreeFromCommit(std::string const& commit,
-> std::optional<std::string> {
return stc_->ServeCommitTree(commit, subdir, sync_tree);
}
+
+auto ServeApi::RetrieveTreeFromArchive(
+ std::string const& content,
+ std::string const& archive_type,
+ std::string const& subdir,
+ std::optional<PragmaSpecial> const& resolve_symlinks,
+ bool sync_tree) -> std::optional<std::string> {
+ return stc_->ServeArchiveTree(
+ content, archive_type, subdir, resolve_symlinks, sync_tree);
+}
diff --git a/src/buildtool/serve_api/remote/serve_api.hpp b/src/buildtool/serve_api/remote/serve_api.hpp
index d206b416..a0d50ea9 100644
--- a/src/buildtool/serve_api/remote/serve_api.hpp
+++ b/src/buildtool/serve_api/remote/serve_api.hpp
@@ -20,6 +20,7 @@
#include <string>
#include "src/buildtool/common/remote/port.hpp"
+#include "src/buildtool/file_system/symlinks_map/pragma_special.hpp"
#include "src/buildtool/serve_api/remote/source_tree_client.hpp"
class ServeApi final {
@@ -41,6 +42,13 @@ class ServeApi final {
bool sync_tree = false)
-> std::optional<std::string>;
+ [[nodiscard]] auto RetrieveTreeFromArchive(
+ std::string const& content,
+ std::string const& archive_type = "archive",
+ std::string const& subdir = ".",
+ std::optional<PragmaSpecial> const& resolve_symlinks = std::nullopt,
+ bool sync_tree = false) -> std::optional<std::string>;
+
private:
// source tree service client
std::unique_ptr<SourceTreeClient> stc_;
diff --git a/src/buildtool/serve_api/remote/source_tree_client.cpp b/src/buildtool/serve_api/remote/source_tree_client.cpp
index 2026d80d..a2ff930f 100644
--- a/src/buildtool/serve_api/remote/source_tree_client.cpp
+++ b/src/buildtool/serve_api/remote/source_tree_client.cpp
@@ -16,6 +16,46 @@
#include "src/buildtool/common/remote/client_common.hpp"
+namespace {
+
+auto StringToArchiveType(std::string const& type)
+ -> justbuild::just_serve::ServeArchiveTreeRequest_ArchiveType {
+ using ServeArchiveType =
+ justbuild::just_serve::ServeArchiveTreeRequest_ArchiveType;
+ return type == "zip"
+ ? ServeArchiveType::ServeArchiveTreeRequest_ArchiveType_ZIP
+ : ServeArchiveType::ServeArchiveTreeRequest_ArchiveType_TAR;
+}
+
+auto PragmaSpecialToSymlinksResolve(
+ std::optional<PragmaSpecial> const& resolve_symlinks)
+ -> justbuild::just_serve::ServeArchiveTreeRequest_SymlinksResolve {
+ using ServeSymlinksResolve =
+ justbuild::just_serve::ServeArchiveTreeRequest_SymlinksResolve;
+ if (not resolve_symlinks) {
+ return ServeSymlinksResolve::
+ ServeArchiveTreeRequest_SymlinksResolve_NONE;
+ }
+ switch (resolve_symlinks.value()) {
+ case PragmaSpecial::Ignore: {
+ return ServeSymlinksResolve::
+ ServeArchiveTreeRequest_SymlinksResolve_IGNORE;
+ }
+ case PragmaSpecial::ResolvePartially: {
+ return ServeSymlinksResolve::
+ ServeArchiveTreeRequest_SymlinksResolve_PARTIAL;
+ }
+ case PragmaSpecial::ResolveCompletely: {
+ return ServeSymlinksResolve::
+ ServeArchiveTreeRequest_SymlinksResolve_COMPLETE;
+ }
+ }
+ // default return, to avoid [-Werror=return-type] error
+ return ServeSymlinksResolve::ServeArchiveTreeRequest_SymlinksResolve_NONE;
+}
+
+} // namespace
+
SourceTreeClient::SourceTreeClient(std::string const& server,
Port port) noexcept {
stub_ = justbuild::just_serve::SourceTree::NewStub(
@@ -48,3 +88,35 @@ auto SourceTreeClient::ServeCommitTree(std::string const& commit_id,
}
return response.tree();
}
+
+auto SourceTreeClient::ServeArchiveTree(
+ std::string const& content,
+ std::string const& archive_type,
+ std::string const& subdir,
+ std::optional<PragmaSpecial> const& resolve_symlinks,
+ bool sync_tree) -> std::optional<std::string> {
+ justbuild::just_serve::ServeArchiveTreeRequest request{};
+ request.set_content(content);
+ request.set_archive_type(StringToArchiveType(archive_type));
+ request.set_subdir(subdir);
+ request.set_resolve_symlinks(
+ PragmaSpecialToSymlinksResolve(resolve_symlinks));
+ request.set_sync_tree(sync_tree);
+
+ grpc::ClientContext context;
+ justbuild::just_serve::ServeArchiveTreeResponse response;
+ grpc::Status status = stub_->ServeArchiveTree(&context, request, &response);
+
+ if (not status.ok()) {
+ LogStatus(&logger_, LogLevel::Debug, status);
+ return std::nullopt;
+ }
+ if (response.status() !=
+ ::justbuild::just_serve::ServeArchiveTreeResponse::OK) {
+ logger_.Emit(LogLevel::Debug,
+ "ServeArchiveTree response returned with {}",
+ static_cast<int>(response.status()));
+ return std::nullopt;
+ }
+ return response.tree();
+}
diff --git a/src/buildtool/serve_api/remote/source_tree_client.hpp b/src/buildtool/serve_api/remote/source_tree_client.hpp
index 1b557163..2a7f1ec2 100644
--- a/src/buildtool/serve_api/remote/source_tree_client.hpp
+++ b/src/buildtool/serve_api/remote/source_tree_client.hpp
@@ -20,6 +20,7 @@
#include "justbuild/just_serve/just_serve.grpc.pb.h"
#include "src/buildtool/common/remote/port.hpp"
+#include "src/buildtool/file_system/symlinks_map/pragma_special.hpp"
#include "src/buildtool/logging/logger.hpp"
/// Implements client side for SourceTree service defined in:
@@ -31,13 +32,28 @@ class SourceTreeClient {
/// \brief Retrieve the Git tree of a given commit, if known by the remote.
/// \param[in] commit_id Hash of the Git commit to look up.
/// \param[in] subdir Relative path of the tree inside commit.
- /// \param[in] sync_tree Sync tree to the remote-execution end point
+ /// \param[in] sync_tree Sync tree to the remote-execution endpoint.
/// \returns The hash of the tree if commit found, nullopt otherwise.
[[nodiscard]] auto ServeCommitTree(std::string const& commit_id,
std::string const& subdir,
bool sync_tree)
-> std::optional<std::string>;
+ /// \brief Retrieve the Git tree of an archive content, if known by remote.
+ /// \param[in] content Hash of the archive content to look up.
+ /// \param[in] archive_type Type of archive ("archive"|"zip").
+ /// \param[in] subdir Relative path of the tree inside archive.
+ /// \param[in] resolve_symlinks Optional enum to state how symlinks in the
+ /// archive should be handled if the tree has to be actually computed.
+ /// \param[in] sync_tree Sync tree to the remote-execution endpoint.
+ /// \returns The hash of the tree if content blob found, nullopt otherwise.
+ [[nodiscard]] auto ServeArchiveTree(
+ std::string const& content,
+ std::string const& archive_type,
+ std::string const& subdir,
+ std::optional<PragmaSpecial> const& resolve_symlinks,
+ bool sync_tree) -> std::optional<std::string>;
+
private:
std::unique_ptr<justbuild::just_serve::SourceTree::Stub> stub_;
Logger logger_{"RemoteSourceTreeClient"};