Skip to content

Commit

Permalink
Implement generate_doc_source for cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
enetheru committed Jan 11, 2025
1 parent 4d1237f commit 54032a4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
41 changes: 36 additions & 5 deletions cmake/python_callouts.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ Its usage is listed as:
]]
function( build_profile_generate_trimmed_api BUILD_PROFILE INPUT_JSON OUTPUT_JSON )
execute_process(
COMMAND "${Python3_EXECUTABLE}" "build_profile.py" "${BUILD_PROFILE}" "${INPUT_JSON}" "${OUTPUT_JSON}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND "${Python3_EXECUTABLE}"
"${godot-cpp_SOURCE_DIR}/build_profile.py"
"${BUILD_PROFILE}"
"${INPUT_JSON}"
"${OUTPUT_JSON}"
WORKING_DIRECTORY ${godot-cpp_SOURCE_DIR}
)
endfunction( )

Expand All @@ -45,7 +49,7 @@ function( binding_generator_get_file_list OUT_VAR_NAME API_FILEPATH OUTPUT_DIR )
string( REGEX REPLACE "\n *" " " PYTHON_SCRIPT "${PYTHON_SCRIPT}" )

execute_process( COMMAND "${Python3_EXECUTABLE}" "-c" "${PYTHON_SCRIPT}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY "${godot-cpp_SOURCE_DIR}"
OUTPUT_VARIABLE GENERATED_FILES_LIST
OUTPUT_STRIP_TRAILING_WHITESPACE
)
Expand Down Expand Up @@ -91,9 +95,36 @@ function( binding_generator_generate_bindings API_FILE USE_TEMPLATE_GET_NODE, BI
add_custom_command(OUTPUT ${GENERATED_FILES_LIST}
COMMAND "${Python3_EXECUTABLE}" "-c" "${PYTHON_SCRIPT}"
VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY ${godot-cpp_SOURCE_DIR}
MAIN_DEPENDENCY ${GODOT_GDEXTENSION_API_FILE}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/binding_generator.py
DEPENDS ${godot-cpp_SOURCE_DIR}/binding_generator.py
COMMENT "Generating bindings"
)
endfunction( )

#[[ Generate doc_data.cpp
The documentation displayed in the Godot editor is compiled into the extension.
It takes a list of XML source files, and transforms them into a cpp file that
is added to the sources list.]]
function( generate_doc_source OUT_VAR_NAME OUTPUT_PATH XML_SOURCES )
# Transform the CMake list into the content of a python list
# quote and join to form the interior of a python array
list( TRANSFORM XML_SOURCES REPLACE "(.*\.xml)" "'\\1'" )
list( JOIN XML_SOURCES "," XML_SOURCES )

# Python one-liner to run our command
# lists in CMake are just strings delimited by ';', so this works.
set( PYTHON_SCRIPT "from doc_source_generator import generate_doc_source"
"generate_doc_source( '${OUTPUT_PATH}', [${XML_SOURCES}] )" )

add_custom_command( OUTPUT "${OUTPUT_PATH}"
COMMAND "${Python3_EXECUTABLE}" "-c" "${PYTHON_SCRIPT}"
VERBATIM
WORKING_DIRECTORY "${godot-cpp_SOURCE_DIR}"
DEPENDS "${godot-cpp_SOURCE_DIR}/doc_source_generator.py"
COMMENT "Generating Doc Data"
)

# Propagate generated file to caller scope
set( ${OUT_VAR_NAME} "${OUTPUT_PATH}" PARENT_SCOPE )
endfunction()
2 changes: 1 addition & 1 deletion doc_source_generator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

import os
import glob
import os
import zlib


Expand Down
14 changes: 13 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ Integration Testing
-------------------
The Test target used to validate changes in the GitHub CI.
]=======================================================================]

message( STATUS "Testing Integration targets are enabled.")

# Generate Doc Data
file( GLOB_RECURSE DOC_XML
LIST_DIRECTORIES NO
CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/doc_classes/*.xml )

generate_doc_source( DOC_DATA "${CMAKE_CURRENT_BINARY_DIR}/gen/doc_data.cpp" "${DOC_XML}" )

foreach( TARGET_ALIAS template_debug template_release editor )
set( TARGET_NAME "godot-cpp.test.${TARGET_ALIAS}" )
set( LINK_TARGET "godot-cpp::${TARGET_ALIAS}" )
Expand All @@ -23,6 +30,11 @@ foreach( TARGET_ALIAS template_debug template_release editor )
src/tests.h
)

# conditionally add doc data to compile output
if( TARGET_ALIAS MATCHES "editor|template_debug" )
target_sources( ${TARGET_NAME} PRIVATE "${DOC_DATA}" )
endif( )

target_link_libraries( ${TARGET_NAME} PRIVATE ${LINK_TARGET} )

### Get useful properties of the library
Expand Down
3 changes: 1 addition & 2 deletions tools/godotcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@

from binding_generator import _generate_bindings, _get_file_list, get_file_list
from build_profile import generate_trimmed_api

from binding_generator import scons_generate_bindings, scons_emit_files
from doc_source_generator import scons_generate_doc_source


def add_sources(sources, dir, extension):
for f in os.listdir(dir):
if f.endswith("." + extension):
Expand Down

0 comments on commit 54032a4

Please sign in to comment.