【问题标题】:Doxygen EXCLUDE_PATTERNS regexDoxygen EXCLUDE_PATTERNS 正则表达式
【发布时间】:2019-04-02 23:58:54
【问题描述】:

我正在尝试从我的 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


【解决方案1】:

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

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

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

可悲的是,CMakes 正则表达式也被削弱了。所以我们不能在 LIST(FILTER EXLUDE) 中使用类似于LIST(FILTER children EXCLUDE REGEX "^((?!autogen/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 &amp;&amp; cmake ../ &amp;&amp; make docs 来创建我们的 html 文档,并让它在我们的源文件夹中包含自动生成的接口,而不包括在构建文件夹中的所有其他目录。

简要说明 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)

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

【讨论】:

  • 您写道:“即使他们声称确实如此。”这是在手册中的什么地方写的?
  • 他们的常见问题解答中的第 9 项:star.bnl.gov/public/comp/sofi/doxygen/faq.html 表示他们使用 QRegExp。
  • @JeremeGuenther 说了什么...我还记得在文档中读到了“您可以使用正则表达式排除”的内容。但是我现在找不到了。也许我只是在做梦? ¯_(ツ)_/¯
猜你喜欢
  • 2014-06-22
  • 2015-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-21
相关资源
最近更新 更多