From ef2da9cbe1d55fd9667ad7fe42792ffd8ed0ec50 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Tue, 5 Dec 2023 13:07:05 +0100 Subject: Add CLI option to set write strategy for target-level cache --- src/buildtool/common/cli.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/buildtool/common/cli.hpp') diff --git a/src/buildtool/common/cli.hpp b/src/buildtool/common/cli.hpp index bdcc5716..9c2bc7e2 100644 --- a/src/buildtool/common/cli.hpp +++ b/src/buildtool/common/cli.hpp @@ -30,6 +30,7 @@ #include "src/buildtool/common/clidefaults.hpp" #include "src/buildtool/compatibility/compatibility.hpp" #include "src/buildtool/logging/log_level.hpp" +#include "src/buildtool/main/build_utils.hpp" #include "src/utils/cpp/path.hpp" constexpr auto kDefaultTimeout = std::chrono::milliseconds{300000}; @@ -103,6 +104,12 @@ struct BuildArguments { bool show_runfiles{false}; }; +/// \brief Arguments related to target-level caching +struct TCArguments { + TargetCacheWriteStrategy target_cache_write_strategy{ + TargetCacheWriteStrategy::Sync}; +}; + /// \brief Arguments required for staging. struct StageArguments { std::filesystem::path output_dir{}; @@ -461,6 +468,26 @@ static inline auto SetupBuildArguments( ->type_name("LOGICAL_PATH"); } +static inline auto SetupTCArguments(gsl::not_null const& app, + gsl::not_null const& tcargs) { + app->add_option_function( + "--target-cache-write-strategy", + [tcargs](auto const& s) { + auto strategy = ToTargetCacheWriteStrategy(s); + if (strategy) { + tcargs->target_cache_write_strategy = *strategy; + } + else { + Logger::Log(LogLevel::Warning, + "Ignoring unknown strategy {} to write " + "target-level cache.", + nlohmann::json(s).dump()); + } + }, + "Strategy for writing target-cache. (Default: sync)") + ->type_name("STRATEGY"); +} + static inline auto SetupStageArguments( gsl::not_null const& app, gsl::not_null const& clargs) { -- cgit v1.2.3