From b857e9cf52951b5c87e25769217c59dbee43acc4 Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Thu, 8 Feb 2024 14:57:27 +0100 Subject: JsonFileMap: refuse to read absent root ... instead of erroring on missing file. In this way, whenever a rule or expression from an absent root would have to be read, we get a meaningful error message and not a complaint about a file not being there. --- src/buildtool/build_engine/base_maps/json_file_map.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/buildtool/build_engine/base_maps/json_file_map.hpp b/src/buildtool/build_engine/base_maps/json_file_map.hpp index f24b3564..79ba7eff 100644 --- a/src/buildtool/build_engine/base_maps/json_file_map.hpp +++ b/src/buildtool/build_engine/base_maps/json_file_map.hpp @@ -47,6 +47,7 @@ auto CreateJsonFileMap(gsl::not_null const& repo_config, auto /* unused */, auto const& key) { auto const* root = ((*repo_config).*get_root)(key.repository); + auto const* json_file_name = ((*repo_config).*get_name)(key.repository); if (root == nullptr or json_file_name == nullptr) { (*logger)(fmt::format("Cannot determine root or JSON file name for " @@ -65,6 +66,20 @@ auto CreateJsonFileMap(gsl::not_null const& repo_config, } auto json_file_path = module / *json_file_name; + if (root->IsAbsent()) { + std::string missing_root = "[unknown]"; + auto absent_tree = root->GetAbsentTreeId(); + if (absent_tree) { + missing_root = *absent_tree; + } + (*logger)(fmt::format( + "Would have to read JSON file {} of absent root {}.", + json_file_path.string(), + missing_root), + true); + return; + } + if (not root->IsFile(json_file_path)) { if constexpr (kMandatory) { (*logger)(fmt::format("JSON file {} does not exist.", -- cgit v1.2.3