From 634842d2f56e8997402a24affc1269041d55e31e Mon Sep 17 00:00:00 2001 From: pajlada Date: Thu, 6 Feb 2025 09:21:21 +0100 Subject: [PATCH] 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 --- .cirrus.yml | 1 + BUILDING_ON_FREEBSD.md | 2 +- CHANGELOG.md | 2 +- lib/twitch-eventsub-ws/CMakeLists.txt | 1 + .../cmake/GenerateJson.cmake | 54 +++++++++++-------- lib/twitch-eventsub-ws/src/CMakeLists.txt | 1 + 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 1183ff71..1cec7bc4 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -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) diff --git a/BUILDING_ON_FREEBSD.md b/BUILDING_ON_FREEBSD.md index a681dcb9..e7111390 100644 --- a/BUILDING_ON_FREEBSD.md +++ b/BUILDING_ON_FREEBSD.md @@ -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 .. ``` diff --git a/CHANGELOG.md b/CHANGELOG.md index cd8d2131..54df4bd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/twitch-eventsub-ws/CMakeLists.txt b/lib/twitch-eventsub-ws/CMakeLists.txt index b82d3dd2..53f36565 100644 --- a/lib/twitch-eventsub-ws/CMakeLists.txt +++ b/lib/twitch-eventsub-ws/CMakeLists.txt @@ -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") diff --git a/lib/twitch-eventsub-ws/cmake/GenerateJson.cmake b/lib/twitch-eventsub-ws/cmake/GenerateJson.cmake index 38880447..80587ee4 100644 --- a/lib/twitch-eventsub-ws/cmake/GenerateJson.cmake +++ b/lib/twitch-eventsub-ws/cmake/GenerateJson.cmake @@ -91,6 +91,7 @@ endfunction() # [OUTPUT_SOURCES ] # [BASE_DIRECTORY ] # [FORCE ] +# [SKIP ] # HEADERS
... # ) # @@ -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 (/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 (/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") diff --git a/lib/twitch-eventsub-ws/src/CMakeLists.txt b/lib/twitch-eventsub-ws/src/CMakeLists.txt index 6dc0e81f..89899c0c 100644 --- a/lib/twitch-eventsub-ws/src/CMakeLists.txt +++ b/lib/twitch-eventsub-ws/src/CMakeLists.txt @@ -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