Skip to content

Fix CMake Unity Build variable clashes in the generated C code #852

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

Open
wants to merge 1 commit into
base: jazzy
Choose a base branch
from
Open
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: 12 additions & 12 deletions rosidl_generator_c/resource/full__description.c.em
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type_name = referenced_type_description['type_name']
c_typename = type_name.replace('/', '__')
}@
@[ if type_name not in full_type_names]@
static const rosidl_type_hash_t @(c_typename)__EXPECTED_HASH = @(type_hash_to_c_definition(hash_lookup[type_name]));
static const rosidl_type_hash_t @(unique_prefix)_@(c_typename)__EXPECTED_HASH = @(type_hash_to_c_definition(hash_lookup[type_name]));
@[ end if]@
@[end for]@
#endif
Expand All @@ -78,7 +78,7 @@ static const rosidl_type_hash_t @(c_typename)__EXPECTED_HASH = @(type_hash_to_c_
@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@# Names for all types
@[for itype_description in all_type_descriptions]@
static char @(typename_to_c(itype_description['type_name']))__TYPE_NAME[] = "@(itype_description['type_name'])";
static char @(unique_prefix)_@(typename_to_c(itype_description['type_name']))__TYPE_NAME[] = "@(itype_description['type_name'])";
@[end for]@
@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Expand Down Expand Up @@ -111,7 +111,7 @@ static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = {
rosidl_runtime_c__type_description__FieldType__@(FIELD_TYPE_ID_TO_NAME[field['type']['type_id']]),
@(field['type']['capacity']),
@(field['type']['string_capacity']),
@(static_seq(f"{typename_to_c(field['type']['nested_type_name'])}__TYPE_NAME", field['type']['nested_type_name'])),
@(static_seq(f"{unique_prefix}_{typename_to_c(field['type']['nested_type_name'])}__TYPE_NAME", field['type']['nested_type_name'])),
},
@(static_seq(f"{td_c_typename}__DEFAULT_VALUE__{field['name']}", field['default_value'])),
},
Expand All @@ -124,7 +124,7 @@ static rosidl_runtime_c__type_description__Field @(td_c_typename)__FIELDS[] = {
static rosidl_runtime_c__type_description__IndividualTypeDescription @(td_c_typename)__REFERENCED_TYPE_DESCRIPTIONS[] = {
@[ for ref_td in ref_tds]@
{
@(static_seq(f"{typename_to_c(ref_td['type_name'])}__TYPE_NAME", ref_td['type_name'])),
@(static_seq(f"{unique_prefix}_{typename_to_c(ref_td['type_name'])}__TYPE_NAME", ref_td['type_name'])),
{NULL, 0, 0},
},
@[ end for]@
Expand All @@ -139,7 +139,7 @@ const rosidl_runtime_c__type_description__TypeDescription *
static bool constructed = false;
static const rosidl_runtime_c__type_description__TypeDescription description = {
{
@(static_seq(f'{td_c_typename}__TYPE_NAME', td_typename)),
@(static_seq(f'{unique_prefix}_{td_c_typename}__TYPE_NAME', td_typename)),
@(static_seq(f'{td_c_typename}__FIELDS', msg['type_description']['fields'])),
},
@(static_seq(f'{td_c_typename}__REFERENCED_TYPE_DESCRIPTIONS', ref_tds)),
Expand All @@ -150,7 +150,7 @@ const rosidl_runtime_c__type_description__TypeDescription *
c_typename = typename_to_c(ref_td['type_name'])
}@
@[ if ref_td['type_name'] not in full_type_names]@
assert(0 == memcmp(&@(c_typename)__EXPECTED_HASH, @(c_typename)__@(GET_HASH_FUNC)(NULL), sizeof(rosidl_type_hash_t)));
assert(0 == memcmp(&@(unique_prefix)_@(c_typename)__EXPECTED_HASH, @(c_typename)__@(GET_HASH_FUNC)(NULL), sizeof(rosidl_type_hash_t)));
@[ end if]@
description.referenced_type_descriptions.data[@(idx)].fields = @(c_typename)__@(GET_DESCRIPTION_FUNC)(NULL)->type_description.fields;
@[ end for]@
Expand All @@ -164,16 +164,16 @@ c_typename = typename_to_c(ref_td['type_name'])
@#<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@# Define individual raw sources
@[if raw_source_content]@
static char toplevel_type_raw_source[] =@
static char @(unique_prefix)_toplevel_type_raw_source[] =@
@[ for line in raw_source_content.splitlines()[:-1]]
"@(utf8_encode(line))\n"@
@[ end for]
"@(utf8_encode(raw_source_content.splitlines()[-1]))";
@[end if]@

static char @(toplevel_encoding)_encoding[] = "@(toplevel_encoding)";
static char @(unique_prefix)_@(toplevel_encoding)_encoding[] = "@(toplevel_encoding)";
@[if implicit_type_descriptions]@
static char implicit_encoding[] = "implicit";
static char @(unique_prefix)_implicit_encoding[] = "implicit";
@[end if]@

// Define all individual source functions
Expand All @@ -188,7 +188,7 @@ if td_typename in implicit_type_names:
contents = None
else:
encoding = toplevel_encoding
contents_var = 'toplevel_type_raw_source'
contents_var = unique_prefix + '_toplevel_type_raw_source'
contents = raw_source_content
}@

Expand All @@ -198,8 +198,8 @@ const rosidl_runtime_c__type_description__TypeSource *
{
(void)type_support;
static const rosidl_runtime_c__type_description__TypeSource source = {
@(static_seq(f'{td_c_typename}__TYPE_NAME', td_typename)),
@(static_seq(f'{encoding}_encoding', encoding)),
@(static_seq(f'{unique_prefix}_{td_c_typename}__TYPE_NAME', td_typename)),
@(static_seq(f'{unique_prefix}_{encoding}_encoding', encoding)),
@(static_seq(contents_var, contents)),
};
return &source;
Expand Down
3 changes: 2 additions & 1 deletion rosidl_generator_c/resource/idl__description.c.em
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ TEMPLATE(
toplevel_type_description=toplevel_type_description,
implicit_type_descriptions=implicit_type_descriptions,
hash_lookup=hash_lookup,
type_source_file=type_source_file)
type_source_file=type_source_file,
unique_prefix=interface_path.stem)
}@
@[end if]@
@#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>