mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-12 21:10:42 +00:00
Remove use of unnecessary swig generated .py wrappers
* These .py wrappers are relevant for the non-builtin path, but since we use -builtin they serve no purpose except to make things more complex. * So instead we make the module directly exported as 'module' instead of '_module'. * On windows there's no conflict because we have renderdoc.dll vs renderdoc.pyd. On linux it's librenderdoc.so vs renderdoc.so. * To prevent supporting files like .lib / .pdb from conflicting on windows we build the python modules into a subdirectory. They're not ever used by the UI (it links in the bindings directly).
This commit is contained in:
@@ -63,47 +63,13 @@ bool CheckCoreInterface();
|
||||
bool CheckQtInterface();
|
||||
|
||||
// defined in SWIG-generated renderdoc_python.cpp
|
||||
extern "C" PyObject *PyInit__renderdoc(void);
|
||||
extern "C" PyObject *PyInit_renderdoc(void);
|
||||
extern "C" PyObject *PassObjectToPython(const char *type, void *obj);
|
||||
// this one is in qrenderdoc_python.cpp
|
||||
extern "C" PyObject *PyInit__qrenderdoc(void);
|
||||
extern "C" PyObject *PyInit_qrenderdoc(void);
|
||||
extern "C" PyObject *WrapBareQWidget(QWidget *);
|
||||
extern "C" QWidget *UnwrapBareQWidget(PyObject *);
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
// on Win32 the renderdoc.py is compiled in as a windows resource. Extract and return
|
||||
#include <windows.h>
|
||||
#include "Resources/resource.h"
|
||||
|
||||
QByteArray GetResourceContents(int resource)
|
||||
{
|
||||
HRSRC res = FindResource(NULL, MAKEINTRESOURCE(resource), MAKEINTRESOURCE(TYPE_EMBED));
|
||||
HGLOBAL data = LoadResource(NULL, res);
|
||||
|
||||
if(!data)
|
||||
return QByteArray();
|
||||
|
||||
DWORD resSize = SizeofResource(NULL, res);
|
||||
const char *resData = (const char *)LockResource(data);
|
||||
|
||||
return QByteArray(resData, (int)resSize);
|
||||
}
|
||||
|
||||
#define GetWrapperModule(name) GetResourceContents(name##_py_module)
|
||||
|
||||
#else
|
||||
|
||||
// Otherwise it's compiled in via include-bin which converts to a .c with extern array
|
||||
extern unsigned char renderdoc_py[];
|
||||
extern unsigned int renderdoc_py_len;
|
||||
extern unsigned char qrenderdoc_py[];
|
||||
extern unsigned int qrenderdoc_py_len;
|
||||
|
||||
#define GetWrapperModule(name) QByteArray((const char *)name##_py, (int)name##_py_len);
|
||||
|
||||
#endif
|
||||
|
||||
// little utility function to convert a PyObject * that we know is a string to a QString
|
||||
static inline QString ToQStr(PyObject *value)
|
||||
{
|
||||
@@ -229,8 +195,8 @@ void PythonContext::GlobalInit()
|
||||
// for the exception signal
|
||||
qRegisterMetaType<QList<QString>>("QList<QString>");
|
||||
|
||||
PyImport_AppendInittab("_renderdoc", &PyInit__renderdoc);
|
||||
PyImport_AppendInittab("_qrenderdoc", &PyInit__qrenderdoc);
|
||||
PyImport_AppendInittab("_renderdoc", &PyInit_renderdoc);
|
||||
PyImport_AppendInittab("_qrenderdoc", &PyInit_qrenderdoc);
|
||||
|
||||
#if defined(STATIC_QRENDERDOC)
|
||||
// add the location where our libs will be for statically-linked python installs
|
||||
@@ -251,43 +217,6 @@ void PythonContext::GlobalInit()
|
||||
|
||||
PyEval_InitThreads();
|
||||
|
||||
QByteArray renderdoc_py_src = GetWrapperModule(renderdoc);
|
||||
|
||||
if(renderdoc_py_src.isEmpty())
|
||||
{
|
||||
qCritical() << "renderdoc.py wrapper is corrupt/empty. Check build configuration to ensure "
|
||||
"SWIG compiled properly with python support.";
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray qrenderdoc_py_src = GetWrapperModule(qrenderdoc);
|
||||
|
||||
if(qrenderdoc_py_src.isEmpty())
|
||||
{
|
||||
qCritical() << "qrenderdoc.py wrapper is corrupt/empty. Check build configuration to ensure "
|
||||
"SWIG compiled properly with python support.";
|
||||
return;
|
||||
}
|
||||
|
||||
PyObject *renderdoc_py_compiled =
|
||||
Py_CompileString(renderdoc_py_src.data(), "renderdoc.py", Py_file_input);
|
||||
|
||||
if(!renderdoc_py_compiled)
|
||||
{
|
||||
qCritical() << "Failed to compile renderdoc.py wrapper, python will not be available";
|
||||
return;
|
||||
}
|
||||
|
||||
PyObject *qrenderdoc_py_compiled =
|
||||
Py_CompileString(qrenderdoc_py_src.data(), "qrenderdoc.py", Py_file_input);
|
||||
|
||||
if(!qrenderdoc_py_compiled)
|
||||
{
|
||||
Py_DecRef(renderdoc_py_compiled);
|
||||
qCritical() << "Failed to compile qrenderdoc.py wrapper, python will not be available";
|
||||
return;
|
||||
}
|
||||
|
||||
OutputRedirectorType.tp_name = "renderdoc_output_redirector";
|
||||
OutputRedirectorType.tp_basicsize = sizeof(OutputRedirector);
|
||||
OutputRedirectorType.tp_flags = Py_TPFLAGS_DEFAULT;
|
||||
@@ -302,18 +231,8 @@ void PythonContext::GlobalInit()
|
||||
|
||||
PyObject *main_module = PyImport_AddModule("__main__");
|
||||
|
||||
// for compatibility with earlier versions of python that took a char * instead of const char *
|
||||
char renderdoc_name[] = "renderdoc";
|
||||
char qrenderdoc_name[] = "qrenderdoc";
|
||||
|
||||
PyObject *rdoc_module = PyImport_ExecCodeModule(renderdoc_name, renderdoc_py_compiled);
|
||||
PyObject *qrdoc_module = PyImport_ExecCodeModule(qrenderdoc_name, qrenderdoc_py_compiled);
|
||||
|
||||
Py_XDECREF(renderdoc_py_compiled);
|
||||
Py_XDECREF(qrenderdoc_py_compiled);
|
||||
|
||||
PyModule_AddObject(main_module, "renderdoc", rdoc_module);
|
||||
PyModule_AddObject(main_module, "qrenderdoc", qrdoc_module);
|
||||
PyModule_AddObject(main_module, "renderdoc", PyImport_ImportModule("_renderdoc"));
|
||||
PyModule_AddObject(main_module, "qrenderdoc", PyImport_ImportModule("_qrenderdoc"));
|
||||
|
||||
main_dict = PyModule_GetDict(main_module);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user