Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JsonGen] Prevent redundant enum generation on up-to-date interfaces #31

Merged
merged 1 commit into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions JsonGenerator/source/class_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@
import trackers
from json_loader import *

def ProcessEnums(action=None):
count = 0

for obj in trackers.enum_tracker.objects:
if not obj.is_duplicate and not obj.included_from and ("@register" not in obj.schema or obj.schema["@register"]):
obj.schema["@register"] = False
count += 1
if action:
action(obj)

return count

def EmitEnumRegs(root, emit, header_file, if_file):
def _EmitEnumRegistration(root, enum):
def _EmitEnumRegistration(enum):
name = enum.original_type if enum.original_type else (Scoped(root, enum) + enum.cpp_class)

emit.Line()
emit.Line("ENUM_CONVERSION_BEGIN(%s)" % name)
emit.Indent()

Expand All @@ -48,21 +61,14 @@ def _EmitEnumRegistration(root, enum):
emit.Line("#include \"%s_%s.h\"" % (config.DATA_NAMESPACE, header_file))
emit.Line()
emit.Line("namespace %s {" % config.FRAMEWORK_NAMESPACE)
count = 0

for obj in trackers.enum_tracker.objects:
if not obj.is_duplicate and not obj.included_from and ("@register" not in obj.schema or obj.schema["@register"]):
emit.Line()
_EmitEnumRegistration(root, obj)
obj.schema["@register"] = False
count += 1
count = ProcessEnums(_EmitEnumRegistration)

emit.Line()
emit.Line("}")

return count


def EmitObjects(log, root, emit, if_file, additional_includes, emitCommon = False):
global emittedItems
emittedItems = 0
Expand Down
1 change: 1 addition & 0 deletions JsonGenerator/source/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def _ParseJsonRpcSchema(schema):
# Generate enum registrations...
if not config.FORCE and (os.path.exists(enum_file) and (os.path.getmtime(source_file) < os.path.getmtime(enum_file))):
log.Success("skipping file %s, up-to-date" % os.path.basename(enum_file))
class_emitter.ProcessEnums()
else:
enum_emitted = 0

Expand Down
Loading