diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/main.cpp | 11 | ||||
-rw-r--r-- | src/other_tools/just_mr/utils.hpp | 5 | ||||
-rw-r--r-- | src/other_tools/repo_map/TARGETS | 1 | ||||
-rw-r--r-- | src/other_tools/repo_map/repos_to_setup_map.cpp | 104 | ||||
-rw-r--r-- | src/other_tools/repo_map/repos_to_setup_map.hpp | 2 |
5 files changed, 120 insertions, 3 deletions
diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp index b479e1f2..52cfe09a 100644 --- a/src/other_tools/just_mr/main.cpp +++ b/src/other_tools/just_mr/main.cpp @@ -1137,6 +1137,9 @@ void DefaultReachableRepositories( &import_to_git_map, &critical_git_op_map, arguments.common.jobs); + auto tree_id_git_map = CreateTreeIdGitMap(&critical_git_op_map, + *arguments.common.local_launcher, + arguments.common.jobs); auto repos_to_setup_map = CreateReposToSetupMap(config, main, interactive, @@ -1145,6 +1148,7 @@ void DefaultReachableRepositories( &fpath_git_map, &content_cas_map, &distdir_git_map, + &tree_id_git_map, arguments.common.jobs); // set up map for progress tracing @@ -1423,6 +1427,13 @@ auto main(int argc, char* argv[]) -> int { arguments.common.main = arguments.setup.sub_main; } + // check for errors in setting up local launcher arg + if (not arguments.common.local_launcher) { + Logger::Log(LogLevel::Error, + "Failed to configure local execution."); + return kExitGenericFailure; + } + // Run subcommands known to just and `do` if (arguments.cmd == SubCommand::kJustDo or arguments.cmd == SubCommand::kJustSubCmd) { diff --git a/src/other_tools/just_mr/utils.hpp b/src/other_tools/just_mr/utils.hpp index bfd81f16..57202a11 100644 --- a/src/other_tools/just_mr/utils.hpp +++ b/src/other_tools/just_mr/utils.hpp @@ -69,7 +69,7 @@ nlohmann::json const kDefaultConfigLocations = nlohmann::json::array( {{"root", "system"}, {"path", "etc/just-repos.json"}}}); /// \brief Checkout type enum -enum class CheckoutType : std::uint8_t { Git, Archive, File, Distdir }; +enum class CheckoutType : std::uint8_t { Git, Archive, File, Distdir, GitTree }; /// \brief Checkout type map std::unordered_map<std::string, CheckoutType> const kCheckoutTypeMap = { @@ -77,7 +77,8 @@ std::unordered_map<std::string, CheckoutType> const kCheckoutTypeMap = { {"archive", CheckoutType::Archive}, {"zip", CheckoutType::Archive}, // treated the same as "archive" {"file", CheckoutType::File}, - {"distdir", CheckoutType::Distdir}}; + {"distdir", CheckoutType::Distdir}, + {"git tree", CheckoutType::GitTree}}; namespace JustMR { diff --git a/src/other_tools/repo_map/TARGETS b/src/other_tools/repo_map/TARGETS index 5e89d85c..649708ae 100644 --- a/src/other_tools/repo_map/TARGETS +++ b/src/other_tools/repo_map/TARGETS @@ -9,6 +9,7 @@ , ["src/other_tools/root_maps", "distdir_git_map"] , ["src/other_tools/root_maps", "fpath_git_map"] , ["src/buildtool/build_engine/expression", "expression"] + , ["src/other_tools/root_maps", "tree_id_git_map"] ] , "stage": ["src", "other_tools", "repo_map"] , "private-deps": diff --git a/src/other_tools/repo_map/repos_to_setup_map.cpp b/src/other_tools/repo_map/repos_to_setup_map.cpp index 36428668..cbdcf6d9 100644 --- a/src/other_tools/repo_map/repos_to_setup_map.cpp +++ b/src/other_tools/repo_map/repos_to_setup_map.cpp @@ -449,6 +449,96 @@ void DistdirCheckout(ExpressionPtr const& repo_desc, }); } +/// \brief Perform checkout for a git tree type repository. +/// Guarantees the logger is called exactly once with fatal if a failure occurs. +void GitTreeCheckout(ExpressionPtr const& repo_desc, + ExpressionPtr&& repos, + std::string const& repo_name, + gsl::not_null<TreeIdGitMap*> const& tree_id_git_map, + gsl::not_null<TaskSystem*> const& ts, + ReposToSetupMap::SetterPtr const& setter, + ReposToSetupMap::LoggerPtr const& logger) { + // enforce mandatory fields + auto repo_desc_hash = repo_desc->At("id"); + if (not repo_desc_hash) { + (*logger)("GitTreeCheckout: Mandatory field \'id\' is missing", + /*fatal=*/true); + return; + } + if (not repo_desc_hash->get()->IsString()) { + (*logger)( + "GitTreeCheckout: Unsupported value for mandatory field \'id\'", + /*fatal=*/true); + return; + } + auto repo_desc_cmd = repo_desc->At("cmd"); + if (not repo_desc_cmd) { + (*logger)("GitTreeCheckout: Mandatory field \'cmd\' is missing", + /*fatal=*/true); + return; + } + if (not repo_desc_cmd->get()->IsList()) { + (*logger)( + "GitTreeCheckout: Unsupported value for mandatory field \'cmd\'", + /*fatal=*/true); + return; + } + std::vector<std::string> cmd{}; + for (auto const& token : repo_desc_cmd->get()->List()) { + if (token.IsNotNull() and token->IsString()) { + cmd.emplace_back(token->String()); + } + else { + (*logger)(fmt::format("GitTreeCheckout: Unsupported entry {} in " + "mandatory field \'cmd\'", + token->ToString()), + /*fatal=*/true); + return; + } + } + std::map<std::string, std::string> env{}; + auto repo_desc_env = repo_desc->Get("env", Expression::none_t{}); + if (repo_desc_env.IsNotNull() and repo_desc_env->IsMap()) { + for (auto const& envar : repo_desc_env->Map().Items()) { + if (envar.second.IsNotNull() and envar.second->IsString()) { + env.insert({envar.first, envar.second->String()}); + } + else { + (*logger)(fmt::format("GitTreeCheckout: Unsupported value {} " + "for key {} in optional field \'envs\'", + envar.second->ToString(), + nlohmann::json(envar.first).dump()), + /*fatal=*/true); + return; + } + } + } + // populate struct + TreeIdInfo tree_id_info = { + repo_desc_hash->get()->String(), /* hash */ + std::move(env), /* env_vars */ + std::move(cmd) /* command */ + }; + // get the WS root as git tree + tree_id_git_map->ConsumeAfterKeysReady( + ts, + {std::move(tree_id_info)}, + [repos = std::move(repos), repo_name, setter](auto const& values) { + auto ws_root = *values[0]; + nlohmann::json cfg({}); + cfg["workspace_root"] = ws_root; + SetReposTakeOver(&cfg, repos, repo_name); + (*setter)(std::move(cfg)); + }, + [logger, repo_name](auto const& msg, bool fatal) { + (*logger)(fmt::format("While setting the workspace root for " + "repository {} of type git tree:\n{}", + repo_name, + msg), + fatal); + }); +} + } // namespace auto CreateReposToSetupMap(std::shared_ptr<Configuration> const& config, @@ -459,6 +549,7 @@ auto CreateReposToSetupMap(std::shared_ptr<Configuration> const& config, gsl::not_null<FilePathGitMap*> const& fpath_git_map, gsl::not_null<ContentCASMap*> const& content_cas_map, gsl::not_null<DistdirGitMap*> const& distdir_git_map, + gsl::not_null<TreeIdGitMap*> const& tree_id_git_map, std::size_t jobs) -> ReposToSetupMap { auto setup_repo = [config, main, @@ -467,7 +558,8 @@ auto CreateReposToSetupMap(std::shared_ptr<Configuration> const& config, content_git_map, fpath_git_map, content_cas_map, - distdir_git_map](auto ts, + distdir_git_map, + tree_id_git_map](auto ts, auto setter, auto logger, auto /* unused */, @@ -583,6 +675,16 @@ auto CreateReposToSetupMap(std::shared_ptr<Configuration> const& config, wrapped_logger); break; } + case CheckoutType::GitTree: { + GitTreeCheckout(*resolved_repo_desc, + std::move(repos), + key, + tree_id_git_map, + ts, + setter, + wrapped_logger); + break; + } } } }; diff --git a/src/other_tools/repo_map/repos_to_setup_map.hpp b/src/other_tools/repo_map/repos_to_setup_map.hpp index f2f7eb43..a24d24b9 100644 --- a/src/other_tools/repo_map/repos_to_setup_map.hpp +++ b/src/other_tools/repo_map/repos_to_setup_map.hpp @@ -20,6 +20,7 @@ #include "src/other_tools/root_maps/content_git_map.hpp" #include "src/other_tools/root_maps/distdir_git_map.hpp" #include "src/other_tools/root_maps/fpath_git_map.hpp" +#include "src/other_tools/root_maps/tree_id_git_map.hpp" /// \brief Maps a global repo name to a JSON object containing the workspace /// root and the TAKE_OVER fields. @@ -33,6 +34,7 @@ auto CreateReposToSetupMap(std::shared_ptr<Configuration> const& config, gsl::not_null<FilePathGitMap*> const& fpath_git_map, gsl::not_null<ContentCASMap*> const& content_cas_map, gsl::not_null<DistdirGitMap*> const& distdir_git_map, + gsl::not_null<TreeIdGitMap*> const& tree_id_git_map, std::size_t jobs) -> ReposToSetupMap; #endif // INCLUDED_SRC_OTHER_TOOLS_REPO_MAP_REPOS_TO_SETUP_MAP_HPP
\ No newline at end of file |