Browse Source

tools: add ability to wrap wire messages with ifs

Makes it possible to hide wire messages behind EXPERIMENTAL_FEATURES
flag.
travis-debug
lisa neigut 5 years ago
committed by Rusty Russell
parent
commit
3f1f075421
  1. 6
      tools/gen/header_template
  2. 6
      tools/gen/impl_template
  3. 14
      tools/generate-wire.py
  4. 2
      tools/test/enum.h
  5. 4
      tools/test/test_cases

6
tools/gen/header_template

@ -85,12 +85,18 @@ void fromwire_${subtype.name}(const u8 **cursor, size_t *plen, ${subtype.type_na
% endfor
% endif
% for msg in messages:
% if msg.if_token:
#if ${msg.if_token}
% endif
/* WIRE: ${msg.name.upper()} */
% for c in msg.msg_comments:
/* ${c} */
% endfor
u8 *towire_${msg.name}(const tal_t *ctx${''.join([f.arg_desc_to() for f in msg.fields.values()])});
bool fromwire_${msg.name}(${'const tal_t *ctx, ' if msg.needs_context() else ''}const void *p${''.join([f.arg_desc_from() for f in msg.fields.values()])});
% if msg.if_token:
#endif /* ${msg.if_token} */
% endif
% endfor

6
tools/gen/impl_template

@ -210,6 +210,9 @@ ${static}const struct tlv_record_type tlvs_${tlv.name}[] = {
% endfor ## END TLV's
% for msg in messages: ## START Wire Messages
% if msg.if_token:
#if ${msg.if_token}
% endif
/* WIRE: ${msg.name.upper()} */
% for c in msg.msg_comments:
/*${c} */
@ -322,4 +325,7 @@ bool fromwire_${msg.name}(${'const tal_t *ctx, ' if msg.needs_context() else ''}
% endfor
return cursor != NULL;
}
% if msg.if_token:
#endif /* ${msg.if_token} */
% endif
% endfor ## END Wire Messages

14
tools/generate-wire.py

@ -356,6 +356,7 @@ class Message(FieldSet):
self.struct_prefix = struct_prefix
self.enumname = None
self.msg_comments = comments
self.if_token = None
def has_option(self):
return self.option is not None
@ -369,6 +370,9 @@ class Message(FieldSet):
return self.struct_prefix + "_" + self.name
return self.name
def add_if(self, if_token):
self.if_token = if_token
class Tlv(object):
def __init__(self, name):
@ -518,6 +522,7 @@ def main(options, args=None, output=sys.stdout, lines=None):
genline = next_line(args, lines)
comment_set = []
token_name = None
# Create a new 'master' that serves as the coordinator for the file generation
master = Master()
@ -530,8 +535,12 @@ def main(options, args=None, output=sys.stdout, lines=None):
if not bool(line):
master.add_comments(comment_set)
comment_set = []
token_name = None
continue
if len(tokens) > 2:
token_name = tokens[1]
if token_type == 'subtype':
subtype, _, _ = master.add_type(tokens[1])
@ -632,6 +641,11 @@ def main(options, args=None, output=sys.stdout, lines=None):
comment_set = []
elif token_type.startswith('#include'):
master.add_include(token_type)
elif token_type.startswith('#if'):
msg = master.find_message(token_name)
if (msg):
if_token = token_type[token_type.index(' ') + 1:]
msg.add_if(if_token)
elif token_type.startswith('#'):
comment_set.append(token_type[1:])
else:

2
tools/test/enum.h

@ -3,6 +3,8 @@
#include <ccan/short_types/short_types.h>
#include <stdlib.h>
#define TEST_IFDEF 0
enum test_enum {
TEST_ONE,
TEST_TWO,

4
tools/test/test_cases

@ -47,6 +47,10 @@ msgdata,test_msg,test_sbt_arrays,subtype_arrays,
msgdata,test_msg,extension_1,test_features,,option_short_id
msgdata,test_msg,extension_2,test_short_id,,option_one,option_two
msgtype,test_ifdef,100
#ifdef TEST_IFDEF
msgdata,test_ifdef,is_def,u32,
msgtype,test_tlv1,2
msgdata,test_tlv1,test_struct,test_short_id,
msgdata,test_tlv1,tlv,test_n1,

Loading…
Cancel
Save