gpt4 book ai didi

Doxygen EXCLUDE_PATTERNS 正则表达式

转载 作者:行者123 更新时间:2023-12-05 07:24:21 26 4
gpt4 key购买 nike

我试图从我的 doxygen 生成的文档中排除某些文件。我使用的是 1.8.14 版本。

我的文件采用以下命名约定:

/Path2/OtherFile.cs
/Path/DAL.Entity/Source.cs
/Path/DAL.Entity/SourceBase.generated.cs

我想排除所有不以 Base.generated.cs 结尾且位于/Path/内的文件。

由于 doxygen 声称对 exclude_patterns 变量使用正则表达式,因此我最终想到了这个:

.*\\Path\\DAL\..{4,15}\\((?<!Base\.generated).)*

不用说,它没有用。其他多种变体也没有。到目前为止,一个简单的通配符 * 是我实际使用的唯一正则表达式字符。

doxygen 将 QRegExp 用于很多事情,所以我假设这也是用于此变量的库,但甚至是该库的模式的几个变体 claims to support不工作;显然该库充满了错误,但我希望有些东西能起作用。

doxygen 是否真的为这个变量使用了一个正则表达式库?如果是这样,它是哪个图书馆?无论哪种情况,是否有实现我的目标的方法?

最佳答案

我的结论是; 不...Doxygen Doxyfile 不支持真正的正则表达式。尽管他们声称支持。这只是有效的标准通配符。

我们最终找到了一个非常尴尬的解决方案来解决这个问题。

我们所做的是在我们的 CMakeLists.txt 中添加一个宏,它创建一个字符串,其中包含我们想要包含在 INPUT 中的所有内容。手动排除我们不需要的部分。

可悲的是 CMakes 正则表达式也有缺陷。所以我们不能在 LIST(FILTER EXLUDE) 中使用高级正则表达式,例如类似于 LIST(FILTER children EXCLUDE REGEX "^((?!auto​​gen/public).)*$") 中的否定前瞻。 .. 所以即使这个解决方案也不是我们真正想要的。

我们的 CMakeLists.txt 最终看起来像这样

cmake_minimum_required(VERSION 3.9)

project(documentation_html LANGUAGES CXX)

find_package(Doxygen REQUIRED dot)

# Custom macros
## Macro for getting all relevant directories when creating HTML documentain.
## This was created cause the regex matching in Doxygen and CMake are lacking support for more
## advanced syntax.
MACRO(SUBDIRS result current_dir include_regex)
FILE(GLOB_RECURSE children ${current_dir} ${current_dir}/*)
LIST(FILTER children INCLUDE REGEX "${include_regex}")
SET(dir_list "")
FOREACH(child ${children})
get_filename_component(path ${child} DIRECTORY)
IF(${path} MATCHES ".*autogen/public.*$" OR NOT ${path} MATCHES ".*build.*$") # If we have the /source/build/autogen/public folder available we create the doxygen for those interfaces also.
LIST(APPEND dir_list ${path})
ENDIF()
ENDFOREACH()
LIST(REMOVE_DUPLICATES dir_list)
string(REPLACE ";" " " dirs "${dir_list}")
SET(${result} ${dirs})
ENDMACRO()

SUBDIRS(DOCSDIRS "${CMAKE_SOURCE_DIR}/docs" ".*.plantuml$|.*.puml$|.*.md$|.*.txt$|.*.sty$|.*.tex$|")
SUBDIRS(SOURCEDIRS "${CMAKE_SOURCE_DIR}/source" ".*.cpp$|.*.hpp$|.*.h$|.*.md$")

# Common config
set(DOXYGEN_CONFIG_PATH ${CMAKE_SOURCE_DIR}/docs/doxy_config)
set(DOXYGEN_IN ${DOXYGEN_CONFIG_PATH}/Doxyfile.in)
set(DOXYGEN_IMAGE_PATH ${CMAKE_SOURCE_DIR}/docs)
set(DOXYGEN_PLANTUML_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/docs)
set(DOXYGEN_OUTPUT_DIRECTORY docs)

# HTML config
set(DOXYGEN_INPUT "${DOCSDIRS} ${SOURCEDIRS}")
set(DOXYGEN_EXCLUDE_PATTERNS "*/tests/* */.*/*")
set(DOXYGEN_FILE_PATTERNS "*.cpp *.hpp *.h *.md")
set(DOXYGEN_RECURSIVE NO)
set(DOXYGEN_GENERATE_LATEX NO)
set(DOXYGEN_GENERATE_HTML YES)
set(DOXYGEN_HTML_DYNAMIC_MENUS NO)
configure_file(${DOXYGEN_IN} ${CMAKE_BINARY_DIR}/DoxyHTML @ONLY)

add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/DoxyHTML -d Markdown
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating documentation"
VERBATIM)

在 Doxyfile 中,我们为这些字段添加了环境变量

OUTPUT_DIRECTORY       = @DOXYGEN_OUTPUT_DIRECTORY@
INPUT = @DOXYGEN_INPUT@
FILE_PATTERNS = @DOXYGEN_FILE_PATTERNS@
RECURSIVE = @DOXYGEN_RECURSIVE@
EXCLUDE_PATTERNS = @DOXYGEN_EXCLUDE_PATTERNS@
IMAGE_PATH = @DOXYGEN_IMAGE_PATH@
GENERATE_HTML = @DOXYGEN_GENERATE_HTML@
HTML_DYNAMIC_MENUS = @DOXYGEN_HTML_DYNAMIC_MENUS@
GENERATE_LATEX = @DOXYGEN_GENERATE_LATEX@
PLANTUML_INCLUDE_PATH = @DOXYGEN_PLANTUML_INCLUDE_PATH@

在此之后,我们可以运行 cd ./build && cmake ../&& make docs 来创建我们的 html 文档,并将自动生成的接口(interface)包含在我们的源文件夹中,而不包含所有其他目录构建文件夹。

CMakeLists.txt 中实际发生的事情的快速描述

# Macro that gets all directories from current_dir recursively and returns the result to result as a space separated string 
MACRO(SUBDIRS result current_dir include_regex)

# Gets all files recursively from current_dir
FILE(GLOB_RECURSE children ${current_dir} ${current_dir}/*)

# Filter files so we only keep the files that match the include_regex (can't be to advanced regex)
LIST(FILTER children INCLUDE REGEX "${include_regex}")
SET(dir_list "")

# Let us act on all files... :)
FOREACH(child ${children})

# We're only interested in the path. So we get the path part from the file
get_filename_component(path ${child} DIRECTORY)

# Since CMakes regex also is crippled we can't do nice things such as LIST(FILTER children EXCLUDE REGEX "^((?!autogen/public).)*$") which would have been preferred (CMake regex does not understand negative lookahead/lookbehind)... So we ended up with this ugly thing instead... Adding all build/autogen/public paths and not adding any other paths inside build. I guess it would be possible to write this expression in regex without negative lookahead. But I'm both not really fluent in regex (who are... right?) and a bit lazy in this case. We just needed to get this one pointer task done... :P
IF(${path} MATCHES ".*autogen/public.*$" OR NOT ${path} MATCHES ".*build.*$")
LIST(APPEND dir_list ${path})
ENDIF()
ENDFOREACH()

# Remove all duplicates... Since we GLOBed all files there are a lot of them. So this is important or Doxygen INPUT will overflow... I know... I tested...
LIST(REMOVE_DUPLICATES dir_list)

# Convert the dir_list to a space seperated string
string(REPLACE ";" " " dirs "${dir_list}")

# Return the result! Coffee and cinnamon buns for everyone!
SET(${result} ${dirs})
ENDMACRO()

# Get all the pathes that we want to include in our documentation ... this is also where the build folders for the different applications are going to be... with our autogenerated interfaces which we want to keep.
SUBDIRS(SOURCEDIRS "${CMAKE_SOURCE_DIR}/source" ".*.cpp$|.*.hpp$|.*.h$|.*.md$")

# Add the dirs we want to the Doxygen INPUT
set(DOXYGEN_INPUT "${SOURCEDIRS}")

# Normal exlude patterns for stuff we don't want to add. This thing does not support regex... even though it should.
set(DOXYGEN_EXCLUDE_PATTERNS "*/tests/* */.*/*")

# Normal use of the file patterns that we want to keep in the documentation
set(DOXYGEN_FILE_PATTERNS "*.cpp *.hpp *.h *.md")

# IMPORTANT! Since we are creating all the INPUT paths our self we don't want Doxygen to do any recursion for us
set(DOXYGEN_RECURSIVE NO)

# Write the config
configure_file(${DOXYGEN_IN} ${CMAKE_BINARY_DIR}/DoxyHTML @ONLY)

# Create the target that will use that config to create the html documentation
add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/DoxyHTML -d Markdown
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Generating documentation"
VERBATIM)

我知道这不是偶然发现这个问题的任何人想要的答案……不幸的是,这似乎是唯一合理的解决方案……...你们都对我表示最深切的哀悼...

关于Doxygen EXCLUDE_PATTERNS 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55485145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com