Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ksergey committed Oct 25, 2024
1 parent 002809c commit 800fbc9
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 100 deletions.
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ add_custom_target(python_venv DEPENDS ${pythonEnv}/pyvenv.cfg)

function(sbe_make_codec TARGET)
set(options)
set(oneValueArgs SCHEMA OUTPUT GENERATOR INCLUDE_BASE)
set(oneValueArgs SCHEMA OUTPUT GENERATOR INCLUDE_BASE PACKAGE)
set(multiValueArgs)

cmake_parse_arguments(PARSED "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
Expand All @@ -30,16 +30,21 @@ function(sbe_make_codec TARGET)
set(destDir "${PARSED_OUTPUT}")
endif()

set(extraArgs)
if (PARSED_PACKAGE)
set(extraArgs ${extraArgs} --package="${PARSED_PACKAGE}")
endif()

add_custom_command(
OUTPUT ${destDir}/schema.h
DEPENDS ${PARSED_SCHEMA} python_venv
COMMAND ${CMAKE_COMMAND} -E rm -rf "${PARSED_OUTPUT}"
COMMAND ${pythonExe} -m app --schema="${PARSED_SCHEMA}" --destination="${destDir}" --generator="${PARSED_GENERATOR}"
COMMAND ${pythonExe} -m app --schema="${PARSED_SCHEMA}" --destination="${destDir}" --generator="${PARSED_GENERATOR}" ${extraArgs}
WORKING_DIRECTORY ${cppCodeGenRoot}
COMMENT "generating schema (${PARSED_SCHEMA})"
)

add_library(${TARGET} INTERFACE)
add_library(${TARGET} INTERFACE EXCLUDE_FROM_ALL)
target_compile_features(${TARGET} INTERFACE cxx_std_20)
target_sources(${TARGET} INTERFACE ${destDir}/schema.h)
target_include_directories(${TARGET} INTERFACE "${PARSED_OUTPUT}")
Expand Down
3 changes: 2 additions & 1 deletion app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def main() -> None:
parser.add_argument('--schema', help='path to xml schema', required=True)
parser.add_argument('--destination', help='path to directory where codec will be written', required=True)
parser.add_argument('--generator', help='choose generator (available: cpp, cppng)', default='cpp')
parser.add_argument('--package', help='override schema package property')

args = parser.parse_args()

Expand All @@ -20,7 +21,7 @@ def main() -> None:
Generator = getattr(module, 'Generator')
schema = Parser.from_file(args.schema).get_schema()
generator = Generator(args.destination)
generator.generate(schema)
generator.generate(schema, package=args.package)
except Exception as e:
sys.exit(traceback.format_exc())
sys.exit(f'error: {e}')
Expand Down
4 changes: 2 additions & 2 deletions app/generation/cpp/templates/enum.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}

{%- set enum_class_name = type.name | format_class_name -%}
{%- set underlying_type = type.encoding_type | replace_keyword -%}
{%- set underlying_type = type.encoding_type.name | replace_keyword -%}

class {{ enum_class_name }} final {
private:
Expand All @@ -12,7 +12,7 @@ private:
public:
enum enumerated : {{ underlying_type }} {
{% for valid_value in type.valid_values %}
{% if type.encoding_type == 'char' %}
{% if type.encoding_type.name == 'char' %}
{{ valid_value.name }} = '{{ valid_value.value }}',
{% else %}
{{ valid_value.name }} = {{ valid_value.value }},
Expand Down
4 changes: 2 additions & 2 deletions app/generation/cpp/templates/property.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
{%- set const_value = type.const_value -%}
{%- endif %}
{%- set enum_class_name = type.name | format_class_name -%}
{%- set underlying_type = type.encoding_type | replace_keyword -%}
{%- set underlying_type = type.encoding_type.name | replace_keyword -%}

{%- if entry.presence == 'constant' %}
[[nodiscard]] static constexpr {{ enum_class_name }} {{ method_name | format_method_name_get }}() noexcept {
Expand Down Expand Up @@ -269,7 +269,7 @@
{% set type = entry -%}
{%- endif %}
{%- set set_class_name = entry.name | format_class_name -%}
{%- set underlying_type = type.encoding_type | replace_keyword -%}
{%- set underlying_type = type.encoding_type.name | replace_keyword -%}

[[nodiscard]] {{ set_class_name }} {{ method_name | format_method_name_get }}() const {
return {{ set_class_name }}(*std::bit_cast<{{ underlying_type }} const*>(buffer_ + offset_ + {{ entry.offset }}));
Expand Down
2 changes: 1 addition & 1 deletion app/generation/cpp/templates/set.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block content %}

{%- set set_class_name = type.name | format_class_name -%}
{%- set underlying_type = type.encoding_type | replace_keyword -%}
{%- set underlying_type = type.encoding_type.name | replace_keyword -%}

class {{ set_class_name }} final {
private:
Expand Down
1 change: 0 additions & 1 deletion app/generation/cppng/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def add_filters(self) -> None:
self.env.filters['replace_keyword'] = Generator.filter_replace_keyword
self.env.filters['format_group_name'] = lambda value: value[0].upper() + value[1:] + 'Group'
self.env.filters['format_data_name'] = lambda value: value[0].upper() + value[1:] + 'Data'

self.env.filters['format_encoding_class_name'] = lambda value: value[0].upper() + value[1:] + 'Encoding'

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions app/generation/cppng/templates/enum.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% block include %}
#include <cstdint>
#include <numeric>
#include <optional>
#include <string_view>

#include "typing.h"
Expand Down
Loading

0 comments on commit 800fbc9

Please sign in to comment.