diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/setup.cpp | 2 | ||||
-rw-r--r-- | src/other_tools/root_maps/TARGETS | 2 | ||||
-rw-r--r-- | src/other_tools/root_maps/fpath_git_map.cpp | 127 | ||||
-rw-r--r-- | src/other_tools/root_maps/fpath_git_map.hpp | 3 |
4 files changed, 109 insertions, 25 deletions
diff --git a/src/other_tools/just_mr/setup.cpp b/src/other_tools/just_mr/setup.cpp index 22d4a04c..e5078592 100644 --- a/src/other_tools/just_mr/setup.cpp +++ b/src/other_tools/just_mr/setup.cpp @@ -178,6 +178,8 @@ auto MultiRepoSetup(std::shared_ptr<Configuration> const& config, &critical_git_op_map, &import_to_git_map, &resolve_symlinks_map, + serve_api_exists, + remote_api ? std::make_optional(&(*remote_api)) : std::nullopt, common_args.jobs, multi_repo_tool_name, common_args.just_path ? common_args.just_path->string() diff --git a/src/other_tools/root_maps/TARGETS b/src/other_tools/root_maps/TARGETS index 4b0a62df..f67c2474 100644 --- a/src/other_tools/root_maps/TARGETS +++ b/src/other_tools/root_maps/TARGETS @@ -69,6 +69,7 @@ , "deps": [ ["@", "gsl", "", "gsl"] , ["@", "json", "", "json"] + , ["src/buildtool/execution_api/common", "common"] , ["src/buildtool/file_system/symlinks_map", "pragma_special"] , ["src/buildtool/file_system/symlinks_map", "resolve_symlinks_map"] , ["src/other_tools/just_mr", "utils"] @@ -79,6 +80,7 @@ , "stage": ["src", "other_tools", "root_maps"] , "private-deps": [ ["@", "fmt", "", "fmt"] + , "root_utils" , ["src/buildtool/execution_api/local", "config"] , ["src/buildtool/file_system", "file_root"] , ["src/buildtool/file_system", "git_repo"] diff --git a/src/other_tools/root_maps/fpath_git_map.cpp b/src/other_tools/root_maps/fpath_git_map.cpp index 79767b95..7ca438c1 100644 --- a/src/other_tools/root_maps/fpath_git_map.cpp +++ b/src/other_tools/root_maps/fpath_git_map.cpp @@ -22,10 +22,64 @@ #include "src/buildtool/storage/config.hpp" #include "src/buildtool/storage/fs_utils.hpp" #include "src/other_tools/git_operations/git_repo_remote.hpp" +#include "src/other_tools/root_maps/root_utils.hpp" #include "src/utils/cpp/tmp_dir.hpp" namespace { +/// \brief Does the serve endpoint checks and sets the workspace root. +/// It guarantees the logger is called exactly once with fatal on failure, and +/// the setter on success. +void CheckServeAndSetRoot( + std::string const& tree_id, + std::string const& repo_root, + bool absent, + bool serve_api_exists, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, + FilePathGitMap::SetterPtr const& ws_setter, + FilePathGitMap::LoggerPtr const& logger) { + // if serve endpoint is given, try to ensure it has this tree available to + // be able to build against it + if (serve_api_exists) { + auto has_tree = CheckServeHasAbsentRoot(tree_id, logger); + if (not has_tree) { + return; // fatal + } + if (not *has_tree) { + if (not remote_api) { + (*logger)(fmt::format( + "Missing remote-execution endpoint needed to " + "sync workspace root {} with the serve endpoint.", + tree_id), + /*fatal=*/true); + return; + } + if (not EnsureAbsentRootOnServe(tree_id, + repo_root, + remote_api, + logger, + /*no_sync_is_fatal=*/absent)) { + return; // fatal + } + } + } + else { + if (absent) { + // give warning + (*logger)(fmt::format("Workspace root {} marked absent but no " + "serve endpoint provided.", + tree_id), + /*fatal=*/false); + } + } + // set the workspace root + auto root = nlohmann::json::array({FileRoot::kGitTreeMarker, tree_id}); + if (not absent) { + root.emplace_back(repo_root); + } + (*ws_setter)(std::move(root)); +} + void ResolveFilePathTree( std::string const& repo_root, std::string const& target_path, @@ -33,6 +87,8 @@ void ResolveFilePathTree( std::optional<PragmaSpecial> const& pragma_special, bool absent, gsl::not_null<ResolveSymlinksMap*> const& resolve_symlinks_map, + bool serve_api_exists, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, gsl::not_null<TaskSystem*> const& ts, FilePathGitMap::SetterPtr const& ws_setter, FilePathGitMap::LoggerPtr const& logger) { @@ -44,19 +100,21 @@ void ResolveFilePathTree( // read resolved tree id auto resolved_tree_id = FileSystemManager::ReadFile(tree_id_file); if (not resolved_tree_id) { - (*logger)(fmt::format("Failed to read resolved " - "tree id from file {}", - tree_id_file.string()), - /*fatal=*/true); + (*logger)( + fmt::format("Failed to read resolved tree id from file {}", + tree_id_file.string()), + /*fatal=*/true); return; } - // set the workspace root - auto root = nlohmann::json::array( - {FileRoot::kGitTreeMarker, *resolved_tree_id}); - if (not absent) { - root.emplace_back(repo_root); - } - (*ws_setter)(std::move(root)); + // if serve endpoint is given, try to ensure it has this tree + // available to be able to build against it + CheckServeAndSetRoot(*resolved_tree_id, + repo_root, + absent, + serve_api_exists, + remote_api, + ws_setter, + logger); } else { // resolve tree @@ -71,6 +129,8 @@ void ResolveFilePathTree( repo_root, tree_id_file, absent, + serve_api_exists, + remote_api, ws_setter, logger](auto const& hashes) { if (not hashes[0]) { @@ -101,13 +161,15 @@ void ResolveFilePathTree( /*fatal=*/true); return; } - // set the workspace root - auto root = nlohmann::json::array( - {FileRoot::kGitTreeMarker, resolved_tree.id}); - if (not absent) { - root.emplace_back(repo_root); - } - (*ws_setter)(std::move(root)); + // if serve endpoint is given, try to ensure it has this + // tree available to be able to build against it + CheckServeAndSetRoot(resolved_tree.id, + repo_root, + absent, + serve_api_exists, + remote_api, + ws_setter, + logger); }, [logger, target_path](auto const& msg, bool fatal) { (*logger)(fmt::format( @@ -119,13 +181,16 @@ void ResolveFilePathTree( } } else { - // set the workspace root as-is - auto root = - nlohmann::json::array({FileRoot::kGitTreeMarker, tree_hash}); - if (not absent) { - root.emplace_back(repo_root); - } - (*ws_setter)(std::move(root)); + // tree needs no further processing; + // if serve endpoint is given, try to ensure it has this tree available + // to be able to build against it + CheckServeAndSetRoot(tree_hash, + repo_root, + absent, + serve_api_exists, + remote_api, + ws_setter, + logger); } } @@ -136,6 +201,8 @@ auto CreateFilePathGitMap( gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, gsl::not_null<ImportToGitMap*> const& import_to_git_map, gsl::not_null<ResolveSymlinksMap*> const& resolve_symlinks_map, + bool serve_api_exists, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, std::size_t jobs, std::string multi_repo_tool_name, std::string build_tool_name) -> FilePathGitMap { @@ -143,6 +210,8 @@ auto CreateFilePathGitMap( critical_git_op_map, import_to_git_map, resolve_symlinks_map, + serve_api_exists, + remote_api, multi_repo_tool_name, build_tool_name](auto ts, auto setter, @@ -196,6 +265,8 @@ auto CreateFilePathGitMap( git_cas = std::move(git_cas), repo_root = std::move(*repo_root), resolve_symlinks_map, + serve_api_exists, + remote_api, ts, setter, logger](auto const& values) { @@ -237,6 +308,8 @@ auto CreateFilePathGitMap( pragma_special, absent, resolve_symlinks_map, + serve_api_exists, + remote_api, ts, setter, logger); @@ -291,6 +364,8 @@ auto CreateFilePathGitMap( pragma_special = key.pragma_special, absent = key.absent, resolve_symlinks_map, + serve_api_exists, + remote_api, ts, setter, logger](auto const& values) { @@ -309,6 +384,8 @@ auto CreateFilePathGitMap( pragma_special, absent, resolve_symlinks_map, + serve_api_exists, + remote_api, ts, setter, logger); diff --git a/src/other_tools/root_maps/fpath_git_map.hpp b/src/other_tools/root_maps/fpath_git_map.hpp index 4dbe204f..e6cd45f9 100644 --- a/src/other_tools/root_maps/fpath_git_map.hpp +++ b/src/other_tools/root_maps/fpath_git_map.hpp @@ -21,6 +21,7 @@ #include "gsl/gsl" #include "nlohmann/json.hpp" +#include "src/buildtool/execution_api/common/execution_api.hpp" #include "src/buildtool/file_system/symlinks_map/pragma_special.hpp" #include "src/buildtool/file_system/symlinks_map/resolve_symlinks_map.hpp" #include "src/other_tools/just_mr/utils.hpp" @@ -51,6 +52,8 @@ using FilePathGitMap = AsyncMapConsumer<FpathInfo, nlohmann::json>; gsl::not_null<CriticalGitOpMap*> const& critical_git_op_map, gsl::not_null<ImportToGitMap*> const& import_to_git_map, gsl::not_null<ResolveSymlinksMap*> const& resolve_symlinks_map, + bool serve_api_exists, + std::optional<gsl::not_null<IExecutionApi*>> const& remote_api, std::size_t jobs, std::string multi_repo_tool_name, std::string build_tool_name) -> FilePathGitMap; |