From 2fa19d98f7e4024da9dc6c9bb8f0071f966c3ae7 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Fri, 14 Apr 2023 12:20:55 +0200 Subject: just-mr support -D option Make just-mr unconditionally support an option -D that collects a configuration overlay and forwards it to the invocation of a just subcommand that supports this option. This syntax-switching facility makes it easy to embedd dynamic parts of the configuration (like the head commit to be part of a version string) as those information can unconditionally be the first argument to just-mr. --- src/other_tools/just_mr/main.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/other_tools/just_mr/main.cpp') diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp index 72dd7b79..6c172e6a 100644 --- a/src/other_tools/just_mr/main.cpp +++ b/src/other_tools/just_mr/main.cpp @@ -1259,6 +1259,7 @@ void DefaultReachableRepositories( bool use_config{false}; bool use_build_root{false}; bool use_launcher{false}; + bool supports_defines{false}; std::optional mr_config_path{std::nullopt}; if (subcommand and kKnownJustSubcommands.contains(*subcommand)) { @@ -1275,6 +1276,7 @@ void DefaultReachableRepositories( } use_build_root = kKnownJustSubcommands.at(*subcommand).build_root; use_launcher = kKnownJustSubcommands.at(*subcommand).launch; + supports_defines = kKnownJustSubcommands.at(*subcommand).defines; } // build just command std::vector cmd = {arguments.common.just_path->string()}; @@ -1313,6 +1315,31 @@ void DefaultReachableRepositories( if (arguments.log.plain_log) { cmd.emplace_back("--plain-log"); } + if (supports_defines) { + auto overlay_config = Configuration(); + for (auto const& s : arguments.common.defines) { + try { + auto map = Expression::FromJson(nlohmann::json::parse(s)); + if (not map->IsMap()) { + Logger::Log(LogLevel::Error, + "Defines entry {} does not contain a map.", + nlohmann::json(s).dump()); + std::exit(kExitClargsError); + } + overlay_config = overlay_config.Update(map); + } catch (std::exception const& e) { + Logger::Log(LogLevel::Error, + "Parsing defines entry {} failed with error:\n{}", + nlohmann::json(s).dump(), + e.what()); + std::exit(kExitClargsError); + } + } + if (not overlay_config.Expr()->Map().empty()) { + cmd.emplace_back("-D"); + cmd.emplace_back(overlay_config.ToString()); + } + } // add args read from just-mrrc if (subcommand and arguments.just_cmd.just_args.contains(*subcommand)) { for (auto const& subcmd_arg : -- cgit v1.2.3