-
-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(eventsub): generate entire files
- Loading branch information
Showing
51 changed files
with
859 additions
and
865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from lib import init_clang_cindex | ||
|
||
init_clang_cindex() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
from .generate import generate | ||
from .helpers import get_clang_builtin_include_dirs, init_clang_cindex, temporary_file | ||
from .logging import init_logging | ||
from .replace import definition_markers, implementation_markers, replace_in_file | ||
|
||
__all__ = [ | ||
"generate", | ||
"get_clang_builtin_include_dirs", | ||
"init_clang_cindex", | ||
"temporary_file", | ||
"init_logging", | ||
"definition_markers", | ||
"implementation_markers", | ||
"replace_in_file", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,57 @@ | ||
from typing import Tuple | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from .struct import Struct | ||
from .enum import Enum | ||
from .build import build_structs | ||
from .format import format_code | ||
from .helpers import init_clang_cindex, temporary_file | ||
from .jinja_env import env | ||
from .logging import init_logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def _generate_implementation(header_path: str, items: list[Struct | Enum]) -> str: | ||
current_ns = "" | ||
doc = f""" | ||
// WARNING: This file is automatically generated. Any changes will be lost. | ||
#include "{header_path}" | ||
#include "twitch-eventsub-ws/chrono.hpp" // IWYU pragma: keep | ||
#include "twitch-eventsub-ws/errors.hpp" | ||
#include <boost/json.hpp> | ||
""" | ||
|
||
for item in items: | ||
next_ns = "::".join(item.namespace) | ||
if next_ns != current_ns: | ||
if current_ns: | ||
doc += "} // namespace " + current_ns + "\n" | ||
if next_ns: | ||
doc += "namespace " + next_ns + "{\n\n" | ||
current_ns = next_ns | ||
doc += item.try_value_to_implementation(env) + "\n\n" | ||
|
||
if current_ns: | ||
doc += "\n} // namespace " + current_ns + "\n\n" | ||
|
||
return doc | ||
|
||
|
||
def _get_relative_header_path(header_path: str) -> str: | ||
root_path = Path(__file__).parent.parent.parent / "include" | ||
return Path(header_path).relative_to(root_path).as_posix() | ||
|
||
|
||
def generate(header_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])) | ||
log.debug("Generate & format implementations") | ||
implementations = format_code("\n\n".join([struct.try_value_to_implementation(env) for struct in structs])) | ||
implementations = format_code(_generate_implementation(rel_header_path, structs)) | ||
|
||
return (definitions, implementations) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.