summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2023-04-03 16:38:54 +0200
committerKlaus Aehlig <klaus.aehlig@huawei.com>2023-04-04 15:18:45 +0200
commit95b3fcb09e94ac9f114509b205903b25a2bbd3ba (patch)
tree1ba56457c5ecdb8b6959213dc2458dbb6688b517 /src
parent65b29dfc610d9393337c20e30f5b96e35dffebd0 (diff)
downloadjustbuild-95b3fcb09e94ac9f114509b205903b25a2bbd3ba.tar.gz
Make git root part of the storage config
In this way, we have the whole layout of the local build root consolidated in one place. Moreover, in this way, the location of the git root is also available to the build tool itself and can, e.g., be used as fallback CAS.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/storage/config.hpp5
-rw-r--r--src/other_tools/just_mr/utils.cpp6
-rw-r--r--src/other_tools/just_mr/utils.hpp3
-rw-r--r--src/other_tools/ops_maps/import_to_git_map.cpp28
-rw-r--r--src/other_tools/root_maps/TARGETS6
-rw-r--r--src/other_tools/root_maps/content_git_map.cpp47
-rw-r--r--src/other_tools/root_maps/distdir_git_map.cpp45
-rw-r--r--src/other_tools/root_maps/fpath_git_map.cpp3
-rw-r--r--src/other_tools/root_maps/tree_id_git_map.cpp53
9 files changed, 99 insertions, 97 deletions
diff --git a/src/buildtool/storage/config.hpp b/src/buildtool/storage/config.hpp
index e2964bb2..058aca88 100644
--- a/src/buildtool/storage/config.hpp
+++ b/src/buildtool/storage/config.hpp
@@ -110,6 +110,11 @@ class StorageConfig {
return BuildRoot() / "protocol-dependent";
}
+ /// \brief Directory for the git repository storing various roots
+ [[nodiscard]] static auto GitRoot() noexcept -> std::filesystem::path {
+ return BuildRoot() / "git";
+ }
+
/// \brief Root directory of specific storage generation for compatible and
/// non-compatible protocol types.
[[nodiscard]] static auto GenerationCacheRoot(std::size_t index) noexcept
diff --git a/src/other_tools/just_mr/utils.cpp b/src/other_tools/just_mr/utils.cpp
index ca891875..d95163fa 100644
--- a/src/other_tools/just_mr/utils.cpp
+++ b/src/other_tools/just_mr/utils.cpp
@@ -20,10 +20,6 @@
namespace JustMR::Utils {
-auto GetGitCacheRoot() noexcept -> std::filesystem::path {
- return StorageConfig::BuildRoot() / "git";
-}
-
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)) {
@@ -37,7 +33,7 @@ auto GetGitRoot(JustMR::PathsPtr const& just_mr_paths,
FileSystemManager::IsDirectory(repo_url_as_path)) {
return repo_url_as_path;
}
- return GetGitCacheRoot();
+ return StorageConfig::GitRoot();
}
auto CreateTypedTmpDir(std::string const& type) noexcept -> TmpDirPtr {
diff --git a/src/other_tools/just_mr/utils.hpp b/src/other_tools/just_mr/utils.hpp
index 0d3dbf1c..a7d43415 100644
--- a/src/other_tools/just_mr/utils.hpp
+++ b/src/other_tools/just_mr/utils.hpp
@@ -125,9 +125,6 @@ using CAInfoPtr = std::shared_ptr<JustMR::CAInfo>;
namespace Utils {
-/// \brief Get the Git cache root path.
-[[nodiscard]] auto GetGitCacheRoot() noexcept -> std::filesystem::path;
-
/// \brief Get location of Git repository. Defaults to the Git cache root when
/// no better location is found.
[[nodiscard]] auto GetGitRoot(JustMR::PathsPtr const& just_mr_paths,
diff --git a/src/other_tools/ops_maps/import_to_git_map.cpp b/src/other_tools/ops_maps/import_to_git_map.cpp
index c603853b..42ec7c9b 100644
--- a/src/other_tools/ops_maps/import_to_git_map.cpp
+++ b/src/other_tools/ops_maps/import_to_git_map.cpp
@@ -17,6 +17,7 @@
#include "fmt/core.h"
#include "src/buildtool/execution_api/common/execution_common.hpp"
#include "src/buildtool/execution_api/local/config.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/other_tools/just_mr/utils.hpp"
namespace {
@@ -31,10 +32,10 @@ void KeepCommitAndSetTree(
ImportToGitMap::LoggerPtr const& logger) {
// Keep tag for commit
GitOpKey op_key = {{
- JustMR::Utils::GetGitCacheRoot(), // target_path
- commit, // git_hash
- "", // branch
- "Keep referenced tree alive" // message
+ StorageConfig::GitRoot(), // target_path
+ commit, // git_hash
+ "", // branch
+ "Keep referenced tree alive" // message
},
GitOpType::KEEP_TAG};
critical_git_op_map->ConsumeAfterKeysReady(
@@ -123,15 +124,14 @@ auto CreateImportToGitMap(
}
// ensure Git cache
// define Git operation to be done
- GitOpKey op_key = {
- {
- JustMR::Utils::GetGitCacheRoot(), // target_path
- "", // git_hash
- "", // branch
- std::nullopt, // message
- true // init_bare
- },
- GitOpType::ENSURE_INIT};
+ GitOpKey op_key = {{
+ StorageConfig::GitRoot(), // target_path
+ "", // git_hash
+ "", // branch
+ std::nullopt, // message
+ true // init_bare
+ },
+ GitOpType::ENSURE_INIT};
critical_git_op_map->ConsumeAfterKeysReady(
ts,
{std::move(op_key)},
@@ -212,7 +212,7 @@ auto CreateImportToGitMap(
setter,
wrapped_logger);
},
- [logger, target_path = JustMR::Utils::GetGitCacheRoot()](
+ [logger, target_path = StorageConfig::GitRoot()](
auto const& msg, bool fatal) {
(*logger)(fmt::format("While running critical Git "
"op ENSURE_INIT bare for "
diff --git a/src/other_tools/root_maps/TARGETS b/src/other_tools/root_maps/TARGETS
index 57b80bbb..d2bb01a3 100644
--- a/src/other_tools/root_maps/TARGETS
+++ b/src/other_tools/root_maps/TARGETS
@@ -14,6 +14,8 @@
, ["src/buildtool/execution_api/common", "common"]
, ["src/buildtool/execution_api/local", "config"]
, ["src/buildtool/execution_api/local", "local"]
+ , ["src/buildtool/storage", "config"]
+ , ["src/buildtool/storage", "storage"]
, ["src/utils/cpp", "tmp_dir"]
, ["src/buildtool/file_system", "file_storage"]
, ["src/other_tools/just_mr/progress_reporting", "progress"]
@@ -52,6 +54,7 @@
, "private-deps":
[ ["src/other_tools/just_mr", "utils"]
, ["src/buildtool/execution_api/local", "config"]
+ , ["src/buildtool/storage", "config"]
, ["src/utils/cpp", "tmp_dir"]
]
}
@@ -69,6 +72,8 @@
[ ["src/other_tools/utils", "archive_ops"]
, ["src/buildtool/execution_api/local", "local"]
, ["src/buildtool/file_system", "file_storage"]
+ , ["src/buildtool/storage", "storage"]
+ , ["src/buildtool/storage", "config"]
, ["src/other_tools/just_mr/progress_reporting", "progress"]
, ["src/other_tools/just_mr/progress_reporting", "statistics"]
]
@@ -87,6 +92,7 @@
[ ["src/other_tools/ops_maps", "critical_git_op_map"]
, ["src/buildtool/execution_api/common", "common"]
, ["src/buildtool/file_system", "file_system_manager"]
+ , ["src/buildtool/storage", "config"]
, ["src/buildtool/system", "system_command"]
, ["src/other_tools/git_operations", "git_repo_remote"]
, ["src/other_tools/just_mr", "utils"]
diff --git a/src/other_tools/root_maps/content_git_map.cpp b/src/other_tools/root_maps/content_git_map.cpp
index 80072fee..9af1c49c 100644
--- a/src/other_tools/root_maps/content_git_map.cpp
+++ b/src/other_tools/root_maps/content_git_map.cpp
@@ -15,6 +15,7 @@
#include "src/other_tools/root_maps/content_git_map.hpp"
#include "src/buildtool/file_system/file_storage.hpp"
+#include "src/buildtool/storage/config.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"
@@ -67,15 +68,14 @@ auto CreateContentGitMap(
}
// ensure Git cache
// define Git operation to be done
- GitOpKey op_key = {
- {
- JustMR::Utils::GetGitCacheRoot(), // target_path
- "", // git_hash
- "", // branch
- std::nullopt, // message
- true // init_bare
- },
- GitOpType::ENSURE_INIT};
+ GitOpKey op_key = {{
+ StorageConfig::GitRoot(), // target_path
+ "", // git_hash
+ "", // branch
+ std::nullopt, // message
+ true // init_bare
+ },
+ GitOpType::ENSURE_INIT};
critical_git_op_map->ConsumeAfterKeysReady(
ts,
{std::move(op_key)},
@@ -114,14 +114,14 @@ auto CreateContentGitMap(
return;
}
// set the workspace root
- (*setter)(std::pair(
- nlohmann::json::array(
- {"git tree",
- *subtree_hash,
- JustMR::Utils::GetGitCacheRoot().string()}),
- true));
+ (*setter)(
+ std::pair(nlohmann::json::array(
+ {"git tree",
+ *subtree_hash,
+ StorageConfig::GitRoot().string()}),
+ true));
},
- [logger, target_path = JustMR::Utils::GetGitCacheRoot()](
+ [logger, target_path = StorageConfig::GitRoot()](
auto const& msg, bool fatal) {
(*logger)(fmt::format("While running critical Git "
"op ENSURE_INIT for "
@@ -204,7 +204,7 @@ auto CreateContentGitMap(
}
// we look for subtree in Git cache
auto just_git_cas =
- GitCAS::Open(JustMR::Utils::GetGitCacheRoot());
+ GitCAS::Open(StorageConfig::GitRoot());
if (not just_git_cas) {
(*logger)(
"Could not open Git cache object database!",
@@ -239,13 +239,12 @@ auto CreateContentGitMap(
return;
}
// set the workspace root
- (*setter)(
- std::pair(nlohmann::json::array(
- {"git tree",
- *subtree_hash,
- JustMR::Utils::GetGitCacheRoot()
- .string()}),
- false));
+ (*setter)(std::pair(
+ nlohmann::json::array(
+ {"git tree",
+ *subtree_hash,
+ StorageConfig::GitRoot().string()}),
+ false));
},
[logger, target_path = tmp_dir->GetPath()](
auto const& msg, bool fatal) {
diff --git a/src/other_tools/root_maps/distdir_git_map.cpp b/src/other_tools/root_maps/distdir_git_map.cpp
index 403247e4..952eeb75 100644
--- a/src/other_tools/root_maps/distdir_git_map.cpp
+++ b/src/other_tools/root_maps/distdir_git_map.cpp
@@ -18,6 +18,7 @@
#include "src/buildtool/execution_api/common/execution_common.hpp"
#include "src/buildtool/file_system/file_storage.hpp"
+#include "src/buildtool/storage/config.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"
@@ -76,15 +77,14 @@ auto CreateDistdirGitMap(
}
// ensure Git cache
// define Git operation to be done
- GitOpKey op_key = {
- {
- JustMR::Utils::GetGitCacheRoot(), // target_path
- "", // git_hash
- "", // branch
- std::nullopt, // message
- true // init_bare
- },
- GitOpType::ENSURE_INIT};
+ GitOpKey op_key = {{
+ StorageConfig::GitRoot(), // target_path
+ "", // git_hash
+ "", // branch
+ std::nullopt, // message
+ true // init_bare
+ },
+ GitOpType::ENSURE_INIT};
critical_git_op_map->ConsumeAfterKeysReady(
ts,
{std::move(op_key)},
@@ -99,14 +99,14 @@ auto CreateDistdirGitMap(
}
// subdir is ".", so no need to deal with the Git cache
// set the workspace root
- (*setter)(std::pair(
- nlohmann::json::array(
- {"git tree",
- distdir_tree_id,
- JustMR::Utils::GetGitCacheRoot().string()}),
- true));
+ (*setter)(
+ std::pair(nlohmann::json::array(
+ {"git tree",
+ distdir_tree_id,
+ StorageConfig::GitRoot().string()}),
+ true));
},
- [logger, target_path = JustMR::Utils::GetGitCacheRoot()](
+ [logger, target_path = StorageConfig::GitRoot()](
auto const& msg, bool fatal) {
(*logger)(fmt::format("While running critical Git "
"op ENSURE_INIT for "
@@ -177,13 +177,12 @@ auto CreateDistdirGitMap(
return;
}
// set the workspace root
- (*setter)(
- std::pair(nlohmann::json::array(
- {"git tree",
- distdir_tree_id,
- JustMR::Utils::GetGitCacheRoot()
- .string()}),
- false));
+ (*setter)(std::pair(
+ nlohmann::json::array(
+ {"git tree",
+ distdir_tree_id,
+ StorageConfig::GitRoot().string()}),
+ false));
},
[logger, target_path = tmp_dir->GetPath()](
auto const& msg, bool fatal) {
diff --git a/src/other_tools/root_maps/fpath_git_map.cpp b/src/other_tools/root_maps/fpath_git_map.cpp
index d8de9fa1..1330ee99 100644
--- a/src/other_tools/root_maps/fpath_git_map.cpp
+++ b/src/other_tools/root_maps/fpath_git_map.cpp
@@ -15,6 +15,7 @@
#include "src/other_tools/root_maps/fpath_git_map.hpp"
#include "src/buildtool/execution_api/local/config.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/other_tools/just_mr/utils.hpp"
#include "src/utils/cpp/tmp_dir.hpp"
@@ -163,7 +164,7 @@ auto CreateFilePathGitMap(
std::string tree = values[0]->first;
// set the workspace root
(*setter)(nlohmann::json::array(
- {"git tree", tree, JustMR::Utils::GetGitCacheRoot()}));
+ {"git tree", tree, StorageConfig::GitRoot()}));
},
[logger, target_path = key](auto const& msg, bool fatal) {
(*logger)(
diff --git a/src/other_tools/root_maps/tree_id_git_map.cpp b/src/other_tools/root_maps/tree_id_git_map.cpp
index d73057c4..a4a1c91a 100644
--- a/src/other_tools/root_maps/tree_id_git_map.cpp
+++ b/src/other_tools/root_maps/tree_id_git_map.cpp
@@ -17,6 +17,7 @@
#include "fmt/core.h"
#include "src/buildtool/execution_api/common/execution_common.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/system/system_command.hpp"
#include "src/other_tools/git_operations/git_repo_remote.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress.hpp"
@@ -35,10 +36,10 @@ void KeepCommitAndSetRoot(
TreeIdGitMap::LoggerPtr const& logger) {
// Keep tag for commit
GitOpKey op_key = {{
- JustMR::Utils::GetGitCacheRoot(), // target_path
- commit, // git_hash
- "", // branch
- "Keep referenced tree alive" // message
+ StorageConfig::GitRoot(), // target_path
+ commit, // git_hash
+ "", // branch
+ "Keep referenced tree alive" // message
},
GitOpType::KEEP_TAG};
critical_git_op_map->ConsumeAfterKeysReady(
@@ -57,12 +58,11 @@ void KeepCommitAndSetRoot(
}
// set the workspace root
JustMRProgress::Instance().TaskTracker().Start(tree_id_info.origin);
- (*ws_setter)(
- std::pair(nlohmann::json::array(
- {"git tree",
- tree_id_info.hash,
- JustMR::Utils::GetGitCacheRoot().string()}),
- false));
+ (*ws_setter)(std::pair(
+ nlohmann::json::array({"git tree",
+ tree_id_info.hash,
+ StorageConfig::GitRoot().string()}),
+ false));
},
[logger, commit, target_path = tmp_dir->GetPath()](auto const& msg,
bool fatal) {
@@ -92,11 +92,11 @@ auto CreateTreeIdGitMap(
// ensure Git cache
// define Git operation to be done
GitOpKey op_key = {{
- JustMR::Utils::GetGitCacheRoot(), // target_path
- "", // git_hash
- "", // branch
- std::nullopt, // message
- true // init_bare
+ StorageConfig::GitRoot(), // target_path
+ "", // git_hash
+ "", // branch
+ std::nullopt, // message
+ true // init_bare
},
GitOpType::ENSURE_INIT};
critical_git_op_map->ConsumeAfterKeysReady(
@@ -115,10 +115,9 @@ auto CreateTreeIdGitMap(
auto git_repo = GitRepoRemote::Open(
op_result.git_cas); // link fake repo to odb
if (not git_repo) {
- (*logger)(
- fmt::format("Could not open repository {}",
- JustMR::Utils::GetGitCacheRoot().string()),
- /*fatal=*/true);
+ (*logger)(fmt::format("Could not open repository {}",
+ StorageConfig::GitRoot().string()),
+ /*fatal=*/true);
return;
}
// setup wrapped logger
@@ -338,16 +337,16 @@ auto CreateTreeIdGitMap(
}
else {
// tree found, so return the git tree root as-is
- (*setter)(std::pair(
- nlohmann::json::array(
- {"git tree",
- key.hash,
- JustMR::Utils::GetGitCacheRoot().string()}),
- true));
+ (*setter)(
+ std::pair(nlohmann::json::array(
+ {"git tree",
+ key.hash,
+ StorageConfig::GitRoot().string()}),
+ true));
}
},
- [logger, target_path = JustMR::Utils::GetGitCacheRoot()](
- auto const& msg, bool fatal) {
+ [logger, target_path = StorageConfig::GitRoot()](auto const& msg,
+ bool fatal) {
(*logger)(fmt::format("While running critical Git "
"op ENSURE_INIT bare for "
"target {}:\n{}",