refactor(eventsub): Allow for skipping generation of json implementations (#5904)

This can be done using the `SKIP_JSON_GENERATION` flag (off by default)

The FreeBSD builder uses this flag since its python stuff is slow
This commit is contained in:
pajlada
2025-02-06 09:21:21 +01:00
committed by GitHub
parent 449aefc6bc
commit 634842d2f5
6 changed files with 36 additions and 25 deletions
+1
View File
@@ -20,6 +20,7 @@ task:
-DUSE_SYSTEM_QTKEYCHAIN="ON" \
-DCMAKE_BUILD_TYPE="release" \
-DCMAKE_EXPORT_COMPILE_COMMANDS="ON" \
-DSKIP_JSON_GENERATION="ON" \
..
cat compile_commands.json
make -j $(getconf _NPROCESSORS_ONLN)
+1 -1
View File
@@ -15,7 +15,7 @@ FreeBSD 15.0-SNAP.
mkdir build
cd build
```
1. Generate build files. To enable Lua plugins in your build add `-DCHATTERINO_PLUGINS=ON` to this command.
1. Generate build files. To enable Lua plugins in your build add `-DCHATTERINO_PLUGINS=ON` to this command. Generating JSON implementation of EventSub blobs is slow (something to do with Python), if you're impatient you can enable the `-DSKIP_JSON_GENERATION=On` option.
```sh
cmake ..
```
+1 -1
View File
@@ -21,7 +21,7 @@
- Bugfix: Fixed the reply button showing for inline whispers and announcements. (#5863)
- Bugfix: Fixed suspicious user treatment update messages not being searchable. (#5865)
- Bugfix: Ensure miniaudio backend exits even if it doesn't exit cleanly. (#5896)
- Dev: Add initial experimental EventSub support. (#5837, #5895, #5897)
- Dev: Add initial experimental EventSub support. (#5837, #5895, #5897, #5904)
- Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784)
- Dev: Removed unused PubSub whisper code. (#5898)
- Dev: Updated Conan dependencies. (#5776)
+1
View File
@@ -17,6 +17,7 @@ find_package(OpenSSL REQUIRED)
option(BUILD_WITH_QT6 "Build with Qt6" On)
option(FORCE_JSON_GENERATION "Make sure JSON implementations are generated at build time" Off)
option(SKIP_JSON_GENERATION "Skip JSON implementations generation at build time" Off)
if (BUILD_WITH_QT6)
set(MAJOR_QT_VERSION "6")
+31 -23
View File
@@ -91,6 +91,7 @@ endfunction()
# [OUTPUT_SOURCES <out-var>]
# [BASE_DIRECTORY <path>]
# [FORCE <force>]
# [SKIP <skip>]
# HEADERS <header>...
# )
#
@@ -101,11 +102,13 @@ endfunction()
# they're relative to the directory of the calling file.
# `FORCE`
# Always generate sources and error if it's not possible.
# `SKIP`
# Never try to generate sources.
# `HEADERS`
# A list of header files for which implmenetations will be generated.
function(generate_json_impls)
cmake_parse_arguments(PARSE_ARGV 0 arg
"" "OUTPUT_SOURCES;BASE_DIRECTORY;FORCE" "HEADERS"
"" "OUTPUT_SOURCES;BASE_DIRECTORY;FORCE;SKIP" "HEADERS"
)
_validate_all_args_are_parsed(arg HEADERS)
if(NOT DEFINED arg_BASE_DIRECTORY)
@@ -114,10 +117,6 @@ function(generate_json_impls)
cmake_path(SET _gen_script NORMALIZE "${_eventsub_lib_root}/ast/generate.py")
if(arg_FORCE AND NOT Python3_EXECUTABLE)
message(FATAL_ERROR "Missing python3")
endif()
# get includes
get_target_property(_qt_inc_dirs Qt${MAJOR_QT_VERSION}::Core INCLUDE_DIRECTORIES)
get_target_property(_qt_iinc_dirs Qt${MAJOR_QT_VERSION}::Core INTERFACE_INCLUDE_DIRECTORIES)
@@ -128,32 +127,41 @@ function(generate_json_impls)
list(APPEND _inc_dirs ${OPENSSL_INCLUDE_DIR})
list(JOIN _inc_dirs ";" _inc_dir)
# setup venv (<build>/lib/twitch-eventsub-ws/eventsub-venv)
if(Python3_EXECUTABLE)
_setup_and_check_venv(
INCLUDES "${_inc_dirs}"
OUT_PYTHON_EXE _python3_path
OUT_CHECK _check_output
)
if(NOT arg_SKIP)
if(arg_FORCE AND NOT Python3_EXECUTABLE)
message(FATAL_ERROR "Missing python3")
endif()
if(NOT _check_output AND _python3_path)
set(_generation_supported On)
# setup venv (<build>/lib/twitch-eventsub-ws/eventsub-venv)
if(Python3_EXECUTABLE)
_setup_and_check_venv(
INCLUDES "${_inc_dirs}"
OUT_PYTHON_EXE _python3_path
OUT_CHECK _check_output
)
if(NOT _check_output AND _python3_path)
set(_generation_supported On)
else()
set(_generation_supported Off)
if (arg_FORCE)
message(FATAL_ERROR "Generation of JSON implementation not supported, because the parser can't parse a simple TU:\n${_check_output}")
endif()
endif()
else()
set(_generation_supported Off)
if (arg_FORCE)
message(FATAL_ERROR "Generation of JSON implementation not supported, because the parser can't parse a simple TU:\n${_check_output}")
endif()
endif()
if(_generation_supported)
message(STATUS "Generation of JSON implementation is supported")
else()
message(STATUS "Generation of JSON implementation is not supported (use FORCE_JSON_GENERATION=On to get more information)")
endif()
else()
message(STATUS "Generation of JSON implementation is skipped because the SKIP_JSON_GENERATION option is On")
set(_generation_supported Off)
endif()
if(_generation_supported)
message(STATUS "Generation of JSON implementation is supported")
else()
message(STATUS "Generation of JSON implementation is not supported (use FORCE_JSON_GENERATION=On to get more information)")
endif()
# get all dependencies
file(GLOB _gen_deps "${_eventsub_lib_root}/ast/lib/*.py")
file(GLOB _ast_templates "${_eventsub_lib_root}/ast/lib/templates/*.tmpl")
@@ -2,6 +2,7 @@ generate_json_impls(
OUTPUT_SOURCES eventsub_generated_sources
BASE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/.."
FORCE ${FORCE_JSON_GENERATION}
SKIP ${SKIP_JSON_GENERATION}
HEADERS
include/twitch-eventsub-ws/messages/metadata.hpp