Back to a shared library for the runner.

This commit is contained in:
Mikaël Capelle
2022-05-08 16:05:26 +02:00
parent 40c6119515
commit 2eabaf1774
7 changed files with 56 additions and 30 deletions
+14 -14
View File
@@ -4,70 +4,70 @@
<context>
<name>ProxyPython</name>
<message>
<location filename="proxy/proxypython.cpp" line="97"/>
<location filename="proxy/proxypython.cpp" line="121"/>
<source>Python Initialization failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="98"/>
<location filename="proxy/proxypython.cpp" line="122"/>
<source>On a previous start the Python Plugin failed to initialize.
Do you want to try initializing python again (at the risk of another crash)?
Suggestion: Select &quot;no&quot;, and click the warning sign for further help.Afterwards you have to re-enable the python plugin.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="149"/>
<location filename="proxy/proxypython.cpp" line="173"/>
<source>Python Proxy</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="159"/>
<location filename="proxy/proxypython.cpp" line="183"/>
<source>Proxy Plugin to allow plugins written in python to be loaded</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="231"/>
<location filename="proxy/proxypython.cpp" line="255"/>
<source>ModOrganizer path contains a semicolon</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="233"/>
<location filename="proxy/proxypython.cpp" line="257"/>
<source>Python DLL not found</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="235"/>
<location filename="proxy/proxypython.cpp" line="259"/>
<source>Invalid Python DLL</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="237"/>
<location filename="proxy/proxypython.cpp" line="261"/>
<source>Initializing Python failed</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="239"/>
<location filename="proxy/proxypython.cpp" line="269"/>
<location filename="proxy/proxypython.cpp" line="263"/>
<location filename="proxy/proxypython.cpp" line="293"/>
<source>invalid problem key %1</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="247"/>
<location filename="proxy/proxypython.cpp" line="271"/>
<source>The path to Mod Organizer (%1) contains a semicolon. &lt;br&gt;While this is legal on NTFS drives, many softwares do not handle it correctly.&lt;br&gt;Unfortunately MO depends on libraries that seem to fall into that group.&lt;br&gt;As a result the python plugin cannot be loaded, and the only solution we canoffer is to remove the semicolon or move MO to a path without a semicolon.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="258"/>
<location filename="proxy/proxypython.cpp" line="282"/>
<source>The Python plugin DLL was not found, maybe your antivirus deleted it. Re-installing MO2 might fix the problem.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="261"/>
<location filename="proxy/proxypython.cpp" line="285"/>
<source>The Python plugin DLL is invalid, maybe your antivirus is blocking it. Re-installing MO2 and adding exclusions for it to your AV might fix the problem.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="proxy/proxypython.cpp" line="266"/>
<location filename="proxy/proxypython.cpp" line="290"/>
<source>The initialization of the Python plugin DLL failed, unfortunately without any details.</source>
<translation type="unfinished"></translation>
</message>
+8 -2
View File
@@ -15,6 +15,12 @@ target_link_libraries(proxy PRIVATE runner)
set_target_properties(proxy PROPERTIES OUTPUT_NAME ${PLUGIN_NAME})
mo2_install_target(proxy FOLDER)
set(PLUGIN_PYTHON_DIR ${MO2_INSTALL_PATH}/bin/plugins/${PLUGIN_NAME})
# install runner
target_link_options(proxy PRIVATE "/DELAYLOAD:runner.dll")
mo2_install_target(runner INSTALLDIR ${PLUGIN_PYTHON_DIR}/dlls)
# translations (custom location)
mo2_add_translations(proxy
TS_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../${PLUGIN_NAME}_en.ts
@@ -25,14 +31,14 @@ mo2_add_translations(proxy
${CMAKE_CURRENT_SOURCE_DIR}/../pybind11-qt)
# install DLLs files needed
set(DLL_DIRS ${MO2_INSTALL_PATH}/bin/plugins/${PLUGIN_NAME}/dlls)
set(DLL_DIRS ${PLUGIN_PYTHON_DIR}/dlls)
file(GLOB dlls_to_install
${PYTHON_BUILD_PATH}/libffi*.dll
${PYTHON_BUILD_PATH}/python${Python_VERSION_SHORT}.dll)
install(FILES ${dlls_to_install} DESTINATION ${DLL_DIRS})
# install Python files
set(PYLIB_DIR ${MO2_INSTALL_PATH}/bin/plugins/${PLUGIN_NAME}/libs)
set(PYLIB_DIR ${PLUGIN_PYTHON_DIR}/libs)
file(GLOB libs_to_install ${PYTHON_BUILD_PATH}/pythoncore/*.pyd)
install(FILES ${libs_to_install} DESTINATION ${PYLIB_DIR})
install(FILES ${PYTHON_BUILD_PATH}/pythoncore/python${Python_VERSION_SHORT}.zip
+21 -11
View File
@@ -54,7 +54,8 @@ fs::path getPluginFolder()
}
ProxyPython::ProxyPython()
: m_MOInfo{nullptr}, m_Runner{nullptr}, m_LoadFailure(FailureType::NONE)
: m_MOInfo{nullptr}, m_RunnerLib{nullptr}, m_Runner{nullptr},
m_LoadFailure(FailureType::NONE)
{
}
@@ -81,16 +82,6 @@ bool ProxyPython::init(IOrganizer* moInfo)
return false;
}
// load the pythonrunner library
const auto dllPaths = pluginFolder / "dlls";
if (SetDllDirectoryW(dllPaths.c_str()) == 0) {
DWORD error = ::GetLastError();
m_LoadFailure = FailureType::DLL_NOT_FOUND;
log::error("failed to add python DLL directory ({}): {}", error,
qUtf8Printable(windowsErrorString(::GetLastError())));
return false;
}
if (m_MOInfo && m_MOInfo->persistent(name(), "tryInit", false).toBool()) {
m_LoadFailure = FailureType::INITIALIZATION;
if (QMessageBox::question(
@@ -115,6 +106,25 @@ bool ProxyPython::init(IOrganizer* moInfo)
m_MOInfo->setPersistent(name(), "tryInit", true);
}
// load the pythonrunner library, this is done in multiple steps:
//
// 1. we set the dlls/ subfolder (from the plugin) as the DLL directory so Windows
// will look for DLLs in it, this is required to find the Python and libffi DLL, but
// also the runner DLL
//
const auto dllPaths = pluginFolder / "dlls";
if (SetDllDirectoryW(dllPaths.c_str()) == 0) {
DWORD error = ::GetLastError();
m_LoadFailure = FailureType::DLL_NOT_FOUND;
log::error("failed to add python DLL directory ({}): {}", error,
qUtf8Printable(windowsErrorString(::GetLastError())));
return false;
}
// 2. we create the Python runner, we do not need to use ::LinkLibrary and
// ::GetProcAddress because we use delayed load for the runner DLL (see the
// CMakeLists.txt)
//
m_Runner = mo2::python::createPythonRunner();
if (m_Runner) {
+1
View File
@@ -59,6 +59,7 @@ public: // IPluginDiagnose
private:
MOBase::IOrganizer* m_MOInfo;
HMODULE m_RunnerLib;
std::unique_ptr<mo2::python::IPythonRunner> m_Runner;
enum class FailureType : unsigned int {
+4 -2
View File
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16)
add_library(runner STATIC)
add_library(runner SHARED)
mo2_configure_library(runner
SOURCE_TREE
WARNINGS 4
@@ -11,7 +11,9 @@ mo2_configure_library(runner
)
target_link_libraries(runner PRIVATE pybind11::embed pybind11::qt)
target_include_directories(runner PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
mo2_install_target(runner)
target_compile_definitions(runner PRIVATE RUNNER_BUILD)
# proxy will install runner
# force runner to build mobase
add_dependencies(runner mobase)
+7 -1
View File
@@ -8,6 +8,12 @@
#include <QString>
#include <QStringList>
#ifdef RUNNER_BUILD
#define RUNNER_DLL_EXPORT Q_DECL_EXPORT
#else
#define RUNNER_DLL_EXPORT Q_DECL_IMPORT
#endif
namespace mo2::python {
// python runner interface
@@ -34,7 +40,7 @@ namespace mo2::python {
// create the Python runner
//
std::unique_ptr<IPythonRunner> createPythonRunner();
RUNNER_DLL_EXPORT std::unique_ptr<IPythonRunner> createPythonRunner();
} // namespace mo2::python
+1
View File
@@ -33,6 +33,7 @@ set(PYTHONPATH "${PYLIB_DIR}\\;$<TARGET_FILE_DIR:mobase>\\;${pythoncore}\\;${pyt
set(extra_paths "${MO2_INSTALL_PATH}/bin/dlls")
string(APPEND extra_paths "\\;${PYTHON_ROOT}/PCbuild/amd64")
string(APPEND extra_paths "\\;$<TARGET_FILE_DIR:runner>")
set_tests_properties(${runner-tests_gtests}
PROPERTIES
WORKING_DIRECTORY "${MO2_INSTALL_PATH}/bin"