summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/main/main.cpp19
-rw-r--r--src/buildtool/storage/config.hpp40
-rw-r--r--src/other_tools/just_mr/TARGETS1
-rw-r--r--src/other_tools/just_mr/main.cpp11
4 files changed, 48 insertions, 23 deletions
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index a3be587b..9f10b8bc 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -110,10 +110,10 @@ void SetupLogging(LogArguments const& clargs) {
[[nodiscard]] auto CreateStorageConfig(
EndpointArguments const& eargs,
+ bool is_compatible,
std::optional<ServerAddress> const& remote_address = std::nullopt,
- std::map<std::string, std::string> const& remote_platform_properties = {},
- std::vector<std::pair<std::map<std::string, std::string>,
- ServerAddress>> const& remote_dispatch = {}) noexcept
+ ExecutionProperties const& remote_platform_properties = {},
+ std::vector<DispatchEndpoint> const& remote_dispatch = {}) noexcept
-> std::optional<StorageConfig> {
StorageConfig::Builder builder;
if (eargs.local_root.has_value()) {
@@ -122,6 +122,8 @@ void SetupLogging(LogArguments const& clargs) {
auto config =
builder
+ .SetHashType(is_compatible ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native)
.SetRemoteExecutionArgs(
remote_address, remote_platform_properties, remote_dispatch)
.Build();
@@ -800,7 +802,8 @@ auto main(int argc, char* argv[]) -> int {
if (arguments.cmd == SubCommand::kGc) {
// Set up storage for GC, as we have all the config args we need.
- auto const storage_config = CreateStorageConfig(arguments.endpoint);
+ auto const storage_config = CreateStorageConfig(
+ arguments.endpoint, Compatibility::IsCompatible());
if (not storage_config) {
return kExitFailure;
}
@@ -828,7 +831,8 @@ auto main(int argc, char* argv[]) -> int {
RemoteExecutionConfig remote_exec_config{};
// Set up storage for local execution.
- auto const storage_config = CreateStorageConfig(arguments.endpoint);
+ auto const storage_config = CreateStorageConfig(
+ arguments.endpoint, Compatibility::IsCompatible());
if (not storage_config) {
return kExitFailure;
}
@@ -885,6 +889,7 @@ auto main(int argc, char* argv[]) -> int {
// Set up storage for serve operation.
auto const storage_config =
CreateStorageConfig(arguments.endpoint,
+ Compatibility::IsCompatible(),
remote_exec_config->remote_address,
remote_exec_config->platform_properties,
remote_exec_config->dispatch);
@@ -950,13 +955,15 @@ auto main(int argc, char* argv[]) -> int {
// correctly-sharded target cache.
auto const storage_config =
CreateStorageConfig(arguments.endpoint,
+ Compatibility::IsCompatible(),
remote_exec_config->remote_address,
remote_exec_config->platform_properties,
remote_exec_config->dispatch);
#else
// For bootstrapping the TargetCache sharding is not needed, so we can
// default all execution arguments.
- auto const storage_config = CreateStorageConfig(arguments.endpoint);
+ auto const storage_config = CreateStorageConfig(
+ arguments.endpoint, Compatibility::IsCompatible());
#endif // BOOTSTRAP_BUILD_TOOL
if (not storage_config) {
return kExitFailure;
diff --git a/src/buildtool/storage/config.hpp b/src/buildtool/storage/config.hpp
index a6213074..5861977e 100644
--- a/src/buildtool/storage/config.hpp
+++ b/src/buildtool/storage/config.hpp
@@ -65,6 +65,8 @@ struct StorageConfig final {
// Number of total storage generations (default: two generations).
std::size_t const num_generations = 2;
+ HashFunction const hash_function{HashFunction::JustHash::Native};
+
// Hash of the execution backend description
std::string const backend_description_id = DefaultBackendDescriptionId();
@@ -154,11 +156,10 @@ struct StorageConfig final {
return dir / (is_compatible ? "compatible-sha256" : "git-sha1");
};
- [[nodiscard]] static auto DefaultBackendDescriptionId() noexcept
- -> std::string {
+ [[nodiscard]] auto DefaultBackendDescriptionId() noexcept -> std::string {
try {
return ArtifactDigest::Create<ObjectType::File>(
- HashFunction::Instance(),
+ hash_function,
DescribeBackend(std::nullopt, {}, {}).value())
.hash();
} catch (...) {
@@ -180,11 +181,16 @@ class StorageConfig::Builder final {
return *this;
}
- auto SetRemoteExecutionArgs(
- std::optional<ServerAddress> address,
- std::map<std::string, std::string> properties,
- std::vector<std::pair<std::map<std::string, std::string>,
- ServerAddress>> dispatch) noexcept -> Builder& {
+ /// \brief Specify the type of the hash function
+ auto SetHashType(HashFunction::JustHash value) noexcept -> Builder& {
+ hash_type_ = value;
+ return *this;
+ }
+
+ auto SetRemoteExecutionArgs(std::optional<ServerAddress> address,
+ ExecutionProperties properties,
+ std::vector<DispatchEndpoint> dispatch) noexcept
+ -> Builder& {
remote_address_ = std::move(address);
remote_platform_properties_ = std::move(properties);
remote_dispatch_ = std::move(dispatch);
@@ -216,14 +222,19 @@ class StorageConfig::Builder final {
}
}
+ auto hash_function = default_config.hash_function;
+ if (hash_type_.has_value()) {
+ hash_function = HashFunction{*hash_type_};
+ }
+
// Hash the execution backend description
auto backend_description_id = default_config.backend_description_id;
auto desc = DescribeBackend(
remote_address_, remote_platform_properties_, remote_dispatch_);
if (desc) {
- backend_description_id = ArtifactDigest::Create<ObjectType::File>(
- HashFunction::Instance(), *desc)
- .hash();
+ backend_description_id =
+ ArtifactDigest::Create<ObjectType::File>(hash_function, *desc)
+ .hash();
}
else {
return unexpected{desc.error()};
@@ -232,18 +243,19 @@ class StorageConfig::Builder final {
return StorageConfig{
.build_root = std::move(build_root),
.num_generations = num_generations,
+ .hash_function = hash_function,
.backend_description_id = std::move(backend_description_id)};
}
private:
std::optional<std::filesystem::path> build_root_;
std::optional<std::size_t> num_generations_;
+ std::optional<HashFunction::JustHash> hash_type_;
// Fields for computing remote execution backend description
std::optional<ServerAddress> remote_address_;
- std::map<std::string, std::string> remote_platform_properties_;
- std::vector<std::pair<std::map<std::string, std::string>, ServerAddress>>
- remote_dispatch_;
+ ExecutionProperties remote_platform_properties_;
+ std::vector<DispatchEndpoint> remote_dispatch_;
};
#endif // INCLUDED_SRC_BUILDTOOL_STORAGE_CONFIG_HPP
diff --git a/src/other_tools/just_mr/TARGETS b/src/other_tools/just_mr/TARGETS
index 17e9b248..af4ef8df 100644
--- a/src/other_tools/just_mr/TARGETS
+++ b/src/other_tools/just_mr/TARGETS
@@ -25,6 +25,7 @@
, "setup"
, "setup_utils"
, "update"
+ , ["src/buildtool/crypto", "hash_function"]
]
, "stage": ["src", "other_tools", "just_mr"]
, "private-ldflags":
diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp
index f104e730..698a6ccb 100644
--- a/src/other_tools/just_mr/main.cpp
+++ b/src/other_tools/just_mr/main.cpp
@@ -28,6 +28,7 @@
#include "src/buildtool/build_engine/expression/configuration.hpp"
#include "src/buildtool/common/retry_cli.hpp"
#include "src/buildtool/compatibility/compatibility.hpp"
+#include "src/buildtool/crypto/hash_function.hpp"
#include "src/buildtool/file_system/git_context.hpp"
#include "src/buildtool/logging/log_config.hpp"
#include "src/buildtool/logging/log_level.hpp"
@@ -206,13 +207,16 @@ void SetupLogging(MultiRepoLogArguments const& clargs) {
}
}
-[[nodiscard]] auto CreateStorageConfig(
- MultiRepoCommonArguments const& args) noexcept
+[[nodiscard]] auto CreateStorageConfig(MultiRepoCommonArguments const& args,
+ bool is_compatible) noexcept
-> std::optional<StorageConfig> {
StorageConfig::Builder builder;
if (args.just_mr_paths->root.has_value()) {
builder.SetBuildRoot(*args.just_mr_paths->root);
}
+ builder.SetHashType(is_compatible ? HashFunction::JustHash::Compatible
+ : HashFunction::JustHash::Native);
+
// As just-mr does not require the TargetCache, we do not need to set any of
// the remote execution fields for the backend description.
auto config = builder.Build();
@@ -314,7 +318,8 @@ auto main(int argc, char* argv[]) -> int {
// Setup LocalStorageConfig to store the local_build_root properly
// and make the cas and git cache roots available
- auto storage_config = CreateStorageConfig(arguments.common);
+ auto storage_config = CreateStorageConfig(
+ arguments.common, Compatibility::IsCompatible());
if (not storage_config) {
Logger::Log(LogLevel::Error,
"Failed to configure local build root.");