Commit 509abfc7 authored by Chuck Lever's avatar Chuck Lever

xdrgen: Prevent reordering of encoder and decoder functions

I noticed that "xdrgen source" reorders the procedure encoder and
decoder functions every time it is run. I would prefer that the
generated code be more deterministic: it enables a reader to better
see exactly what has changed between runs of the tool.

The problem is that Python sets are not ordered. I use a Python set
to ensure that, when multiple procedures use a particular argument or
result type, the encoder/decoder for that type is emitted only once.

Sets aren't ordered, but I can use Python dictionaries for this
purpose to ensure the procedure functions are always emitted in the
same order if the .x file does not change.
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent fed8a17c
......@@ -34,20 +34,20 @@ def emit_version_declarations(
environment: Environment, program: str, version: _RpcVersion
) -> None:
"""Emit declarations for each RPC version's procedures"""
arguments = set()
arguments = dict.fromkeys([])
for procedure in version.procedures:
if procedure.name not in excluded_apis:
arguments.add(procedure.argument.type_name)
arguments[procedure.argument.type_name] = None
if len(arguments) > 0:
print("")
template = environment.get_template("declaration/argument.j2")
for argument in arguments:
print(template.render(program=program, argument=argument))
results = set()
results = dict.fromkeys([])
for procedure in version.procedures:
if procedure.name not in excluded_apis:
results.add(procedure.result.type_name)
results[procedure.result.type_name] = None
if len(results) > 0:
print("")
template = environment.get_template("declaration/result.j2")
......@@ -59,10 +59,10 @@ def emit_version_argument_decoders(
environment: Environment, program: str, version: _RpcVersion
) -> None:
"""Emit server argument decoders for each RPC version's procedures"""
arguments = set()
arguments = dict.fromkeys([])
for procedure in version.procedures:
if procedure.name not in excluded_apis:
arguments.add(procedure.argument.type_name)
arguments[procedure.argument.type_name] = None
template = environment.get_template("decoder/argument.j2")
for argument in arguments:
......@@ -73,10 +73,10 @@ def emit_version_result_decoders(
environment: Environment, program: str, version: _RpcVersion
) -> None:
"""Emit client result decoders for each RPC version's procedures"""
results = set()
results = dict.fromkeys([])
for procedure in version.procedures:
if procedure.name not in excluded_apis:
results.add(procedure.result.type_name)
results[procedure.result.type_name] = None
template = environment.get_template("decoder/result.j2")
for result in results:
......@@ -87,10 +87,10 @@ def emit_version_argument_encoders(
environment: Environment, program: str, version: _RpcVersion
) -> None:
"""Emit client argument encoders for each RPC version's procedures"""
arguments = set()
arguments = dict.fromkeys([])
for procedure in version.procedures:
if procedure.name not in excluded_apis:
arguments.add(procedure.argument.type_name)
arguments[procedure.argument.type_name] = None
template = environment.get_template("encoder/argument.j2")
for argument in arguments:
......@@ -101,10 +101,10 @@ def emit_version_result_encoders(
environment: Environment, program: str, version: _RpcVersion
) -> None:
"""Emit server result encoders for each RPC version's procedures"""
results = set()
results = dict.fromkeys([])
for procedure in version.procedures:
if procedure.name not in excluded_apis:
results.add(procedure.result.type_name)
results[procedure.result.type_name] = None
template = environment.get_template("encoder/result.j2")
for result in results:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment