diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/build_engine/expression/evaluator.cpp | 15 | ||||
-rw-r--r-- | src/buildtool/common/cli.hpp | 6 | ||||
-rw-r--r-- | src/buildtool/execution_api/common/bytestream_utils.cpp | 26 | ||||
-rw-r--r-- | src/buildtool/execution_api/local/local_action.cpp | 2 | ||||
-rw-r--r-- | src/buildtool/execution_engine/executor/executor.hpp | 8 | ||||
-rw-r--r-- | src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp | 11 | ||||
-rw-r--r-- | src/buildtool/main/build_utils.cpp | 6 | ||||
-rw-r--r-- | src/other_tools/just_mr/fetch.cpp | 5 | ||||
-rw-r--r-- | src/other_tools/just_mr/launch.cpp | 20 | ||||
-rw-r--r-- | src/other_tools/just_mr/mirrors.hpp | 2 | ||||
-rw-r--r-- | src/other_tools/just_mr/update.cpp | 6 | ||||
-rw-r--r-- | src/other_tools/repo_map/repos_to_setup_map.cpp | 10 |
12 files changed, 64 insertions, 53 deletions
diff --git a/src/buildtool/build_engine/expression/evaluator.cpp b/src/buildtool/build_engine/expression/evaluator.cpp index 3283c2b1..0aa553e8 100644 --- a/src/buildtool/build_engine/expression/evaluator.cpp +++ b/src/buildtool/build_engine/expression/evaluator.cpp @@ -840,14 +840,11 @@ auto LookupExpr(SubExprEvaluator&& eval, throw Evaluator::EvaluationError{fmt::format( "Map expected to be mapping but found {}.", d->ToString())}; } - auto lookup = Expression::kNone; - if (d->Map().contains(k->String())) { - lookup = d->Map().at(k->String()); + auto const& lookup = d->Map().Find(k->String()); + if (lookup and (*lookup)->IsNotNull()) { + return **lookup; } - if (lookup->IsNone()) { - lookup = eval(expr->Get("default", Expression::none_t()), env); - } - return lookup; + return eval(expr->Get("default", Expression::none_t()), env); } auto ArrayAccessExpr(SubExprEvaluator&& eval, @@ -936,7 +933,7 @@ auto ToSubdirExpr(SubExprEvaluator&& eval, else { for (auto const& el : d->Map()) { auto new_key = ToNormalPath(subdir / el.first).string(); - if (auto it = result.find(new_key); + if (auto const it = result.find(new_key); it != result.end() and (not((it->second == el.second) and el.second->IsCacheable()))) { auto msg_expr = expr->Map().Find("msg"); @@ -979,7 +976,7 @@ auto FromSubdirExpr(SubExprEvaluator&& eval, std::filesystem::path(el.first).lexically_relative(subdir)); if (PathIsNonUpwards(new_path)) { auto new_key = new_path.string(); - if (auto it = result.find(new_key); + if (auto const it = result.find(new_key); it != result.end() && (!((it->second == el.second) && el.second->IsCacheable()))) { throw Evaluator::EvaluationError{ diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index ff4db0bb..096044e0 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -26,6 +26,7 @@ #include <string> #include <thread> #include <type_traits> +#include <unordered_map> #include <vector> #include "CLI/CLI.hpp" @@ -705,8 +706,9 @@ static inline auto SetupToAddArguments( app->add_option_function<std::string>( "--resolve-special", [clargs](auto const& raw_value) { - if (kResolveSpecialMap.contains(raw_value)) { - clargs->resolve_special = kResolveSpecialMap.at(raw_value); + if (auto const it = kResolveSpecialMap.find(raw_value); + it != kResolveSpecialMap.end()) { + clargs->resolve_special = it->second; } else { Logger::Log(LogLevel::Warning, diff --git a/src/buildtool/execution_api/common/bytestream_utils.cpp b/src/buildtool/execution_api/common/bytestream_utils.cpp index 93acede8..fa91cd98 100644 --- a/src/buildtool/execution_api/common/bytestream_utils.cpp +++ b/src/buildtool/execution_api/common/bytestream_utils.cpp @@ -34,15 +34,15 @@ namespace { std::size_t shift = 0; for (std::size_t length = 0; shift + length < request.size(); ++length) { - if (request.at(shift + length) == '/') { - parts.emplace_back(&request.at(shift), length); + if (request[shift + length] == '/') { + parts.emplace_back(&request[shift], length); shift += length + 1; length = 0; } } if (shift < request.size()) { - parts.emplace_back(&request.at(shift), request.size() - shift); + parts.emplace_back(&request[shift], request.size() - shift); } } catch (...) { return {}; @@ -80,15 +80,15 @@ auto ByteStreamUtils::ReadRequest::FromString( auto const parts = ::SplitRequest(request); if (parts.size() != kReadRequestPartsCount or - parts.at(kBlobsIndex).compare(ByteStreamUtils::kBlobs) != 0) { + parts[kBlobsIndex].compare(ByteStreamUtils::kBlobs) != 0) { return std::nullopt; } ReadRequest result; - result.instance_name_ = std::string(parts.at(kInstanceNameIndex)); - result.hash_ = std::string(parts.at(kHashIndex)); + result.instance_name_ = std::string(parts[kInstanceNameIndex]); + result.hash_ = std::string(parts[kHashIndex]); try { - result.size_ = std::stoi(std::string(parts.at(kSizeIndex))); + result.size_ = std::stoi(std::string(parts[kSizeIndex])); } catch (...) { return std::nullopt; } @@ -126,17 +126,17 @@ auto ByteStreamUtils::WriteRequest::FromString( auto const parts = ::SplitRequest(request); if (parts.size() != kWriteRequestPartsCount or - parts.at(kUploadsIndex).compare(ByteStreamUtils::kUploads) != 0 or - parts.at(kBlobsIndex).compare(ByteStreamUtils::kBlobs) != 0) { + parts[kUploadsIndex].compare(ByteStreamUtils::kUploads) != 0 or + parts[kBlobsIndex].compare(ByteStreamUtils::kBlobs) != 0) { return std::nullopt; } WriteRequest result; - result.instance_name_ = std::string(parts.at(kInstanceNameIndex)); - result.uuid_ = std::string(parts.at(kUUIDIndex)); - result.hash_ = std::string(parts.at(kHashIndex)); + result.instance_name_ = std::string(parts[kInstanceNameIndex]); + result.uuid_ = std::string(parts[kUUIDIndex]); + result.hash_ = std::string(parts[kHashIndex]); try { - result.size_ = std::stoul(std::string(parts.at(kSizeIndex))); + result.size_ = std::stoul(std::string(parts[kSizeIndex])); } catch (...) { return std::nullopt; } diff --git a/src/buildtool/execution_api/local/local_action.cpp b/src/buildtool/execution_api/local/local_action.cpp index d202233f..174caf08 100644 --- a/src/buildtool/execution_api/local/local_action.cpp +++ b/src/buildtool/execution_api/local/local_action.cpp @@ -337,7 +337,7 @@ auto LocalAction::StageInputs( return false; } for (std::size_t i{}; i < result->paths.size(); ++i) { - if (not StageInput(result->paths.at(i), result->infos.at(i), copies)) { + if (not StageInput(result->paths[i], result->infos[i], copies)) { return false; } } diff --git a/src/buildtool/execution_engine/executor/executor.hpp b/src/buildtool/execution_engine/executor/executor.hpp index f009783d..5f5c2e92 100644 --- a/src/buildtool/execution_engine/executor/executor.hpp +++ b/src/buildtool/execution_engine/executor/executor.hpp @@ -632,8 +632,8 @@ class ExecutorImpl { std::vector<DependencyGraph::NamedArtifactNodePtr> const& artifacts) -> std::optional<ArtifactDigest> { if (artifacts.size() == 1 and - (artifacts.at(0).path == "." or artifacts.at(0).path.empty())) { - auto const& info = artifacts.at(0).node->Content().Info(); + (artifacts[0].path == "." or artifacts[0].path.empty())) { + auto const& info = artifacts[0].node->Content().Info(); if (info and IsTreeObject(info->type)) { // Artifact list contains single tree with path "." or "". Reuse // the existing tree artifact by returning its digest. @@ -831,7 +831,7 @@ class ExecutorImpl { msg << nlohmann::json(action->Env()).dump(); } auto const& origin_map = progress->OriginMap(); - auto origins = origin_map.find(action->Content().Id()); + auto const origins = origin_map.find(action->Content().Id()); if (origins != origin_map.end() and not origins->second.empty()) { msg << "\nrequested by"; for (auto const& origin : origins->second) { @@ -887,7 +887,7 @@ class ExecutorImpl { remote_context->exec_config->dispatch) { bool match = true; for (auto const& [k, v] : pred) { - auto v_it = properties.find(k); + auto const v_it = properties.find(k); if (not(v_it != properties.end() and v_it->second == v)) { match = false; } diff --git a/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp b/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp index ecf08e8e..fb7d3bf0 100644 --- a/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp +++ b/src/buildtool/execution_engine/tree_operations/tree_operations_utils.cpp @@ -221,9 +221,16 @@ auto TreeOperationsUtils::SerializeGitTree( } auto it = git_entries.find(*git_hash); if (it == git_entries.end()) { - git_entries.insert({*git_hash, std::vector<GitRepo::TreeEntry>{}}); + if (auto res = git_entries.insert( + {*git_hash, std::vector<GitRepo::TreeEntry>{}}); + res.second) { + it = std::move(res).first; + } + else { + return std::nullopt; + } } - git_entries.at(*git_hash).emplace_back(name, entry.info.type); + it->second.emplace_back(name, entry.info.type); } // Serialize git entries. diff --git a/src/buildtool/main/build_utils.cpp b/src/buildtool/main/build_utils.cpp index 684d2dd1..17b26d80 100644 --- a/src/buildtool/main/build_utils.cpp +++ b/src/buildtool/main/build_utils.cpp @@ -92,7 +92,8 @@ auto CreateTargetCacheWriterMap( // get the TaretCacheKey corresponding to this Id TargetCacheKey tc_key{key}; // check if entry actually needs storing - if (not cache_targets.contains(tc_key)) { + auto const tc_key_it = cache_targets.find(tc_key); + if (tc_key_it == cache_targets.end()) { if (tc.Read(tc_key)) { // entry already in target-cache, so nothing to be done (*setter)(nullptr); @@ -104,9 +105,8 @@ auto CreateTargetCacheWriterMap( true); return; } - auto const& target = cache_targets.at(tc_key); auto entry = TargetCacheEntry::FromTarget( - apis->remote->GetHashType(), target, extra_infos); + apis->remote->GetHashType(), tc_key_it->second, extra_infos); if (not entry) { (*logger)( fmt::format("Failed creating target cache entry for key {}", diff --git a/src/other_tools/just_mr/fetch.cpp b/src/other_tools/just_mr/fetch.cpp index 3585d2f3..a7afc575 100644 --- a/src/other_tools/just_mr/fetch.cpp +++ b/src/other_tools/just_mr/fetch.cpp @@ -223,7 +223,8 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config, return kExitFetchError; } auto repo_type_str = repo_type->get()->String(); - if (not kCheckoutTypeMap.contains(repo_type_str)) { + auto const checkout_type_it = kCheckoutTypeMap.find(repo_type_str); + if (checkout_type_it == kCheckoutTypeMap.end()) { Logger::Log(LogLevel::Error, "Config: Unknown repository type {} for {}", nlohmann::json(repo_type_str).dump(), @@ -231,7 +232,7 @@ auto MultiRepoFetch(std::shared_ptr<Configuration> const& config, return kExitFetchError; } // only do work if repo is archive or git tree type - switch (kCheckoutTypeMap.at(repo_type_str)) { + switch (checkout_type_it->second) { case CheckoutType::Archive: { auto logger = std::make_shared<AsyncMapConsumerLogger>( [&repo_name](std::string const& msg, bool fatal) { diff --git a/src/other_tools/just_mr/launch.cpp b/src/other_tools/just_mr/launch.cpp index 0a061031..c085f5be 100644 --- a/src/other_tools/just_mr/launch.cpp +++ b/src/other_tools/just_mr/launch.cpp @@ -93,8 +93,9 @@ auto CallJust(std::optional<std::filesystem::path> const& config_file, std::optional<LockFile> lock{}; if (subcommand and kKnownJustSubcommands.contains(*subcommand)) { + auto const& flags = kKnownJustSubcommands.at(*subcommand); // Read the config file if needed - if (kKnownJustSubcommands.at(*subcommand).config) { + if (flags.config) { auto repo_lock = RepositoryGarbageCollector::SharedLock(storage_config); if (not repo_lock) { @@ -128,15 +129,14 @@ auto CallJust(std::optional<std::filesystem::path> const& config_file, return kExitSetupError; } } - use_build_root = kKnownJustSubcommands.at(*subcommand).build_root; - use_launcher = kKnownJustSubcommands.at(*subcommand).launch; - supports_defines = kKnownJustSubcommands.at(*subcommand).defines; - supports_remote = kKnownJustSubcommands.at(*subcommand).remote; - supports_remote_properties = - kKnownJustSubcommands.at(*subcommand).remote_props; - supports_serve = kKnownJustSubcommands.at(*subcommand).serve; - supports_dispatch = kKnownJustSubcommands.at(*subcommand).dispatch; - does_build = kKnownJustSubcommands.at(*subcommand).does_build; + use_build_root = flags.build_root; + use_launcher = flags.launch; + supports_defines = flags.defines; + supports_remote = flags.remote; + supports_remote_properties = flags.remote_props; + supports_serve = flags.serve; + supports_dispatch = flags.dispatch; + does_build = flags.does_build; } // build just command std::vector<std::string> cmd = {common_args.just_path->string()}; diff --git a/src/other_tools/just_mr/mirrors.hpp b/src/other_tools/just_mr/mirrors.hpp index 7480a839..41351bbb 100644 --- a/src/other_tools/just_mr/mirrors.hpp +++ b/src/other_tools/just_mr/mirrors.hpp @@ -158,7 +158,7 @@ namespace MirrorsUtils { CurlURLHandle::GetHostname(mirror).value_or(std::string{}); auto it = mirrors_by_hostname.find(hostname); if (it != mirrors_by_hostname.end()) { - mirrors_by_hostname.at(hostname).emplace_back(mirror); + it->second.emplace_back(mirror); } else { // add missing or unknown hostnames to fallback list with key "" diff --git a/src/other_tools/just_mr/update.cpp b/src/other_tools/just_mr/update.cpp index e2ed9197..43fd2de6 100644 --- a/src/other_tools/just_mr/update.cpp +++ b/src/other_tools/just_mr/update.cpp @@ -24,6 +24,7 @@ #include <optional> #include <thread> #include <unordered_map> +#include <utility> #include <vector> #include "fmt/core.h" @@ -118,7 +119,8 @@ auto MultiRepoUpdate(std::shared_ptr<Configuration> const& config, return kExitUpdateError; } auto repo_type_str = repo_type->get()->String(); - if (not kCheckoutTypeMap.contains(repo_type_str)) { + auto const checkout_type_it = kCheckoutTypeMap.find(repo_type_str); + if (checkout_type_it == kCheckoutTypeMap.end()) { Logger::Log(LogLevel::Error, "Unknown repository type {} for {}", nlohmann::json(repo_type_str).dump(), @@ -126,7 +128,7 @@ auto MultiRepoUpdate(std::shared_ptr<Configuration> const& config, return kExitUpdateError; } // only do work if repo is git type - if (kCheckoutTypeMap.at(repo_type_str) == CheckoutType::Git) { + if (checkout_type_it->second == CheckoutType::Git) { auto repo_desc_repository = (*resolved_repo_desc)->At("repository"); if (not repo_desc_repository) { 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 4e29ffc2..7aeb69f7 100644 --- a/src/other_tools/repo_map/repos_to_setup_map.cpp +++ b/src/other_tools/repo_map/repos_to_setup_map.cpp @@ -502,7 +502,8 @@ void DistdirCheckout(ExpressionPtr const& repo_desc, } // get repo_type auto repo_type_str = repo_type->get()->String(); - if (not kCheckoutTypeMap.contains(repo_type_str)) { + auto const checkout_type_it = kCheckoutTypeMap.find(repo_type_str); + if (checkout_type_it == kCheckoutTypeMap.end()) { (*logger)(fmt::format("DistdirCheckout: Unknown type {} for " "repository {}", nlohmann::json(repo_type_str).dump(), @@ -511,7 +512,7 @@ void DistdirCheckout(ExpressionPtr const& repo_desc, return; } // only do work if repo is archive type - if (kCheckoutTypeMap.at(repo_type_str) == CheckoutType::Archive) { + if (checkout_type_it->second == CheckoutType::Archive) { auto const archive = ParseArchiveContent(*resolved_repo_desc, dist_repo_name); if (not archive) { @@ -794,7 +795,8 @@ auto CreateReposToSetupMap( } // get repo_type auto repo_type_str = repo_type->get()->String(); - if (not kCheckoutTypeMap.contains(repo_type_str)) { + auto const checkout_type_it = kCheckoutTypeMap.find(repo_type_str); + if (checkout_type_it == kCheckoutTypeMap.end()) { (*logger)( fmt::format("Config: Unknown type {} for repository {}", nlohmann::json(repo_type_str).dump(), @@ -811,7 +813,7 @@ auto CreateReposToSetupMap( fatal); }); // do checkout - switch (kCheckoutTypeMap.at(repo_type_str)) { + switch (checkout_type_it->second) { case CheckoutType::Git: { GitCheckout(*resolved_repo_desc, std::move(repos), |