| 805 | } |
| 806 | |
| 807 | SC::Result SC::PluginDynamicLibrary::load(const PluginCompiler& compiler, const PluginSysroot& sysroot, |
| 808 | StringSpan executablePath) |
| 809 | { |
| 810 | SC_TRY_MSG(not dynamicLibrary.isValid(), "Dynamic Library must be unloaded first"); |
| 811 | ProcessEnvironment environment; |
| 812 | PluginCompilerEnvironment compilerEnvironment; |
| 813 | |
| 814 | size_t index; |
| 815 | StringSpan name; |
| 816 | if (environment.contains("CFLAGS", &index)) |
| 817 | { |
| 818 | SC_TRY(environment.get(index, name, compilerEnvironment.cFlags)); |
| 819 | } |
| 820 | if (environment.contains("LDFLAGS", &index)) |
| 821 | { |
| 822 | SC_TRY(environment.get(index, name, compilerEnvironment.ldFlags)); |
| 823 | } |
| 824 | lastErrorLog = {}; |
| 825 | |
| 826 | Span<char> lastErrorLogCopy = {errorStorage, sizeof(errorStorage) - 1}; |
| 827 | |
| 828 | auto deferWrite = MakeDeferred( |
| 829 | [&] |
| 830 | { |
| 831 | if (lastErrorLogCopy.sizeInBytes() > 0) |
| 832 | { |
| 833 | const size_t last = lastErrorLogCopy.sizeInBytes() - 1; |
| 834 | lastErrorLogCopy[last] = 0; |
| 835 | } |
| 836 | lastErrorLog = {lastErrorLogCopy, true, StringEncoding::Ascii}; |
| 837 | }); |
| 838 | SC_TRY_MSG(compiler.compile(definition, sysroot, compilerEnvironment, lastErrorLogCopy), "Compile failed"); |
| 839 | #if SC_PLATFORM_WINDOWS |
| 840 | ::Sleep(400); // Sometimes file is locked... |
| 841 | #endif |
| 842 | lastErrorLogCopy = {errorStorage, sizeof(errorStorage) - 1}; |
| 843 | SC_TRY_MSG(compiler.link(definition, sysroot, compilerEnvironment, executablePath, lastErrorLogCopy), "Link fails"); |
| 844 | deferWrite.disarm(); |
| 845 | StringPath buffer; |
| 846 | SC_TRY(definition.getDynamicLibraryAbsolutePath(buffer)); |
| 847 | SC_TRY(dynamicLibrary.load(buffer.view())); |
| 848 | |
| 849 | SC_TRY(PluginString::assign(buffer, {definition.identity.identifier.view(), "Init"})); |
| 850 | SC_TRY_MSG(dynamicLibrary.getSymbol(buffer.view(), pluginInit), "Missing #PluginName#Init"); |
| 851 | SC_TRY(PluginString::assign(buffer, {definition.identity.identifier.view(), "Close"})); |
| 852 | SC_TRY_MSG(dynamicLibrary.getSymbol(buffer.view(), pluginClose), "Missing #PluginName#Close"); |
| 853 | SC_TRY(PluginString::assign(buffer, {definition.identity.identifier.view(), "QueryInterface"})); |
| 854 | (void)(dynamicLibrary.getSymbol(buffer.view(), pluginQueryInterface)); // QueryInterface is optional |
| 855 | numReloads += 1; |
| 856 | lastLoadTime = PluginNow(); |
| 857 | return Result(true); |
| 858 | } |
| 859 | |
| 860 | void SC::PluginRegistry::init(Span<PluginDynamicLibrary> librariesStorage) |
| 861 | { |
no test coverage detected