From 8c74c92079d84457b9cb71a682d01c2595f7f285 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 2 Oct 2017 15:54:23 +0100 Subject: [PATCH] Move docstring check from fatal-onstart-hack to unit test run by CI --- qrenderdoc/Code/pyrenderdoc/PythonContext.cpp | 16 ++++++++++ qrenderdoc/Code/pyrenderdoc/PythonContext.h | 2 ++ qrenderdoc/Code/pyrenderdoc/document_check.h | 6 ++-- qrenderdoc/Code/pyrenderdoc/qrenderdoc.i | 25 +++++++++------- qrenderdoc/Code/pyrenderdoc/renderdoc.i | 23 ++++++++++----- qrenderdoc/Code/qrenderdoc.cpp | 29 +++++++++++++++++++ scripts/travis/linux_compile.sh | 1 + 7 files changed, 80 insertions(+), 22 deletions(-) diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index a83a063b0..758b56fc1 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -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(); diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.h b/qrenderdoc/Code/pyrenderdoc/PythonContext.h index 25a9280eb..92e0ed300 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.h +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.h @@ -55,6 +55,8 @@ public: static void GlobalInit(); static void GlobalShutdown(); + bool CheckDocstrings(); + QString versionString(); template diff --git a/qrenderdoc/Code/pyrenderdoc/document_check.h b/qrenderdoc/Code/pyrenderdoc/document_check.h index 9c05f4ca7..bc7a2d279 100644 --- a/qrenderdoc/Code/pyrenderdoc/document_check.h +++ b/qrenderdoc/Code/pyrenderdoc/document_check.h @@ -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; } diff --git a/qrenderdoc/Code/pyrenderdoc/qrenderdoc.i b/qrenderdoc/Code/pyrenderdoc/qrenderdoc.i index 0dd4b6f96..85d58ce8c 100644 --- a/qrenderdoc/Code/pyrenderdoc/qrenderdoc.i +++ b/qrenderdoc/Code/pyrenderdoc/qrenderdoc.i @@ -100,24 +100,29 @@ CONTAINER_TYPEMAPS(QMap) %header %{ #include #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. diff --git a/qrenderdoc/Code/pyrenderdoc/renderdoc.i b/qrenderdoc/Code/pyrenderdoc/renderdoc.i index 97a7e70ee..077cc76b3 100644 --- a/qrenderdoc/Code/pyrenderdoc/renderdoc.i +++ b/qrenderdoc/Code/pyrenderdoc/renderdoc.i @@ -160,20 +160,27 @@ PyObject *PassObjectToPython(const char *type, void *obj) %header %{ #include #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]); %} diff --git a/qrenderdoc/Code/qrenderdoc.cpp b/qrenderdoc/Code/qrenderdoc.cpp index 9fe80cc57..0464a48f2 100644 --- a/qrenderdoc/Code/qrenderdoc.cpp +++ b/qrenderdoc/Code/qrenderdoc.cpp @@ -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; diff --git a/scripts/travis/linux_compile.sh b/scripts/travis/linux_compile.sh index fe09e5293..3cd51f1ea 100644 --- a/scripts/travis/linux_compile.sh +++ b/scripts/travis/linux_compile.sh @@ -25,3 +25,4 @@ make -j2 echo "--- Running unit tests ---" ./bin/renderdoccmd test -t unit +./bin/qrenderdoc --unittest