summaryrefslogtreecommitdiff
path: root/src/other_tools/just_mr/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/other_tools/just_mr/utils.cpp')
-rw-r--r--src/other_tools/just_mr/utils.cpp94
1 files changed, 0 insertions, 94 deletions
diff --git a/src/other_tools/just_mr/utils.cpp b/src/other_tools/just_mr/utils.cpp
index be0e841e..7e99eb43 100644
--- a/src/other_tools/just_mr/utils.cpp
+++ b/src/other_tools/just_mr/utils.cpp
@@ -14,102 +14,8 @@
#include "src/other_tools/just_mr/utils.hpp"
-#include "src/buildtool/file_system/file_storage.hpp"
-#include "src/buildtool/storage/storage.hpp"
-#include "src/utils/cpp/path.hpp"
-
namespace JustMR::Utils {
-auto GetGitRoot(JustMR::PathsPtr const& just_mr_paths,
- std::string const& repo_url) noexcept -> std::filesystem::path {
- if (just_mr_paths->git_checkout_locations.contains(repo_url)) {
- return std::filesystem::absolute(ToNormalPath(std::filesystem::path{
- just_mr_paths->git_checkout_locations[repo_url]
- .get<std::string>()}));
- }
- auto repo_url_as_path = std::filesystem::absolute(
- ToNormalPath(std::filesystem::path(repo_url)));
- if (not repo_url_as_path.empty() and
- FileSystemManager::IsAbsolutePath(repo_url_as_path) and
- FileSystemManager::IsDirectory(repo_url_as_path)) {
- return repo_url_as_path;
- }
- return StorageConfig::GitRoot();
-}
-
-auto CreateTypedTmpDir(std::string const& type) noexcept -> TmpDirPtr {
- // try to create parent dir
- auto parent_path =
- StorageConfig::GenerationCacheRoot(0) / "tmp-workspaces" / type;
- return TmpDir::Create(parent_path);
-}
-
-auto GetCommitTreeIDFile(std::string const& commit) noexcept
- -> std::filesystem::path {
- return StorageConfig::BuildRoot() / "commit-tree-map" / commit;
-}
-
-auto GetArchiveTreeIDFile(std::string const& repo_type,
- std::string const& content) noexcept
- -> std::filesystem::path {
- return StorageConfig::BuildRoot() / "tree-map" / repo_type / content;
-}
-
-auto GetDistdirTreeIDFile(std::string const& content) noexcept
- -> std::filesystem::path {
- return StorageConfig::BuildRoot() / "distfiles-tree-map" / content;
-}
-
-auto GetResolvedTreeIDFile(std::string const& tree_hash,
- PragmaSpecial const& pragma_special) noexcept
- -> std::filesystem::path {
- return StorageConfig::BuildRoot() / "special-tree-map" /
- kPragmaSpecialInverseMap.at(pragma_special) / tree_hash;
-}
-
-auto WriteTreeIDFile(std::filesystem::path const& tree_id_file,
- std::string const& tree_id) noexcept -> bool {
- // needs to be done safely, so use the rename trick
- auto tmp_dir = TmpDir::Create(tree_id_file.parent_path());
- if (not tmp_dir) {
- Logger::Log(LogLevel::Error,
- "could not create tmp dir for writing tree id file {}",
- tree_id_file.string());
- return false;
- }
- std::filesystem::path tmp_file{tmp_dir->GetPath() / "tmp_file"};
- if (not FileSystemManager::WriteFile(tree_id, tmp_file)) {
- Logger::Log(LogLevel::Error, "could not create tmp tree id file");
- return false;
- }
- return FileSystemManager::Rename(tmp_file.string(), tree_id_file);
-}
-
-auto AddToCAS(std::string const& data) noexcept
- -> std::optional<std::filesystem::path> {
- // get file CAS instance
- auto const& cas = Storage::Instance().CAS();
- // write to cas
- auto digest = cas.StoreBlob(data);
- if (digest) {
- return cas.BlobPath(*digest, /*is_executable=*/false);
- }
- return std::nullopt;
-}
-
-void AddDistfileToCAS(std::filesystem::path const& distfile,
- JustMR::PathsPtr const& just_mr_paths) noexcept {
- auto const& cas = Storage::Instance().CAS();
- for (auto const& dirpath : just_mr_paths->distdirs) {
- auto candidate = dirpath / distfile;
- if (FileSystemManager::Exists(candidate)) {
- // try to add to CAS
- [[maybe_unused]] auto digest =
- cas.StoreBlob(candidate, /*is_executable=*/false);
- }
- }
-}
-
// NOLINTNEXTLINE(misc-no-recursion)
auto ResolveRepo(ExpressionPtr const& repo_desc,
ExpressionPtr const& repos,