From ade594e94114e7ca9c1f37c82cc7fa0f43e474ad Mon Sep 17 00:00:00 2001 From: lisa neigut Date: Fri, 19 Jul 2019 11:33:03 -0500 Subject: [PATCH] bolt-gen: add 'top-line' file comments to output if there are any comments that aren't "attached" to a message, print them at the top of the generated file. we need this for the fancy auto-gen'd dependencies in the tool-wiregen tests. --- tools/gen/impl_template | 10 ++++++---- tools/generate-bolts.py | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/gen/impl_template b/tools/gen/impl_template index 2f2d3f4a2..87c7eee47 100644 --- a/tools/gen/impl_template +++ b/tools/gen/impl_template @@ -6,8 +6,11 @@ #include #include #include - +% for comment in top_comments: +/*${comment} */ +% endfor % for enum_set in enum_sets: + const char *${enum_set['name']}_name(int e) { static char invalidbuf[sizeof("INVALID ") + STR_MAX_CHARS(e)]; @@ -29,7 +32,7 @@ const char *${enum_set['name']}_name(int e) % for subtype in subtypes: /* SUBTYPE: ${subtype.name.upper()} */ % for c in subtype.type_comments: -/* ${c} */ +/*${c} */ % endfor <% static = '' if options.expose_subtypes else 'static ' %> ${static}void towire_${subtype.name}(u8 **p, const struct ${subtype.name} *${subtype.name}) @@ -38,10 +41,9 @@ ${static}void towire_${subtype.name}(u8 **p, const struct ${subtype.name} *${sub ${f.type_obj.type_name()} ${f.name} = tal_count(${subtype.name}->${f.len_field_of}); % endfor -## FIXME: abstract this out? (semi-shared with towire_msg, minus the optional bits) % for f in subtype.fields.values(): % for c in f.field_comments: - /* ${c} */ + /*${c} */ % endfor <% fieldname = '{}->{}'.format(subtype.name,f.name) diff --git a/tools/generate-bolts.py b/tools/generate-bolts.py index 5f3e05ecd..4b9d9676b 100755 --- a/tools/generate-bolts.py +++ b/tools/generate-bolts.py @@ -33,9 +33,7 @@ def next_line(args, lines): lines = fileinput.input(args) for i, line in enumerate(lines): - if not bool(line.strip()): - continue - yield i, line.strip() + yield i + 1, line.strip() # Class definitions, to keep things classy @@ -285,6 +283,10 @@ class Master(object): messages = {} extension_msgs = {} inclusions = [] + top_comments = [] + + def add_comments(self, comments): + self.top_comments += comments def add_include(self, inclusion): self.inclusions.append(inclusion) @@ -362,6 +364,7 @@ class Master(object): 'set': tlv.messages.values(), }) stuff = {} + stuff['top_comments'] = self.top_comments stuff['options'] = options stuff['idem'] = re.sub(r'[^A-Z]+', '_', options.header_filename.upper()) stuff['header_filename'] = options.header_filename @@ -388,6 +391,12 @@ def main(options, args=None, output=sys.stdout, lines=None): ln, line = next(genline) tokens = line.split(',') token_type = tokens[0] + + if not bool(line): + master.add_comments(comment_set) + comment_set = [] + continue + if token_type == 'subtype': subtype, _ = master.add_type(tokens[1])