Skip to content

Commit

Permalink
feat: we need generated rst files for every component
Browse files Browse the repository at this point in the history
  • Loading branch information
xxthunder committed Jan 4, 2024
1 parent 5a21b92 commit 63b230d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 37 deletions.
58 changes: 51 additions & 7 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ macro(spl_create_component)
list(APPEND COMPONENT_NAMES ${component_name})
set(COMPONENT_NAMES ${COMPONENT_NAMES} PARENT_SCOPE)

# Collect all component paths for later usage (e.g., in an extension)
list(APPEND COMPONENT_PATHS ${component_path})
set(COMPONENT_PATHS ${COMPONENT_PATHS} PARENT_SCOPE)

list(APPEND target_include_directories__INCLUDES ${CMAKE_CURRENT_LIST_DIR}/src)
list(APPEND target_include_directories__INCLUDES ${CMAKE_CURRENT_BINARY_DIR})

Expand Down Expand Up @@ -172,6 +176,41 @@ macro(spl_create_component)
# create the config.json file. This is exported as SPHINX_BUILD_CONFIGURATION_FILE env variable
set(_reports_config_json ${SPHINX_OUTPUT_DIR}/config.json)

# create the test specification rst file
set(_unit_test_spec_rst ${SPHINX_OUTPUT_DIR}/unit_test_spec.rst)
file(WRITE ${_unit_test_spec_rst} "
Unit Test Specification
=======================
.. needtable::
:filter: type == 'test'
:columns: id, title, tests, results
:style: table
")

# create the test results rst file
set(_unit_test_results_rst ${SPHINX_OUTPUT_DIR}/unit_test_results.rst)
file(WRITE ${_unit_test_results_rst} "
Unit Test Results
=================
.. test-report:: Unit Test Results
:id: TEST_RESULT
:file: ${_component_test_junit_xml}
")

# create the code coverage rst file
set(_coverage_rst ${SPHINX_OUTPUT_DIR}/coverage.rst)
file(WRITE ${_coverage_rst} "
Code Coverage
=============
`Report <coverage/index.html>`_
")

# generate Doxyfile from template
set(_component_doxyfile ${SPHINX_OUTPUT_DIR}/Doxyfile)
set(DOXYGEN_PROJECT_NAME "Doxygen Documentation")
Expand All @@ -187,11 +226,10 @@ macro(spl_create_component)
file(RELATIVE_PATH _rel_component_doxysphinx_index_rst ${SPHINX_SOURCE_DIR} ${DOXYGEN_OUTPUT_DIRECTORY}/html/index)

file(WRITE ${_reports_config_json} "{
\"component_doc_dir\": \"${_rel_component_doc_dir}\",
\"component_reports_dir\": \"${SPHINX_OUTPUT_DIR}\",
\"component_test_junit_xml\": \"${_component_test_junit_xml}\",
\"include_patterns\": [\"${_rel_component_doc_dir}/**\",\"${_rel_sphinx_output_dir}/**\"]
}")
\"component_doc_dir\": \"${_rel_component_doc_dir}\",
\"component_reports_dir\": \"${_rel_sphinx_output_dir}\",
\"include_patterns\": [\"${_rel_component_doc_dir}/**\",\"${_rel_sphinx_output_dir}/**\"]
}")

# add the generated files as dependency to cmake configure step
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_reports_config_json} ${_unit_test_spec_rst} ${_unit_test_results_rst} ${_component_doxyfile})
Expand All @@ -205,6 +243,9 @@ macro(spl_create_component)
COMMAND ${CMAKE_COMMAND} -E remove_directory ${SPHINX_OUTPUT_DIR}/html
COMMAND ${CMAKE_COMMAND} -E remove_directory ${SPHINX_OUTPUT_DIR}/doxygen
COMMAND ${CMAKE_COMMAND} -E make_directory ${SPHINX_OUTPUT_DIR}/doxygen

# now comes the mighty tricky part: we need to copy the coverage directory to the html output directory
COMMAND ${CMAKE_COMMAND} -E copy_directory ${SPHINX_OUTPUT_DIR}/coverage ${SPHINX_OUTPUT_DIR}/html/${_rel_sphinx_output_dir}/coverage
COMMAND doxygen ${_rel_component_doxyfile}
COMMAND doxysphinx build ${SPHINX_SOURCE_DIR} ${SPHINX_OUTPUT_HTML_DIR} ${_rel_component_doxyfile}
COMMAND ${CMAKE_COMMAND} -E env SPHINX_BUILD_CONFIGURATION_FILE=${_reports_config_json} AUTOCONF_JSON_FILE=${AUTOCONF_JSON} VARIANT=${VARIANT} -- sphinx-build -b html ${SPHINX_SOURCE_DIR} ${SPHINX_OUTPUT_HTML_DIR}
Expand All @@ -227,10 +268,13 @@ macro(_spl_create_docs_target)

# create the config.json file. This is exported as SPHINX_BUILD_CONFIGURATION_FILE env variable
set(_docs_config_json ${SPHINX_OUTPUT_DIR}/config.json)
list(JOIN COMPONENT_PATHS "\", \"" _component_paths_json)
set(_component_paths_json "[\"${_component_paths_json}\"]")
file(RELATIVE_PATH _rel_sphinx_output_dir ${SPHINX_SOURCE_DIR} ${SPHINX_OUTPUT_DIR})
file(WRITE ${_docs_config_json} "{
\"include_patterns\": [\"${_rel_sphinx_output_dir}/**\"]
}")
\"include_patterns\": [\"${_rel_sphinx_output_dir}/**\", \"src/**\"],
\"component_paths\": ${_component_paths_json}
}")

# add the generated files as dependency to cmake configure step
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${_docs_config_json})
Expand Down
9 changes: 4 additions & 5 deletions cmake/spl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ elseif(BUILD_KIT STREQUAL test)

add_custom_target(coverage)
add_custom_target(reports)
_spl_create_docs_target()
else()
message(FATAL_ERROR "Invalid BUILD_KIT selected!")
endif(BUILD_KIT STREQUAL prod)
Expand All @@ -81,10 +80,10 @@ endif(BUILD_KIT STREQUAL prod)
cmake_language(DEFER DIRECTORY ${CMAKE_SOURCE_DIR} CALL _spl_hook_end_of_configure())

function(_spl_hook_end_of_configure)
_spl_coverage_create_overall_report()

if(CONAN__REQUIRES OR CONAN__BUILD_REQUIRES)
endif() # CONAN__REQUIRES
if(BUILD_KIT STREQUAL test)
_spl_coverage_create_overall_report()
_spl_create_docs_target()
endif(BUILD_KIT STREQUAL test)
endfunction(_spl_hook_end_of_configure)

# # This is one possibility to open guiconfig of kconfiglib. VSCode task is the preferred solution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"**/test_results.rst", # We renamed this file, but nobody deletes it.
]

include_patterns = ["index.rst", "coverage.rst", "definitions.rst", "doc/**"]
include_patterns = ["index.rst", "doc/**"]

# configuration of built-in stuff ###########################################
# @see https://www.sphinx-doc.org/en/master/usage/configuration.html
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Software Component Report

{{ build_config.component_doc_dir }}/index
{% if build_config.component_reports_dir %}
/doc/unit_test_spec
/doc/unit_test_results
{{ build_config.component_reports_dir }}/unit_test_spec
{{ build_config.component_reports_dir }}/unit_test_results
{{ build_config.component_reports_dir }}/doxygen/html/index
coverage
{{ build_config.component_reports_dir }}/coverage
{% endif %}

{% else %}
Expand Down

0 comments on commit 63b230d

Please sign in to comment.