| 10 | namespace chi { |
| 11 | |
| 12 | Result jsonToGraphModule(Context& createInside, const nlohmann::json& input, |
| 13 | const boost::filesystem::path& fullName, GraphModule** toFill) { |
| 14 | Result res; |
| 15 | |
| 16 | auto resCtx = res.addScopedContext({{"Loading Module Name", fullName.string()}, |
| 17 | {"Workspace Path", createInside.workspacePath().string()}}); |
| 18 | |
| 19 | // create the module |
| 20 | auto createdModule = createInside.newGraphModule(fullName); |
| 21 | if (toFill != nullptr) { *toFill = createdModule; } |
| 22 | |
| 23 | // load if it has C enabled |
| 24 | { |
| 25 | auto iter = input.find("has_c_support"); |
| 26 | if (iter == input.end()) { |
| 27 | res.addEntry("EUKN", "No has_c_support section in module JSON, assuming none", {}); |
| 28 | return res; |
| 29 | } |
| 30 | if (!iter->is_boolean()) { |
| 31 | res.addEntry("EUKN", "has_c_support section in module JSON isn't a bool", |
| 32 | {{"Actual Data", *iter}}); |
| 33 | return res; |
| 34 | } |
| 35 | |
| 36 | createdModule->setCEnabled(*iter); |
| 37 | } |
| 38 | |
| 39 | // load dependencies |
| 40 | { |
| 41 | auto iter = input.find("dependencies"); |
| 42 | if (iter == input.end()) { |
| 43 | res.addEntry("E38", "No dependencies element in module", {}); |
| 44 | return res; |
| 45 | } |
| 46 | if (!iter->is_array()) { |
| 47 | res.addEntry("E39", "dependencies element isn't an array", {}); |
| 48 | return res; |
| 49 | } |
| 50 | |
| 51 | for (const auto& dep : *iter) { |
| 52 | if (!dep.is_string()) { |
| 53 | res.addEntry("E40", "dependency isn't a string", {{"Actual Data", dep}}); |
| 54 | continue; |
| 55 | } |
| 56 | |
| 57 | std::string depName = dep; |
| 58 | res += createdModule->addDependency(depName); |
| 59 | |
| 60 | if (!res) { return res; } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | // load types |
| 65 | { |
| 66 | auto iter = input.find("types"); |
| 67 | if (iter == input.end() || !iter->is_object()) { |
| 68 | res.addEntry("EUKN", "No types object in module", {{}}); |
| 69 | return res; |
no test coverage detected