mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-05 01:20:42 +00:00
Move document checking to a C++ header file
* It's better to edit C++ source natively not in the SWIG file, and also clang-format can format it.
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
/******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2017 Baldur Karlsson
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
inline void check_docstrings(swig_type_info **swig_types, size_t numTypes)
|
||||
{
|
||||
std::set<std::string> docstrings;
|
||||
for(size_t i = 0; i < numTypes; i++)
|
||||
{
|
||||
SwigPyClientData *typeinfo = (SwigPyClientData *)swig_types[i]->clientdata;
|
||||
|
||||
// opaque types have no typeinfo, skip these
|
||||
if(!typeinfo)
|
||||
continue;
|
||||
|
||||
PyTypeObject *typeobj = typeinfo->pytype;
|
||||
|
||||
std::string typedoc = typeobj->tp_doc;
|
||||
|
||||
auto result = docstrings.insert(typedoc);
|
||||
|
||||
if(!result.second)
|
||||
{
|
||||
snprintf(convert_error, sizeof(convert_error) - 1,
|
||||
"Duplicate docstring '%s' found on struct '%s' - are you missing a DOCUMENT()?",
|
||||
typedoc.c_str(), typeobj->tp_name);
|
||||
RENDERDOC_LogMessage(LogType::Fatal, "QTRD", __FILE__, __LINE__, convert_error);
|
||||
}
|
||||
|
||||
PyMethodDef *method = typeobj->tp_methods;
|
||||
|
||||
while(method->ml_doc)
|
||||
{
|
||||
std::string typedoc = method->ml_doc;
|
||||
|
||||
size_t i = 0;
|
||||
while(typedoc[i] == '\n')
|
||||
i++;
|
||||
|
||||
// skip the first line as it's autodoc generated
|
||||
i = typedoc.find('\n', i);
|
||||
if(i != std::string::npos)
|
||||
{
|
||||
while(typedoc[i] == '\n')
|
||||
i++;
|
||||
|
||||
typedoc.erase(0, i);
|
||||
|
||||
result = docstrings.insert(typedoc);
|
||||
|
||||
if(!result.second)
|
||||
{
|
||||
snprintf(
|
||||
convert_error, sizeof(convert_error) - 1,
|
||||
"Duplicate docstring '%s' found on method '%s.%s' - are you missing a DOCUMENT()?",
|
||||
method_doc.c_str(), typeobj->tp_name, method->ml_name);
|
||||
RENDERDOC_LogMessage(LogType::Fatal, "QTRD", __FILE__, __LINE__, convert_error);
|
||||
}
|
||||
}
|
||||
|
||||
method++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
// this file is included from renderdoc.i, it's not a module in itself
|
||||
|
||||
%header %{
|
||||
#include <set>
|
||||
%}
|
||||
|
||||
%init %{
|
||||
// verify that docstrings aren't duplicated, which is a symptom of missing DOCUMENT()
|
||||
// macros around newly added classes/members.
|
||||
#if !defined(RELEASE)
|
||||
static bool doc_checked = false;
|
||||
|
||||
if(!doc_checked)
|
||||
{
|
||||
doc_checked = true;
|
||||
|
||||
std::set<std::string> docstrings;
|
||||
for(size_t i=0; i < sizeof(swig_type_initial)/sizeof(swig_type_initial[0]); i++)
|
||||
{
|
||||
SwigPyClientData *typeinfo = (SwigPyClientData *)swig_type_initial[i]->clientdata;
|
||||
|
||||
// opaque types have no typeinfo, skip these
|
||||
if(!typeinfo) continue;
|
||||
|
||||
PyTypeObject *typeobj = typeinfo->pytype;
|
||||
|
||||
std::string typedoc = typeobj->tp_doc;
|
||||
|
||||
auto result = docstrings.insert(typedoc);
|
||||
|
||||
if(!result.second)
|
||||
{
|
||||
snprintf(convert_error, sizeof(convert_error)-1, "Duplicate docstring '%s' found on struct '%s' - are you missing a DOCUMENT()?", typedoc.c_str(), typeobj->tp_name);
|
||||
RENDERDOC_LogMessage(LogType::Fatal, "QTRD", __FILE__, __LINE__, convert_error);
|
||||
}
|
||||
|
||||
PyMethodDef *method = typeobj->tp_methods;
|
||||
|
||||
while(method->ml_doc)
|
||||
{
|
||||
std::string typedoc = method->ml_doc;
|
||||
|
||||
size_t i = 0;
|
||||
while(typedoc[i] == '\n')
|
||||
i++;
|
||||
|
||||
// skip the first line as it's autodoc generated
|
||||
i = typedoc.find('\n', i);
|
||||
if(i != std::string::npos)
|
||||
{
|
||||
while(typedoc[i] == '\n')
|
||||
i++;
|
||||
|
||||
typedoc.erase(0, i);
|
||||
|
||||
result = docstrings.insert(typedoc);
|
||||
|
||||
if(!result.second)
|
||||
{
|
||||
snprintf(convert_error, sizeof(convert_error)-1, "Duplicate docstring '%s' found on method '%s' - are you missing a DOCUMENT()?", typedoc.c_str(), method->ml_name);
|
||||
RENDERDOC_LogMessage(LogType::Fatal, "QTRD", __FILE__, __LINE__, convert_error);
|
||||
}
|
||||
}
|
||||
|
||||
method++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
@@ -102,4 +102,23 @@ PyObject *PassObjectToPython(const char *type, void *obj)
|
||||
|
||||
%}
|
||||
|
||||
%include "document_check.i"
|
||||
%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;
|
||||
|
||||
if(!doc_checked)
|
||||
{
|
||||
doc_checked = true;
|
||||
|
||||
check_docstrings(swig_type_initial, sizeof(swig_type_initial)/sizeof(swig_type_initial[0]));
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
@@ -210,6 +210,8 @@ HEADERS += Code/CaptureContext.h \
|
||||
Code/QRDUtils.h \
|
||||
Code/Resources.h \
|
||||
Code/pyrenderdoc/PythonContext.h \
|
||||
Code/pyrenderdoc/pyconversion.h \
|
||||
Code/pyrenderdoc/document_check.h \
|
||||
Code/Interface/QRDInterface.h \
|
||||
Code/Interface/CommonPipelineState.h \
|
||||
Code/Interface/PersistantConfig.h \
|
||||
|
||||
@@ -859,6 +859,7 @@
|
||||
<ClInclude Include="Code\Interface\PersistantConfig.h" />
|
||||
<ClInclude Include="Code\Interface\QRDInterface.h" />
|
||||
<ClInclude Include="Code\Interface\RemoteHost.h" />
|
||||
<ClInclude Include="Code\pyrenderdoc\document_check.h" />
|
||||
<ClInclude Include="Code\Resources.h" />
|
||||
<ClInclude Include="$(IntDir)generated\ui_AboutDialog.h" />
|
||||
<ClInclude Include="$(IntDir)generated\ui_APIInspector.h" />
|
||||
@@ -1175,7 +1176,7 @@
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="Code\pyrenderdoc\renderdoc.i">
|
||||
<FileType>Document</FileType>
|
||||
<AdditionalInputs>%(Fullpath);pyconversion.i;document_check.i;$(SolutionDir)renderdoc\api\replay\basic_types.h;$(SolutionDir)renderdoc\api\replay\capture_options.h;$(SolutionDir)renderdoc\api\replay\control_types.h;$(SolutionDir)renderdoc\api\replay\d3d11_pipestate.h;$(SolutionDir)renderdoc\api\replay\d3d12_pipestate.h;$(SolutionDir)renderdoc\api\replay\data_types.h;$(SolutionDir)renderdoc\api\replay\gl_pipestate.h;$(SolutionDir)renderdoc\api\replay\renderdoc_replay.h;$(SolutionDir)renderdoc\api\replay\replay_enums.h;$(SolutionDir)renderdoc\api\replay\shader_types.h;$(SolutionDir)renderdoc\api\replay\vk_pipestate.h;%(AdditionalInputs)</AdditionalInputs>
|
||||
<AdditionalInputs>%(Fullpath);pyconversion.i;document_check.h;$(SolutionDir)renderdoc\api\replay\basic_types.h;$(SolutionDir)renderdoc\api\replay\capture_options.h;$(SolutionDir)renderdoc\api\replay\control_types.h;$(SolutionDir)renderdoc\api\replay\d3d11_pipestate.h;$(SolutionDir)renderdoc\api\replay\d3d12_pipestate.h;$(SolutionDir)renderdoc\api\replay\data_types.h;$(SolutionDir)renderdoc\api\replay\gl_pipestate.h;$(SolutionDir)renderdoc\api\replay\renderdoc_replay.h;$(SolutionDir)renderdoc\api\replay\replay_enums.h;$(SolutionDir)renderdoc\api\replay\shader_types.h;$(SolutionDir)renderdoc\api\replay\vk_pipestate.h;%(AdditionalInputs)</AdditionalInputs>
|
||||
<Command>$(ProjectDir)3rdparty\swig\swig.exe -v -Wextra -Werror -O -c++ -python -modern -modernargs -enumclass -fastunpack -py3 -builtin -I$(SolutionDir)renderdoc\api\replay -outdir $(IntDir)generated -o $(IntDir)generated\%(Filename)_python.cxx %(FullPath)</Command>
|
||||
<Message>Compiling SWIG interface</Message>
|
||||
<Outputs>$(IntDir)generated\%(Filename).py;$(IntDir)generated\%(Filename)_python.cxx;%(Outputs)</Outputs>
|
||||
@@ -1374,7 +1375,6 @@
|
||||
</CustomBuild>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Code\pyrenderdoc\document_check.i" />
|
||||
<None Include="Code\pyrenderdoc\pyconversion.h" />
|
||||
<None Include="Code\pyrenderdoc\pyconversion.i" />
|
||||
<None Include="Resources\128.png" />
|
||||
|
||||
@@ -878,6 +878,9 @@
|
||||
<ClInclude Include="Code\Interface\QRDInterface.h">
|
||||
<Filter>Code\Interface</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Code\pyrenderdoc\document_check.h">
|
||||
<Filter>Code\pyrenderdoc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\128.png">
|
||||
@@ -1060,9 +1063,6 @@
|
||||
<None Include="Code\pyrenderdoc\pyconversion.i">
|
||||
<Filter>Code\pyrenderdoc</Filter>
|
||||
</None>
|
||||
<None Include="Code\pyrenderdoc\document_check.i">
|
||||
<Filter>Code\pyrenderdoc</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Resources\qrenderdoc.rc">
|
||||
|
||||
Reference in New Issue
Block a user