From 1c760e07d1be6e164cbed4b76ffb3e7cfa4c3511 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__functions.c.em | 3 ++- rosidl_generator_c/resource/idl__struct.h.em | 3 ++- rosidl_generator_c/resource/idl__type_support.c.em | 5 +++-- rosidl_generator_c/resource/idl__type_support.h.em | 6 ++++-- 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 +- 10 files changed, 19 insertions(+), 13 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__functions.c.em b/rosidl_generator_c/resource/idl__functions.c.em index 8614665e7..a15829f9a 100644 --- a/rosidl_generator_c/resource/idl__functions.c.em +++ b/rosidl_generator_c/resource/idl__functions.c.em @@ -11,12 +11,13 @@ @# - 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_base + '__functions.h', 'rcutils/allocator.h'} +include_directives = OrderedDict.fromkeys([include_base + '__functions.h', 'rcutils/allocator.h']) }@ #include "@(include_base)__functions.h" diff --git a/rosidl_generator_c/resource/idl__struct.h.em b/rosidl_generator_c/resource/idl__struct.h.em index 546507f47..546515c62 100644 --- a/rosidl_generator_c/resource/idl__struct.h.em +++ b/rosidl_generator_c/resource/idl__struct.h.em @@ -14,6 +14,7 @@ @# - content (IdlContent, list of elements, e.g. Messages or Services) @####################################################################### @{ +from collections import OrderedDict from rosidl_generator_c import idl_structure_type_to_c_typename from rosidl_pycommon import convert_camel_case_to_lower_case_underscore include_parts = [package_name] + list(interface_path.parents[0].parts) + [ @@ -21,7 +22,7 @@ include_parts = [package_name] + list(interface_path.parents[0].parts) + [ header_guard_variable = '__'.join([x.upper() for x in include_parts]) + \ '__STRUCT_H_' -include_directives = set() +include_directives = OrderedDict() }@ #ifndef @(header_guard_variable) 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/idl__type_support.h.em b/rosidl_generator_c/resource/idl__type_support.h.em index ea0ade2eb..8c5ed9304 100644 --- a/rosidl_generator_c/resource/idl__type_support.h.em +++ b/rosidl_generator_c/resource/idl__type_support.h.em @@ -1,7 +1,9 @@ // generated from rosidl_generator_c/resource/idl__type_support.h.em // with input from @(package_name):@(interface_path) // generated code does not contain a copyright notice -@{from rosidl_pycommon import convert_camel_case_to_lower_case_underscore} +@{ +from collections import OrderedDict +from rosidl_pycommon import convert_camel_case_to_lower_case_underscore} // IWYU pragma: private, include "@(package_name)/@(interface_path.parent)/@(convert_camel_case_to_lower_case_underscore(interface_path.stem)).h" @ @@ -20,7 +22,7 @@ include_parts = [package_name] + list(interface_path.parents[0].parts) + [ header_guard_variable = '__'.join([x.upper() for x in include_parts]) + \ '__TYPE_SUPPORT_H_' -include_directives = set() +include_directives = OrderedDict() }@ #ifndef @(header_guard_variable) 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)"