summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKlaus Aehlig <klaus.aehlig@huawei.com>2024-03-12 18:23:35 +0100
committerKlaus Aehlig <klaus.aehlig@huawei.com>2024-03-13 12:14:53 +0100
commit2bd069cdecb5371d906f8df9f5fb36f308d6296f (patch)
tree3db2cee634411639d520b2dee796b8a97b7342f6 /src
parentf487f592fdc85fbdb95856abb7f4281dd4353da9 (diff)
downloadjustbuild-2bd069cdecb5371d906f8df9f5fb36f308d6296f.tar.gz
Move storage-aware tmpdir creation to config
... as the fs_utils have a lot more dependencies making them usable in less places. Moreover, this function also serves to shape the layout of the local build root and hence is more appropriately placed in the config anyway.
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/execution_api/execution_service/TARGETS2
-rw-r--r--src/buildtool/execution_api/execution_service/cas_utils.cpp4
-rw-r--r--src/buildtool/serve_api/serve_service/source_tree.cpp8
-rw-r--r--src/buildtool/storage/TARGETS2
-rw-r--r--src/buildtool/storage/config.hpp10
-rw-r--r--src/buildtool/storage/fs_utils.cpp6
-rw-r--r--src/buildtool/storage/fs_utils.hpp6
-rw-r--r--src/other_tools/just_mr/TARGETS2
-rw-r--r--src/other_tools/just_mr/update.cpp4
-rw-r--r--src/other_tools/ops_maps/TARGETS1
-rw-r--r--src/other_tools/ops_maps/git_tree_fetch_map.cpp9
-rw-r--r--src/other_tools/root_maps/TARGETS2
-rw-r--r--src/other_tools/root_maps/commit_git_map.cpp2
-rw-r--r--src/other_tools/root_maps/content_git_map.cpp2
-rw-r--r--src/other_tools/root_maps/distdir_git_map.cpp2
-rw-r--r--src/other_tools/root_maps/foreign_file_git_map.cpp3
-rw-r--r--src/other_tools/root_maps/fpath_git_map.cpp2
-rw-r--r--src/other_tools/root_maps/tree_id_git_map.cpp3
18 files changed, 33 insertions, 37 deletions
diff --git a/src/buildtool/execution_api/execution_service/TARGETS b/src/buildtool/execution_api/execution_service/TARGETS
index e494711c..a7d31a27 100644
--- a/src/buildtool/execution_api/execution_service/TARGETS
+++ b/src/buildtool/execution_api/execution_service/TARGETS
@@ -165,7 +165,7 @@
, ["src/buildtool/file_system", "git_repo"]
, ["src/buildtool/file_system", "object_type"]
, ["src/buildtool/file_system", "file_system_manager"]
- , ["src/buildtool/storage", "fs_utils"]
+ , ["src/buildtool/storage", "config"]
, ["src/utils/cpp", "hex_string"]
]
}
diff --git a/src/buildtool/execution_api/execution_service/cas_utils.cpp b/src/buildtool/execution_api/execution_service/cas_utils.cpp
index b710dd36..e2c4a418 100644
--- a/src/buildtool/execution_api/execution_service/cas_utils.cpp
+++ b/src/buildtool/execution_api/execution_service/cas_utils.cpp
@@ -23,7 +23,7 @@
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/file_system/git_repo.hpp"
#include "src/buildtool/file_system/object_type.hpp"
-#include "src/buildtool/storage/fs_utils.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/utils/cpp/hex_string.hpp"
auto CASUtils::EnsureTreeInvariant(std::string const& data,
@@ -150,7 +150,7 @@ auto CASUtils::SpliceBlob(bazel_re::Digest const& blob_digest,
-> std::variant<bazel_re::Digest, grpc::Status> {
// Assemble blob from chunks.
- auto tmp_dir = StorageUtils::CreateTypedTmpDir("splice");
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir("splice");
auto tmp_file = tmp_dir->GetPath() / "blob";
{
std::ofstream tmp(tmp_file, std::ios::binary);
diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp
index 4941f786..5156ce9c 100644
--- a/src/buildtool/serve_api/serve_service/source_tree.cpp
+++ b/src/buildtool/serve_api/serve_service/source_tree.cpp
@@ -806,7 +806,7 @@ auto SourceTreeService::ServeArchiveTree(
}
}
// extract archive
- auto tmp_dir = StorageUtils::CreateTypedTmpDir(archive_type);
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir(archive_type);
if (not tmp_dir) {
auto str = fmt::format(
"Failed to create tmp path for {} archive with content {}",
@@ -845,7 +845,7 @@ auto SourceTreeService::DistdirImportToGit(
bool sync_tree,
ServeDistdirTreeResponse* response) -> ::grpc::Status {
// create tmp directory for the distdir
- auto distdir_tmp_dir = StorageUtils::CreateTypedTmpDir("distdir");
+ auto distdir_tmp_dir = StorageConfig::CreateTypedTmpDir("distdir");
if (not distdir_tmp_dir) {
auto str = fmt::format(
"Failed to create tmp path for distdir target {}", content_id);
@@ -1546,7 +1546,7 @@ auto SourceTreeService::CheckRootTree(
// As we currently build only against roots in Git repositories, we need
// to move the tree from CAS to local Git storage
auto tmp_dir =
- StorageUtils::CreateTypedTmpDir("source-tree-check-root-tree");
+ StorageConfig::CreateTypedTmpDir("source-tree-check-root-tree");
if (not tmp_dir) {
auto str = fmt::format(
"Failed to create tmp directory for copying "
@@ -1621,7 +1621,7 @@ auto SourceTreeService::GetRemoteTree(
return ::grpc::Status::OK;
}
auto tmp_dir =
- StorageUtils::CreateTypedTmpDir("source-tree-get-remote-tree");
+ StorageConfig::CreateTypedTmpDir("source-tree-get-remote-tree");
if (not tmp_dir) {
auto str = fmt::format(
"Failed to create tmp directory for copying git-tree {} from "
diff --git a/src/buildtool/storage/TARGETS b/src/buildtool/storage/TARGETS
index 796b3fa9..5bcca567 100644
--- a/src/buildtool/storage/TARGETS
+++ b/src/buildtool/storage/TARGETS
@@ -13,6 +13,7 @@
, ["src/buildtool/logging", "logging"]
, ["src/buildtool/logging", "log_level"]
, ["src/utils/cpp", "gsl"]
+ , ["src/utils/cpp", "tmp_dir"]
]
, "stage": ["src", "buildtool", "storage"]
}
@@ -65,7 +66,6 @@
, "deps":
[ ["src/buildtool/common", "user_structs"]
, ["src/buildtool/file_system/symlinks_map", "pragma_special"]
- , ["src/utils/cpp", "tmp_dir"]
]
, "stage": ["src", "buildtool", "storage"]
, "private-deps":
diff --git a/src/buildtool/storage/config.hpp b/src/buildtool/storage/config.hpp
index 92358d12..858f74ff 100644
--- a/src/buildtool/storage/config.hpp
+++ b/src/buildtool/storage/config.hpp
@@ -38,6 +38,7 @@
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/utils/cpp/gsl.hpp"
+#include "src/utils/cpp/tmp_dir.hpp"
/// \brief Global storage configuration.
class StorageConfig {
@@ -184,6 +185,15 @@ class StorageConfig {
return EphemeralRoot() / "exec_root";
}
+ /// \brief Create a tmp directory with controlled lifetime for specific
+ /// operations (archive, zip, file, distdir checkouts; fetch; update).
+ [[nodiscard]] static auto CreateTypedTmpDir(
+ std::string const& type) noexcept -> TmpDirPtr {
+ // try to create parent dir
+ auto parent_path = EphemeralRoot() / "tmp-workspaces" / type;
+ return TmpDir::Create(parent_path);
+ }
+
private:
[[nodiscard]] static auto Data() noexcept -> ConfigData& {
static ConfigData instance{};
diff --git a/src/buildtool/storage/fs_utils.cpp b/src/buildtool/storage/fs_utils.cpp
index 5cc3d8a0..b606431c 100644
--- a/src/buildtool/storage/fs_utils.cpp
+++ b/src/buildtool/storage/fs_utils.cpp
@@ -49,12 +49,6 @@ auto GetGitRoot(LocalPathsPtr const& just_mr_paths,
return StorageConfig::GitRoot();
}
-auto CreateTypedTmpDir(std::string const& type) noexcept -> TmpDirPtr {
- // try to create parent dir
- auto parent_path = StorageConfig::EphemeralRoot() / "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;
diff --git a/src/buildtool/storage/fs_utils.hpp b/src/buildtool/storage/fs_utils.hpp
index 6e8f640b..e24f50a3 100644
--- a/src/buildtool/storage/fs_utils.hpp
+++ b/src/buildtool/storage/fs_utils.hpp
@@ -21,7 +21,6 @@
#include "src/buildtool/common/user_structs.hpp"
#include "src/buildtool/file_system/symlinks_map/pragma_special.hpp"
-#include "src/utils/cpp/tmp_dir.hpp"
/* Utilities related to CAS and paths therein */
@@ -33,11 +32,6 @@ namespace StorageUtils {
std::string const& repo_url) noexcept
-> std::filesystem::path;
-/// \brief Create a tmp directory with controlled lifetime for specific
-/// operations (archive, zip, file, distdir checkouts; fetch; update).
-[[nodiscard]] auto CreateTypedTmpDir(std::string const& type) noexcept
- -> TmpDirPtr;
-
/// \brief Get the path to the file storing the tree id associated with
/// a given commit.
[[nodiscard]] auto GetCommitTreeIDFile(std::string const& commit) noexcept
diff --git a/src/other_tools/just_mr/TARGETS b/src/other_tools/just_mr/TARGETS
index 5a8869c6..8471282b 100644
--- a/src/other_tools/just_mr/TARGETS
+++ b/src/other_tools/just_mr/TARGETS
@@ -131,7 +131,7 @@
, ["@", "json", "", "json"]
, ["src/buildtool/logging", "logging"]
, ["src/buildtool/multithreading", "task_system"]
- , ["src/buildtool/storage", "fs_utils"]
+ , ["src/buildtool/storage", "config"]
, ["src/other_tools/git_operations", "git_repo_remote"]
, "exit_codes"
, ["src/other_tools/just_mr/progress_reporting", "progress"]
diff --git a/src/other_tools/just_mr/update.cpp b/src/other_tools/just_mr/update.cpp
index a768e0e0..b4e2e455 100644
--- a/src/other_tools/just_mr/update.cpp
+++ b/src/other_tools/just_mr/update.cpp
@@ -21,7 +21,7 @@
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
-#include "src/buildtool/storage/fs_utils.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/other_tools/git_operations/git_repo_remote.hpp"
#include "src/other_tools/just_mr/exit_codes.hpp"
#include "src/other_tools/just_mr/progress_reporting/progress.hpp"
@@ -186,7 +186,7 @@ auto MultiRepoUpdate(std::shared_ptr<Configuration> const& config,
}
}
// Create fake repo for the anonymous remotes
- auto tmp_dir = StorageUtils::CreateTypedTmpDir("update");
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir("update");
if (not tmp_dir) {
Logger::Log(LogLevel::Error, "Failed to create commit update tmp dir");
return kExitUpdateError;
diff --git a/src/other_tools/ops_maps/TARGETS b/src/other_tools/ops_maps/TARGETS
index 4a15849f..94894e60 100644
--- a/src/other_tools/ops_maps/TARGETS
+++ b/src/other_tools/ops_maps/TARGETS
@@ -124,7 +124,6 @@
, ["src/buildtool/multithreading", "task_system"]
, ["src/buildtool/serve_api/remote", "serve_api"]
, ["src/buildtool/storage", "config"]
- , ["src/buildtool/storage", "fs_utils"]
, ["src/buildtool/storage", "storage"]
, ["src/buildtool/system", "system_command"]
, ["src/other_tools/git_operations", "git_repo_remote"]
diff --git a/src/other_tools/ops_maps/git_tree_fetch_map.cpp b/src/other_tools/ops_maps/git_tree_fetch_map.cpp
index 74214349..fecd2756 100644
--- a/src/other_tools/ops_maps/git_tree_fetch_map.cpp
+++ b/src/other_tools/ops_maps/git_tree_fetch_map.cpp
@@ -24,7 +24,6 @@
#include "src/buildtool/multithreading/task_system.hpp"
#include "src/buildtool/serve_api/remote/serve_api.hpp"
#include "src/buildtool/storage/config.hpp"
-#include "src/buildtool/storage/fs_utils.hpp"
#include "src/buildtool/storage/storage.hpp"
#include "src/buildtool/system/system_command.hpp"
#include "src/other_tools/git_operations/git_repo_remote.hpp"
@@ -73,7 +72,7 @@ void MoveCASTreeToGit(
GitTreeFetchMap::SetterPtr const& setter,
GitTreeFetchMap::LoggerPtr const& logger) {
// Move tree from CAS to local Git storage
- auto tmp_dir = StorageUtils::CreateTypedTmpDir("fetch-remote-git-tree");
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir("fetch-remote-git-tree");
if (not tmp_dir) {
(*logger)(fmt::format("Failed to create tmp directory for copying "
"git-tree {} from remote CAS",
@@ -259,7 +258,7 @@ auto CreateGitTreeFetchMap(
return;
}
// create temporary location for command execution root
- auto tmp_dir = StorageUtils::CreateTypedTmpDir("git-tree");
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir("git-tree");
if (not tmp_dir) {
(*logger)(
"Failed to create execution root tmp directory for "
@@ -268,7 +267,7 @@ auto CreateGitTreeFetchMap(
return;
}
// create temporary location for storing command result files
- auto out_dir = StorageUtils::CreateTypedTmpDir("git-tree");
+ auto out_dir = StorageConfig::CreateTypedTmpDir("git-tree");
if (not out_dir) {
(*logger)(
"Failed to create results tmp directory for tree id "
@@ -397,7 +396,7 @@ auto CreateGitTreeFetchMap(
}
// define temp repo path
auto tmp_dir =
- StorageUtils::CreateTypedTmpDir("git-tree");
+ StorageConfig::CreateTypedTmpDir("git-tree");
;
if (not tmp_dir) {
(*logger)(fmt::format("Could not create unique "
diff --git a/src/other_tools/root_maps/TARGETS b/src/other_tools/root_maps/TARGETS
index 42739b92..671a1d40 100644
--- a/src/other_tools/root_maps/TARGETS
+++ b/src/other_tools/root_maps/TARGETS
@@ -148,6 +148,7 @@
, ["src/buildtool/file_system", "file_root"]
, ["src/buildtool/logging", "log_level"]
, ["src/buildtool/serve_api/remote", "serve_api"]
+ , ["src/buildtool/storage", "config"]
, ["src/buildtool/storage", "fs_utils"]
, ["src/buildtool/storage", "storage"]
, ["src/utils/cpp", "tmp_dir"]
@@ -177,7 +178,6 @@
, ["src/buildtool/execution_api/git", "git"]
, ["src/buildtool/file_system", "file_root"]
, ["src/buildtool/storage", "config"]
- , ["src/buildtool/storage", "fs_utils"]
, ["src/buildtool/storage", "storage"]
]
}
diff --git a/src/other_tools/root_maps/commit_git_map.cpp b/src/other_tools/root_maps/commit_git_map.cpp
index 8bd18cc9..f9da1300 100644
--- a/src/other_tools/root_maps/commit_git_map.cpp
+++ b/src/other_tools/root_maps/commit_git_map.cpp
@@ -727,7 +727,7 @@ void EnsureCommit(
JustMRProgress::Instance().TaskTracker().Stop(
repo_info.origin);
// Move tree from local CAS to local Git storage
- auto tmp_dir = StorageUtils::CreateTypedTmpDir(
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir(
"fetch-absent-root");
if (not tmp_dir) {
(*logger)(
diff --git a/src/other_tools/root_maps/content_git_map.cpp b/src/other_tools/root_maps/content_git_map.cpp
index 67e61606..3bbc21c5 100644
--- a/src/other_tools/root_maps/content_git_map.cpp
+++ b/src/other_tools/root_maps/content_git_map.cpp
@@ -359,7 +359,7 @@ void ExtractAndImportToGit(
ContentGitMap::SetterPtr const& setter,
ContentGitMap::LoggerPtr const& logger) {
// extract archive
- auto tmp_dir = StorageUtils::CreateTypedTmpDir(key.repo_type);
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir(key.repo_type);
if (not tmp_dir) {
(*logger)(fmt::format("Failed to create tmp path for {} target {}",
key.repo_type,
diff --git a/src/other_tools/root_maps/distdir_git_map.cpp b/src/other_tools/root_maps/distdir_git_map.cpp
index cc44c05c..e003e000 100644
--- a/src/other_tools/root_maps/distdir_git_map.cpp
+++ b/src/other_tools/root_maps/distdir_git_map.cpp
@@ -71,7 +71,7 @@ void ImportFromCASAndSetRoot(
DistdirGitMap::SetterPtr const& setter,
DistdirGitMap::LoggerPtr const& logger) {
// create the links to CAS
- auto tmp_dir = StorageUtils::CreateTypedTmpDir("distdir");
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir("distdir");
if (not tmp_dir) {
(*logger)(fmt::format("Failed to create tmp path for "
"distdir target {}",
diff --git a/src/other_tools/root_maps/foreign_file_git_map.cpp b/src/other_tools/root_maps/foreign_file_git_map.cpp
index c2d06786..5e08a18a 100644
--- a/src/other_tools/root_maps/foreign_file_git_map.cpp
+++ b/src/other_tools/root_maps/foreign_file_git_map.cpp
@@ -19,6 +19,7 @@
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/serve_api/remote/serve_api.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/fs_utils.hpp"
#include "src/buildtool/storage/storage.hpp"
#include "src/other_tools/root_maps/root_utils.hpp"
@@ -55,7 +56,7 @@ void WithFetchedFile(ForeignFileInfo const& key,
gsl::not_null<TaskSystem*> const& ts,
ForeignFileGitMap::SetterPtr const& setter,
ForeignFileGitMap::LoggerPtr const& logger) {
- auto tmp_dir = StorageUtils::CreateTypedTmpDir("foreign-file");
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir("foreign-file");
auto const& cas = Storage::Instance().CAS();
auto digest = ArtifactDigest(key.archive.content, 0, key.executable);
auto content_cas_path = cas.BlobPath(digest, key.executable);
diff --git a/src/other_tools/root_maps/fpath_git_map.cpp b/src/other_tools/root_maps/fpath_git_map.cpp
index 9fb6858d..4c398612 100644
--- a/src/other_tools/root_maps/fpath_git_map.cpp
+++ b/src/other_tools/root_maps/fpath_git_map.cpp
@@ -346,7 +346,7 @@ auto CreateFilePathGitMap(
/*fatal=*/false);
}
// it's not a git repo, so import it to git cache
- auto tmp_dir = StorageUtils::CreateTypedTmpDir("file");
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir("file");
if (not tmp_dir) {
(*logger)("Failed to create import-to-git tmp directory!",
/*fatal=*/true);
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 e0456f12..9e8b1360 100644
--- a/src/other_tools/root_maps/tree_id_git_map.cpp
+++ b/src/other_tools/root_maps/tree_id_git_map.cpp
@@ -19,7 +19,6 @@
#include "src/buildtool/execution_api/git/git_api.hpp"
#include "src/buildtool/file_system/file_root.hpp"
#include "src/buildtool/storage/config.hpp"
-#include "src/buildtool/storage/fs_utils.hpp"
#include "src/buildtool/storage/storage.hpp"
#include "src/other_tools/root_maps/root_utils.hpp"
@@ -84,7 +83,7 @@ void MoveCASTreeToGitAndProcess(
TreeIdGitMap::SetterPtr const& setter,
TreeIdGitMap::LoggerPtr const& logger) {
// Move tree from CAS to local Git storage
- auto tmp_dir = StorageUtils::CreateTypedTmpDir("fetch-remote-git-tree");
+ auto tmp_dir = StorageConfig::CreateTypedTmpDir("fetch-remote-git-tree");
if (not tmp_dir) {
(*logger)(fmt::format("Failed to create tmp directory for copying "
"git-tree {} from remote CAS",