summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/other_tools/ops_maps/TARGETS3
-rw-r--r--src/other_tools/ops_maps/content_cas_map.cpp29
-rw-r--r--src/other_tools/utils/TARGETS11
-rw-r--r--src/other_tools/utils/content.hpp49
4 files changed, 62 insertions, 30 deletions
diff --git a/src/other_tools/ops_maps/TARGETS b/src/other_tools/ops_maps/TARGETS
index 9ca5e5f4..1baf11e5 100644
--- a/src/other_tools/ops_maps/TARGETS
+++ b/src/other_tools/ops_maps/TARGETS
@@ -66,8 +66,7 @@
]
, "stage": ["src", "other_tools", "ops_maps"]
, "private-deps":
- [ ["src/other_tools/utils", "curl_easy_handle"]
- , ["src/buildtool/crypto", "hasher"]
+ [ ["src/other_tools/utils", "content"]
, ["src/buildtool/execution_api/local", "local"]
, ["src/buildtool/file_system", "file_storage"]
, ["src/buildtool/storage", "fs_utils"]
diff --git a/src/other_tools/ops_maps/content_cas_map.cpp b/src/other_tools/ops_maps/content_cas_map.cpp
index b796dc04..04b3d036 100644
--- a/src/other_tools/ops_maps/content_cas_map.cpp
+++ b/src/other_tools/ops_maps/content_cas_map.cpp
@@ -14,39 +14,12 @@
#include "src/other_tools/ops_maps/content_cas_map.hpp"
-#include "src/buildtool/crypto/hasher.hpp"
#include "src/buildtool/file_system/file_storage.hpp"
#include "src/buildtool/storage/fs_utils.hpp"
#include "src/buildtool/storage/storage.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress.hpp"
#include "src/other_tools/just_mr/progress_reporting/statistics.hpp"
-#include "src/other_tools/utils/curl_easy_handle.hpp"
-
-namespace {
-
-/// \brief Fetches a file from the internet and stores its content in memory.
-/// Returns the content.
-[[nodiscard]] auto NetworkFetch(std::string const& fetch_url,
- CAInfoPtr const& ca_info) noexcept
- -> std::optional<std::string> {
- auto curl_handle =
- CurlEasyHandle::Create(ca_info->no_ssl_verify, ca_info->ca_bundle);
- if (not curl_handle) {
- return std::nullopt;
- }
- return curl_handle->DownloadToString(fetch_url);
-}
-
-template <Hasher::HashType type>
-[[nodiscard]] auto GetContentHash(std::string const& data) noexcept
- -> std::string {
- Hasher hasher{type};
- hasher.Update(data);
- auto digest = std::move(hasher).Finalize();
- return digest.HexString();
-}
-
-} // namespace
+#include "src/other_tools/utils/content.hpp"
auto CreateContentCASMap(LocalPathsPtr const& just_mr_paths,
CAInfoPtr const& ca_info,
diff --git a/src/other_tools/utils/TARGETS b/src/other_tools/utils/TARGETS
index df08d551..35685ba7 100644
--- a/src/other_tools/utils/TARGETS
+++ b/src/other_tools/utils/TARGETS
@@ -28,4 +28,15 @@
, "stage": ["src", "other_tools", "utils"]
, "private-deps": [["src/buildtool/logging", "logging"], ["", "libcurl"]]
}
+, "content":
+ { "type": ["@", "rules", "CC", "library"]
+ , "name": ["content"]
+ , "hdrs": ["content.hpp"]
+ , "deps":
+ [ "curl_easy_handle"
+ , ["src/buildtool/common", "user_structs"]
+ , ["src/buildtool/crypto", "hasher"]
+ ]
+ , "stage": ["src", "other_tools", "utils"]
+ }
}
diff --git a/src/other_tools/utils/content.hpp b/src/other_tools/utils/content.hpp
new file mode 100644
index 00000000..e7cb7501
--- /dev/null
+++ b/src/other_tools/utils/content.hpp
@@ -0,0 +1,49 @@
+// Copyright 2023 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef INCLUDED_SRC_OTHER_TOOLS_UTILS_CONTENT_HPP
+#define INCLUDED_SRC_OTHER_TOOLS_UTILS_CONTENT_HPP
+
+#include <optional>
+#include <string>
+
+#include "src/buildtool/common/user_structs.hpp"
+#include "src/buildtool/crypto/hasher.hpp"
+#include "src/other_tools/utils/curl_easy_handle.hpp"
+
+// Utilities related to the content of an archive
+
+/// \brief Fetches a file from the internet and stores its content in memory.
+/// Returns the content.
+[[nodiscard]] static auto NetworkFetch(std::string const& fetch_url,
+ CAInfoPtr const& ca_info) noexcept
+ -> std::optional<std::string> {
+ auto curl_handle =
+ CurlEasyHandle::Create(ca_info->no_ssl_verify, ca_info->ca_bundle);
+ if (not curl_handle) {
+ return std::nullopt;
+ }
+ return curl_handle->DownloadToString(fetch_url);
+}
+
+template <Hasher::HashType type>
+[[nodiscard]] static auto GetContentHash(std::string const& data) noexcept
+ -> std::string {
+ Hasher hasher{type};
+ hasher.Update(data);
+ auto digest = std::move(hasher).Finalize();
+ return digest.HexString();
+}
+
+#endif // INCLUDED_SRC_OTHER_TOOLS_UTILS_CONTENT_HPP