| 985 | } |
| 986 | |
| 987 | SC::Result SC::PluginRegistry::loadPlugin(StringSpan identifier, const PluginCompiler& compiler, |
| 988 | const PluginSysroot& sysroot, StringSpan executablePath, LoadMode loadMode) |
| 989 | { |
| 990 | PluginDynamicLibrary* res = findPlugin(identifier); |
| 991 | SC_TRY_MSG(res != nullptr, "loadplugin res == nullptr"); |
| 992 | PluginDynamicLibrary& lib = *res; |
| 993 | if (loadMode == LoadMode::Reload or not lib.dynamicLibrary.isValid()) |
| 994 | { |
| 995 | // TODO: Shield against circular dependencies |
| 996 | for (const auto& dependency : lib.definition.dependencies) |
| 997 | { |
| 998 | SC_TRY(loadPlugin(dependency.view(), compiler, sysroot, executablePath, LoadMode::Load)); |
| 999 | } |
| 1000 | if (lib.dynamicLibrary.isValid()) |
| 1001 | { |
| 1002 | SC_TRY_MSG(unloadPlugin(identifier), "unload plugin"); |
| 1003 | } |
| 1004 | SC_TRY(lib.load(compiler, sysroot, executablePath)); |
| 1005 | SC_TRY_MSG(lib.pluginInit(lib.instance), "PluginInit failed"); // TODO: Return actual failure strings |
| 1006 | return Result(true); |
| 1007 | } |
| 1008 | return Result(true); |
| 1009 | } |
| 1010 | |
| 1011 | SC::Result SC::PluginRegistry::unloadPlugin(StringSpan identifier) { return unloadPlugin(identifier, true); } |
| 1012 | |