diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-04-14 12:20:55 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-04-14 14:37:07 +0200 |
commit | 2fa19d98f7e4024da9dc6c9bb8f0071f966c3ae7 (patch) | |
tree | 83657ce4b5322138a5e53d90d64dc3024dd553f1 /src/other_tools/just_mr/main.cpp | |
parent | ec4820b68c6c6957cf621f5339164ff28861ef1d (diff) | |
download | justbuild-2fa19d98f7e4024da9dc6c9bb8f0071f966c3ae7.tar.gz |
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.
Diffstat (limited to 'src/other_tools/just_mr/main.cpp')
-rw-r--r-- | src/other_tools/just_mr/main.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
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<std::filesystem::path> 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<std::string> 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 : |