mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-13 17:25:54 +00:00
Move docstring check from fatal-onstart-hack to unit test run by CI
This commit is contained in:
@@ -58,6 +58,10 @@ PyTypeObject **SbkPySide2_QtWidgetsTypes = NULL;
|
||||
#include "Code/QRDUtils.h"
|
||||
#include "PythonContext.h"
|
||||
|
||||
// exported by generated files, used to check docstrings in interfaces
|
||||
bool CheckCoreDocstrings();
|
||||
bool CheckQtDocstrings();
|
||||
|
||||
// defined in SWIG-generated renderdoc_python.cpp
|
||||
extern "C" PyObject *PyInit__renderdoc(void);
|
||||
extern "C" PyObject *PassObjectToPython(const char *type, void *obj);
|
||||
@@ -443,6 +447,18 @@ PythonContext::~PythonContext()
|
||||
outputTick();
|
||||
}
|
||||
|
||||
bool PythonContext::CheckDocstrings()
|
||||
{
|
||||
bool errors = false;
|
||||
|
||||
PyGILState_STATE gil = PyGILState_Ensure();
|
||||
errors |= CheckCoreDocstrings();
|
||||
errors |= CheckQtDocstrings();
|
||||
PyGILState_Release(gil);
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
void PythonContext::Finish()
|
||||
{
|
||||
PyGILState_STATE gil = PyGILState_Ensure();
|
||||
|
||||
@@ -55,6 +55,8 @@ public:
|
||||
static void GlobalInit();
|
||||
static void GlobalShutdown();
|
||||
|
||||
bool CheckDocstrings();
|
||||
|
||||
QString versionString();
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
inline void check_docstrings(swig_type_info **swig_types, size_t numTypes)
|
||||
inline bool check_docstrings(swig_type_info **swig_types, size_t numTypes)
|
||||
{
|
||||
// track all errors and fatal error at the end, so we see all of the problems at once instead of
|
||||
// requiring rebuilds over and over.
|
||||
@@ -180,7 +180,5 @@ inline void check_docstrings(swig_type_info **swig_types, size_t numTypes)
|
||||
}
|
||||
}
|
||||
|
||||
if(errors_found)
|
||||
RENDERDOC_LogMessage(LogType::Fatal, "QTRD", __FILE__, __LINE__,
|
||||
"Found errors in python binding docstrings. Please fix!");
|
||||
return errors_found;
|
||||
}
|
||||
|
||||
@@ -100,24 +100,29 @@ CONTAINER_TYPEMAPS(QMap)
|
||||
%header %{
|
||||
#include <set>
|
||||
#include "Code/pyrenderdoc/document_check.h"
|
||||
%}
|
||||
|
||||
%init %{
|
||||
PyDateTime_IMPORT;
|
||||
|
||||
// verify that docstrings aren't duplicated, which is a symptom of missing DOCUMENT()
|
||||
// macros around newly added classes/members.
|
||||
// For enums, verify that all constants are documented in the parent docstring
|
||||
#if !defined(RELEASE)
|
||||
static bool doc_checked = false;
|
||||
static swig_type_info **docCheckTypes;
|
||||
static size_t docCheckNumTypes = 0;
|
||||
|
||||
if(!doc_checked)
|
||||
bool CheckQtDocstrings()
|
||||
{
|
||||
doc_checked = true;
|
||||
#if defined(RELEASE)
|
||||
return false;
|
||||
#else
|
||||
if(docCheckNumTypes == 0)
|
||||
return false;
|
||||
|
||||
check_docstrings(swig_type_initial, sizeof(swig_type_initial)/sizeof(swig_type_initial[0]));
|
||||
return check_docstrings(docCheckTypes, docCheckNumTypes);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%init %{
|
||||
docCheckTypes = swig_type_initial;
|
||||
docCheckNumTypes = sizeof(swig_type_initial)/sizeof(swig_type_initial[0]);
|
||||
%}
|
||||
|
||||
// declare functions for using swig opaque wrap/unwrap of QWidget, for when pyside isn't available.
|
||||
|
||||
@@ -160,20 +160,27 @@ PyObject *PassObjectToPython(const char *type, void *obj)
|
||||
%header %{
|
||||
#include <set>
|
||||
#include "Code/pyrenderdoc/document_check.h"
|
||||
%}
|
||||
|
||||
%init %{
|
||||
// verify that docstrings aren't duplicated, which is a symptom of missing DOCUMENT()
|
||||
// macros around newly added classes/members.
|
||||
// For enums, verify that all constants are documented in the parent docstring
|
||||
#if !defined(RELEASE)
|
||||
static bool doc_checked = false;
|
||||
static swig_type_info **docCheckTypes;
|
||||
static size_t docCheckNumTypes = 0;
|
||||
|
||||
if(!doc_checked)
|
||||
bool CheckCoreDocstrings()
|
||||
{
|
||||
doc_checked = true;
|
||||
#if defined(RELEASE)
|
||||
return false;
|
||||
#else
|
||||
if(docCheckNumTypes == 0)
|
||||
return false;
|
||||
|
||||
check_docstrings(swig_type_initial, sizeof(swig_type_initial)/sizeof(swig_type_initial[0]));
|
||||
return check_docstrings(docCheckTypes, docCheckNumTypes);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%init %{
|
||||
docCheckTypes = swig_type_initial;
|
||||
docCheckNumTypes = sizeof(swig_type_initial)/sizeof(swig_type_initial[0]);
|
||||
%}
|
||||
|
||||
@@ -66,6 +66,35 @@ int main(int argc, char *argv[])
|
||||
|
||||
qInstallMessageHandler(sharedLogOutput);
|
||||
|
||||
#if !defined(RELEASE)
|
||||
for(int i = 0; i < argc; i++)
|
||||
{
|
||||
if(!QString::compare(QString::fromUtf8(argv[i]), lit("--unittest"), Qt::CaseInsensitive))
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
PythonContext::GlobalInit();
|
||||
|
||||
bool errors = false;
|
||||
|
||||
qInfo() << "Checking python binding docstrings.";
|
||||
|
||||
{
|
||||
PythonContextHandle py;
|
||||
errors = py.ctx().CheckDocstrings();
|
||||
}
|
||||
|
||||
if(errors)
|
||||
{
|
||||
qCritical() << "Found errors in python binding docstrings. Please fix!";
|
||||
return 1;
|
||||
}
|
||||
|
||||
qInfo() << "Python binding docstrings are consistent.";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
qInfo() << "QRenderDoc initialising.";
|
||||
|
||||
QString filename;
|
||||
|
||||
@@ -25,3 +25,4 @@ make -j2
|
||||
echo "--- Running unit tests ---"
|
||||
|
||||
./bin/renderdoccmd test -t unit
|
||||
./bin/qrenderdoc --unittest
|
||||
|
||||
Reference in New Issue
Block a user