Skip to content

Commit

Permalink
refactor(eventsub): Allow for skipping generation of json implementat…
Browse files Browse the repository at this point in the history
…ions

This can be done using the `SKIP_JSON_GENERATION` flag (off by default)
  • Loading branch information
pajlada committed Feb 6, 2025
1 parent 449aefc commit 36a8f31
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/twitch-eventsub-ws/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
54 changes: 31 additions & 23 deletions lib/twitch-eventsub-ws/cmake/GenerateJson.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ endfunction()
# [OUTPUT_SOURCES <out-var>]
# [BASE_DIRECTORY <path>]
# [FORCE <force>]
# [SKIP <skip>]
# HEADERS <header>...
# )
#
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -128,30 +127,39 @@ 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()
else()
set(_generation_supported Off)
endif()

if(_generation_supported)
message(STATUS "Generation of JSON implementation is supported")
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 not supported (use FORCE_JSON_GENERATION=On to get more information)")
message(STATUS "Generation of JSON implementation is skipped because the SKIP_JSON_GENERATION option is On")
set(_generation_supported Off)
endif()

# get all dependencies
Expand Down
1 change: 1 addition & 0 deletions lib/twitch-eventsub-ws/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 36a8f31

Please sign in to comment.