diff --git a/.github/workflows/check-formatting.yml b/.github/workflows/check-formatting.yml index 223023e3..5556482b 100644 --- a/.github/workflows/check-formatting.yml +++ b/.github/workflows/check-formatting.yml @@ -28,7 +28,7 @@ jobs: - name: Check formatting uses: DoozyX/clang-format-lint-action@v0.20 with: - source: "./src ./tests/src ./benchmarks/src ./mocks/include" + source: "./src ./tests/src ./benchmarks/src ./mocks/include ./lib/twitch-eventsub-ws/include ./lib/twitch-eventsub-ws/src" extensions: "hpp,cpp" clangFormatVersion: 19 diff --git a/lib/twitch-eventsub-ws/ast/generate.py b/lib/twitch-eventsub-ws/ast/generate.py index 680d407a..0342d36f 100755 --- a/lib/twitch-eventsub-ws/ast/generate.py +++ b/lib/twitch-eventsub-ws/ast/generate.py @@ -75,7 +75,7 @@ def main(): log.debug(f"{header_path}: definition={def_path}, implementation={source_path}") - (definition, implementation) = generate(header_path, args.includes) + (definition, implementation) = generate(header_path, source_path, args.includes) # ensure directories are created Path(def_path).parent.mkdir(parents=True, exist_ok=True) diff --git a/lib/twitch-eventsub-ws/ast/lib/format.py b/lib/twitch-eventsub-ws/ast/lib/format.py index 0aba499e..2913bc0b 100644 --- a/lib/twitch-eventsub-ws/ast/lib/format.py +++ b/lib/twitch-eventsub-ws/ast/lib/format.py @@ -4,8 +4,10 @@ import subprocess log = logging.getLogger(__name__) -def format_code(code: str) -> str: - proc = subprocess.Popen(["clang-format", "-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE) +def format_code(filename: str, code: str) -> str: + proc = subprocess.Popen( + ["clang-format", "--assume-filename", filename, "-"], stdin=subprocess.PIPE, stdout=subprocess.PIPE + ) outs, errs = proc.communicate(input=code.encode(), timeout=2) if errs is not None: log.warning(f"Error formatting code: {errs.decode()}") diff --git a/lib/twitch-eventsub-ws/ast/lib/generate.py b/lib/twitch-eventsub-ws/ast/lib/generate.py index 276c8e1e..920f087f 100644 --- a/lib/twitch-eventsub-ws/ast/lib/generate.py +++ b/lib/twitch-eventsub-ws/ast/lib/generate.py @@ -44,14 +44,16 @@ def _get_relative_header_path(header_path: str) -> str: return Path(header_path).relative_to(root_path).as_posix() -def generate(header_path: str, additional_includes: list[str] = []) -> Tuple[str, str]: +def generate(header_path: str, source_path: str, additional_includes: list[str] = []) -> Tuple[str, str]: structs = build_structs(header_path, additional_includes) rel_header_path = _get_relative_header_path(header_path) log.debug("Generate & format definitions") - definitions = format_code("\n\n".join([struct.try_value_to_definition(env) for struct in structs])) + # Technically the definitions we save will be saved in an .inc file, but for the purpose of formatting the code we can assume it's the real header file + definitions = format_code(header_path, "\n\n".join([struct.try_value_to_definition(env) for struct in structs])) + log.debug("Generate & format implementations") - implementations = format_code(_generate_implementation(rel_header_path, structs)) + implementations = format_code(source_path, _generate_implementation(rel_header_path, structs)) return (definitions, implementations) diff --git a/lib/twitch-eventsub-ws/src/generated/messages/metadata.cpp b/lib/twitch-eventsub-ws/src/generated/messages/metadata.cpp index d9aa2bf8..541550b0 100644 --- a/lib/twitch-eventsub-ws/src/generated/messages/metadata.cpp +++ b/lib/twitch-eventsub-ws/src/generated/messages/metadata.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/messages/metadata.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/messages/metadata.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/automod-message-hold-v2.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/automod-message-hold-v2.cpp index 3eb4decc..e6d5b9e2 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/automod-message-hold-v2.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/automod-message-hold-v2.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/automod-message-hold-v2.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/automod-message-hold-v2.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/automod-message-update-v2.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/automod-message-update-v2.cpp index 5b5ae709..cc1fce63 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/automod-message-update-v2.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/automod-message-update-v2.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/automod-message-update-v2.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/automod-message-update-v2.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/automod-message.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/automod-message.cpp index fa3d2b18..bf566042 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/automod-message.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/automod-message.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/automod-message.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/automod-message.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/channel-ban-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/channel-ban-v1.cpp index 9e8edb9a..9e1b6778 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/channel-ban-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/channel-ban-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/channel-ban-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/channel-ban-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-message-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-message-v1.cpp index 15a89492..4eacb9d3 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-message-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-message-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/channel-chat-message-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/channel-chat-message-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-notification-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-notification-v1.cpp index 2d8e3a64..7ecd14a1 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-notification-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-notification-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/channel-chat-notification-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/channel-chat-notification-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-user-message-hold-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-user-message-hold-v1.cpp index 57e184a7..168e5204 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-user-message-hold-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-user-message-hold-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/channel-chat-user-message-hold-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/channel-chat-user-message-hold-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-user-message-update-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-user-message-update-v1.cpp index 68df51a5..c30da8e3 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-user-message-update-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/channel-chat-user-message-update-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/channel-chat-user-message-update-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/channel-chat-user-message-update-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/channel-moderate-v2.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/channel-moderate-v2.cpp index f405dcf8..431727f9 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/channel-moderate-v2.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/channel-moderate-v2.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/channel-moderate-v2.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/channel-moderate-v2.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/channel-suspicious-user-message-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/channel-suspicious-user-message-v1.cpp index 8a37a0c2..c9686d79 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/channel-suspicious-user-message-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/channel-suspicious-user-message-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/channel-suspicious-user-message-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/channel-suspicious-user-message-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/channel-suspicious-user-update-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/channel-suspicious-user-update-v1.cpp index f78cf32f..6d16cbba 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/channel-suspicious-user-update-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/channel-suspicious-user-update-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/channel-suspicious-user-update-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/channel-suspicious-user-update-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/channel-update-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/channel-update-v1.cpp index 0b699ffe..0f16f3a0 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/channel-update-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/channel-update-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/channel-update-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/channel-update-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/session-welcome.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/session-welcome.cpp index dd9cd84c..52f63e6f 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/session-welcome.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/session-welcome.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/session-welcome.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/session-welcome.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/stream-offline-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/stream-offline-v1.cpp index c3e095e0..c8759ced 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/stream-offline-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/stream-offline-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/stream-offline-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/stream-offline-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/stream-online-v1.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/stream-online-v1.cpp index 6be3b350..2a0745fd 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/stream-online-v1.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/stream-online-v1.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/stream-online-v1.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/stream-online-v1.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/structured-message.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/structured-message.cpp index 6e202a05..7d080faa 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/structured-message.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/structured-message.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/structured-message.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/structured-message.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/subscription.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/subscription.cpp index 293c0b72..7cc1c5fa 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/subscription.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/subscription.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/subscription.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/subscription.hpp" #include diff --git a/lib/twitch-eventsub-ws/src/generated/payloads/suspicious-users.cpp b/lib/twitch-eventsub-ws/src/generated/payloads/suspicious-users.cpp index 990fe064..cff0b46e 100644 --- a/lib/twitch-eventsub-ws/src/generated/payloads/suspicious-users.cpp +++ b/lib/twitch-eventsub-ws/src/generated/payloads/suspicious-users.cpp @@ -1,8 +1,9 @@ // WARNING: This file is automatically generated. Any changes will be lost. +#include "twitch-eventsub-ws/payloads/suspicious-users.hpp" + #include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep #include "twitch-eventsub-ws/detail/errors.hpp" #include "twitch-eventsub-ws/detail/variant.hpp" // IWYU pragma: keep -#include "twitch-eventsub-ws/payloads/suspicious-users.hpp" #include diff --git a/scripts/clang-format-all.sh b/scripts/clang-format-all.sh index aaf751d6..267b12f4 100755 --- a/scripts/clang-format-all.sh +++ b/scripts/clang-format-all.sh @@ -17,6 +17,8 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then -regex '\./src/.*\.\(hpp\|cpp\)' -o \ -regex '\./tests/src/.*\.\(hpp\|cpp\)' -o \ -regex '\./benchmarks/src/.*\.\(hpp\|cpp\)' -o \ + -regex '\./lib/twitch-eventsub-ws/include/.*\.\(hpp\|cpp\)' -o \ + -regex '\./lib/twitch-eventsub-ws/src/.*\.\(hpp\|cpp\)' -o \ -regex '\./mocks/include/.*\.\(hpp\|cpp\)' \ \) | parallel --verbose --jobs "$NUM_FORMAT_JOBS" clang-format -i else @@ -24,6 +26,8 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then -regex '\./src/.*\.\(hpp\|cpp\)' -o \ -regex '\./tests/src/.*\.\(hpp\|cpp\)' -o \ -regex '\./benchmarks/src/.*\.\(hpp\|cpp\)' -o \ + -regex '\./lib/twitch-eventsub-ws/include/.*\.\(hpp\|cpp\)' -o \ + -regex '\./lib/twitch-eventsub-ws/src/.*\.\(hpp\|cpp\)' -o \ -regex '\./mocks/include/.*\.\(hpp\|cpp\)' \ \) -exec clang-format -i {} \; fi