diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-04-27 11:12:13 +0200 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2023-04-27 11:39:46 +0200 |
commit | de891b0ec828de9bce1661be2879d83b84ec887d (patch) | |
tree | 966c76f8db21d9e0a5a4f975eb699bce7f8c7ca6 /src | |
parent | d762bfa1953933dfac0a29a74523c25719396b8c (diff) | |
download | justbuild-de891b0ec828de9bce1661be2879d83b84ec887d.tar.gz |
just-mr: Fix config always being required
In just-mr the config file should only be needed if:
1. We call just with a subcommand requiring a config file, or
2. We use one of just-mr's own commands (except version).
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/main.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp index 0e0ec0c3..e115e7e2 100644 --- a/src/other_tools/just_mr/main.cpp +++ b/src/other_tools/just_mr/main.cpp @@ -495,8 +495,14 @@ void SetupLogging(MultiRepoLogArguments const& clargs) { } [[nodiscard]] auto ReadConfiguration( - std::filesystem::path const& config_file) noexcept + std::optional<std::filesystem::path> const& config_file_opt) noexcept -> std::shared_ptr<Configuration> { + if (not config_file_opt) { + Logger::Log(LogLevel::Error, "Cannot find repository configuration."); + std::exit(kExitConfigError); + } + auto const& config_file = *config_file_opt; + std::shared_ptr<Configuration> config{nullptr}; if (not FileSystemManager::IsFile(config_file)) { Logger::Log(LogLevel::Error, @@ -1243,9 +1249,10 @@ void DefaultReachableRepositories( } /// \brief Runs execvp for given command. Only returns if execvp fails. -[[nodiscard]] auto CallJust(std::shared_ptr<Configuration> const& config, - CommandLineArguments const& arguments, - bool forward_build_root) -> int { +[[nodiscard]] auto CallJust( + std::optional<std::filesystem::path> const& config_file, + CommandLineArguments const& arguments, + bool forward_build_root) -> int { // check if subcmd_name can be taken from additional args auto additional_args_offset = 0U; auto subcommand = arguments.just_cmd.subcmd_name; @@ -1262,7 +1269,10 @@ void DefaultReachableRepositories( std::optional<std::filesystem::path> mr_config_path{std::nullopt}; if (subcommand and kKnownJustSubcommands.contains(*subcommand)) { + // Read the config file if needed if (kKnownJustSubcommands.at(*subcommand).config) { + auto config = ReadConfiguration(config_file); + use_config = true; mr_config_path = MultiRepoSetup(config, arguments, /*interactive=*/false); @@ -1390,13 +1400,6 @@ auto main(int argc, char* argv[]) -> int { if (arguments.common.repository_config) { config_file = arguments.common.repository_config; } - if (not config_file) { - Logger::Log(LogLevel::Error, - "Cannot find repository configuration."); - std::exit(kExitConfigError); - } - - auto config = ReadConfiguration(*config_file); // if optional args were not read from just-mrrc or given by user, use // the defaults @@ -1481,9 +1484,12 @@ auto main(int argc, char* argv[]) -> int { // Run subcommands known to just and `do` if (arguments.cmd == SubCommand::kJustDo or arguments.cmd == SubCommand::kJustSubCmd) { - return CallJust(config, arguments, forward_build_root); + return CallJust(config_file, arguments, forward_build_root); } + // The remaining options all need the config file + auto config = ReadConfiguration(config_file); + // Run subcommand `setup` or `setup-env` if (arguments.cmd == SubCommand::kSetup or arguments.cmd == SubCommand::kSetupEnv) { |