| 39 | struct CreateConfig { |
| 40 | |
| 41 | CreateConfig(std::filesystem::path path, std::string prefix) : prefix(prefix) { |
| 42 | // Load JSON |
| 43 | std::ifstream config_file(path); |
| 44 | Json::Value config_json; |
| 45 | config_file >> config_json; |
| 46 | config_file.close(); |
| 47 | Json::Value::Object config = config_json.get<Json::Value::Object>(); |
| 48 | |
| 49 | // prefix |
| 50 | if(prefix.empty() && config.contains("prefix")){ |
| 51 | this->prefix = config["prefix"].get<std::string>(); |
| 52 | } |
| 53 | |
| 54 | // paths |
| 55 | if(config.contains("paths")){ |
| 56 | for(Json::Value value : config["paths"].get<Json::Value::Array>()){ |
| 57 | value.visit(overloaded { |
| 58 | [](auto&){ |
| 59 | throw Exception::Exception("invalid path type"); |
| 60 | }, |
| 61 | [&](Json::Value::String& path_str){ |
| 62 | auto parsed = parse_create_path(path_str); |
| 63 | if(!std::filesystem::exists(parsed.first)){ |
| 64 | Exception::Warning(std::string("file ") + parsed.first.string() + " not found, skipped"); |
| 65 | return; |
| 66 | } |
| 67 | std::filesystem::path file_path = std::filesystem::canonical(parsed.first); |
| 68 | if(paths.contains(file_path)){ |
| 69 | Exception::Warning(std::string("multiple definitions found for file ") + parsed.first.string()); |
| 70 | } |
| 71 | paths[file_path] = parsed.second.value_or(std::filesystem::relative(file_path)); |
| 72 | }, |
| 73 | [&](Json::Value::Object& path_obj){ |
| 74 | if(!path_obj.contains("file")){ |
| 75 | throw Exception::Exception("invalid path object"); |
| 76 | } |
| 77 | std::filesystem::path file_path = path_obj["file"].get<std::string>(); |
| 78 | if(!std::filesystem::exists(file_path)){ |
| 79 | Exception::Warning(std::string("file ") + file_path.string() + " not found, skipped"); |
| 80 | return; |
| 81 | } |
| 82 | std::filesystem::path canon = std::filesystem::canonical(file_path); |
| 83 | if(paths.contains(canon)){ |
| 84 | Exception::Warning(std::string("multiple definitions found for file ") + file_path.string()); |
| 85 | } |
| 86 | if(path_obj.contains("module")){ |
| 87 | paths[canon] = path_obj["module"].get<std::string>(); |
| 88 | }else{ |
| 89 | paths[canon] = std::filesystem::relative(canon); |
| 90 | } |
| 91 | } |
| 92 | }); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | std::filesystem::path prefix; |
| 98 | std::map<std::filesystem::path, std::filesystem::path> paths; |
nothing calls this directly
no test coverage detected