diff options
author | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-12-23 17:02:24 +0100 |
---|---|---|
committer | Paul Cristian Sarbu <paul.cristian.sarbu@huawei.com> | 2022-12-23 18:29:02 +0100 |
commit | e86cf7ad0d9e5fe2e711e82d6a573d16436c3cf5 (patch) | |
tree | 60802c44802ad5fb08f18f7ddb4df522019beb30 /src | |
parent | bac42ee6f84248309e082845e7ea835527cda39b (diff) | |
download | justbuild-e86cf7ad0d9e5fe2e711e82d6a573d16436c3cf5.tar.gz |
Just-MR: Fix mrrc config handling
The parser was exiting early when the user gave no rc file, before
having the chance to look for the config file in the default locations.
Diffstat (limited to 'src')
-rw-r--r-- | src/other_tools/just_mr/main.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp index d167c87f..20e1df7c 100644 --- a/src/other_tools/just_mr/main.cpp +++ b/src/other_tools/just_mr/main.cpp @@ -217,7 +217,7 @@ void SetupDefaultLogging() { auto path = location->Get("path", Expression::none_t{}); auto base = location->Get("base", std::string(".")); - if (not path.IsNotNull() or not root.IsNotNull() or + if (not path->IsString() or not root->IsString() or not kLocationTypes.contains(root->String())) { Logger::Log(LogLevel::Error, "Malformed location object: {}", @@ -260,13 +260,9 @@ void SetupDefaultLogging() { // set default if rcpath not given if (not clargs->common.norc) { if (not rc_path) { - if (not FileSystemManager::IsFile(kDefaultRCPath)) { - return std::nullopt; - } rc_path = kDefaultRCPath; } else { - if (not FileSystemManager::IsFile(*rc_path)) { Logger::Log(LogLevel::Error, "Cannot read RC file {}.", @@ -274,22 +270,27 @@ void SetupDefaultLogging() { std::exit(kExitConfigError); } } - try { - std::ifstream fs(*rc_path); - auto map = Expression::FromJson(nlohmann::json::parse(fs)); - if (not map->IsMap()) { + if (FileSystemManager::IsFile(*rc_path)) { + // json::parse may throw + try { + std::ifstream fs(*rc_path); + auto map = Expression::FromJson(nlohmann::json::parse(fs)); + if (not map->IsMap()) { + Logger::Log( + LogLevel::Error, + "In RC file {}: expected an object but found:\n{}", + rc_path->string(), + map->ToString()); + std::exit(kExitConfigError); + } + rc_config = Configuration{map}; + } catch (std::exception const& e) { Logger::Log(LogLevel::Error, - "RC file {} does not contain a JSON object.", - rc_path->string()); + "Parsing RC file {} as JSON failed with error:\n{}", + rc_path->string(), + e.what()); std::exit(kExitConfigError); } - rc_config = Configuration{map}; - } catch (std::exception const& e) { - Logger::Log(LogLevel::Error, - "Parsing RC file {} failed with error:\n{}", - rc_path->string(), - e.what()); - std::exit(kExitConfigError); } } // read local build root; overwritten if user provided it already |