Skip to content

Commit

Permalink
bolt-gen: add 'top-line' file comments to output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
niftynei authored and rustyrussell committed Jul 24, 2019
1 parent fe3f4f5 commit ade594e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 6 additions & 4 deletions tools/gen/impl_template
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#include <ccan/mem/mem.h>
#include <ccan/tal/str/str.h>
#include <stdio.h>

% 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)];
Expand All @@ -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})
Expand All @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions tools/generate-bolts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -362,6 +364,7 @@ def write(self, options, output):
'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
Expand All @@ -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])

Expand Down

0 comments on commit ade594e

Please sign in to comment.