From 7cf813d06d8ad33ce0b9c6e1409e18090533758c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Wed, 27 Nov 2024 14:33:29 +0000 Subject: [PATCH] Use OrderedDict for reproducible codegen Python set's do not have a deterministic iteration order (unlike dicts), therefore replace usage of set with OrderedDict's to make codegen reproducible. Signed-off-by: Harry Sarson --- rosidl_generator_c/resource/action__type_support.h.em | 2 +- rosidl_generator_c/resource/full__description.c.em | 5 +++-- rosidl_generator_c/resource/idl__type_support.c.em | 5 +++-- rosidl_generator_c/resource/msg__functions.c.em | 2 +- rosidl_generator_c/resource/msg__struct.h.em | 2 +- rosidl_generator_c/resource/msg__type_support.h.em | 2 +- rosidl_generator_c/resource/srv__type_support.h.em | 2 +- 7 files changed, 11 insertions(+), 9 deletions(-) diff --git a/rosidl_generator_c/resource/action__type_support.h.em b/rosidl_generator_c/resource/action__type_support.h.em index a1747c6c0..6457de191 100644 --- a/rosidl_generator_c/resource/action__type_support.h.em +++ b/rosidl_generator_c/resource/action__type_support.h.em @@ -4,7 +4,7 @@ // already included above // @ @[else]@ -@{include_directives.add(header_file)}@ +@{include_directives[header_file] = None}@ @[end if]@ #include "@(header_file)" diff --git a/rosidl_generator_c/resource/full__description.c.em b/rosidl_generator_c/resource/full__description.c.em index c146e1643..43add36d6 100644 --- a/rosidl_generator_c/resource/full__description.c.em +++ b/rosidl_generator_c/resource/full__description.c.em @@ -1,5 +1,6 @@ @# Included from rosidl_generator_c/resource/idl__description.c.em @{ +from collections import OrderedDict from rosidl_generator_c import escape_string from rosidl_generator_c import idl_structure_type_to_c_include_prefix from rosidl_generator_c import type_hash_to_c_definition @@ -31,7 +32,7 @@ def utf8_encode(value_string): return escape_string(repr(value_string.encode('utf-8'))[2:-1]) implicit_type_names = set(td['type_description']['type_name'] for td, _ in implicit_type_descriptions) -includes = set() +includes = OrderedDict() toplevel_msg, _ = toplevel_type_description for referenced_td in toplevel_msg['referenced_type_descriptions']: @@ -40,7 +41,7 @@ for referenced_td in toplevel_msg['referenced_type_descriptions']: names = referenced_td['type_name'].split('/') _type = NamespacedType(names[:-1], names[-1]) include_prefix = idl_structure_type_to_c_include_prefix(_type, 'detail') - includes.add(include_prefix + '__functions.h') + includes[include_prefix + '__functions.h'] = None full_type_descriptions = [toplevel_type_description] + implicit_type_descriptions full_type_names = [t['type_description']['type_name'] for t, _ in full_type_descriptions] diff --git a/rosidl_generator_c/resource/idl__type_support.c.em b/rosidl_generator_c/resource/idl__type_support.c.em index 77128406b..bf23ea0be 100644 --- a/rosidl_generator_c/resource/idl__type_support.c.em +++ b/rosidl_generator_c/resource/idl__type_support.c.em @@ -11,16 +11,17 @@ @# - content (IdlContent, list of elements, e.g. Messages or Services) @####################################################################### @{ +from collections import OrderedDict from rosidl_pycommon import convert_camel_case_to_lower_case_underscore include_parts = [package_name] + list(interface_path.parents[0].parts) + [ 'detail', convert_camel_case_to_lower_case_underscore(interface_path.stem)] include_base = '/'.join(include_parts) -include_directives = { +include_directives = OrderedDict.fromkeys([ 'rosidl_typesupport_interface/macros.h', include_base + '__type_support.h', include_base + '__struct.h', - include_base + '__functions.h'} + include_base + '__functions.h']) }@ #include diff --git a/rosidl_generator_c/resource/msg__functions.c.em b/rosidl_generator_c/resource/msg__functions.c.em index f7fe8d7f1..a4d2ad621 100644 --- a/rosidl_generator_c/resource/msg__functions.c.em +++ b/rosidl_generator_c/resource/msg__functions.c.em @@ -63,7 +63,7 @@ for member in message.structure.members: // already included above // @ @[ else]@ -@{include_directives.add(header_file)}@ +@{include_directives[header_file] = None}@ @[ end if]@ #include "@(header_file)" @[ end for]@ diff --git a/rosidl_generator_c/resource/msg__struct.h.em b/rosidl_generator_c/resource/msg__struct.h.em index 23414ed45..ae2ddd52a 100644 --- a/rosidl_generator_c/resource/msg__struct.h.em +++ b/rosidl_generator_c/resource/msg__struct.h.em @@ -109,7 +109,7 @@ static const char * const @(idl_structure_type_to_c_typename(message.structure.n // already included above // @ @[ else]@ -@{include_directives.add(header_file)}@ +@{include_directives[header_file] = None}@ @[ end if]@ #include "@(header_file)" @[ end for]@ diff --git a/rosidl_generator_c/resource/msg__type_support.h.em b/rosidl_generator_c/resource/msg__type_support.h.em index 785c4f55b..03928c2b1 100644 --- a/rosidl_generator_c/resource/msg__type_support.h.em +++ b/rosidl_generator_c/resource/msg__type_support.h.em @@ -4,7 +4,7 @@ // already included above // @ @[else]@ -@{include_directives.add(header_file)}@ +@{include_directives[header_file] = None}@ @[end if]@ #include "@(header_file)" diff --git a/rosidl_generator_c/resource/srv__type_support.h.em b/rosidl_generator_c/resource/srv__type_support.h.em index 5cfbd883f..f4c2123ae 100644 --- a/rosidl_generator_c/resource/srv__type_support.h.em +++ b/rosidl_generator_c/resource/srv__type_support.h.em @@ -25,7 +25,7 @@ TEMPLATE( // already included above // @ @[else]@ -@{include_directives.add(header_file)}@ +@{include_directives[header_file] = None}@ @[end if]@ #include "@(header_file)"