mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-01 17:47:30 +01:00
tools: add ability to wrap wire messages with ifs
Makes it possible to hide wire messages behind EXPERIMENTAL_FEATURES flag.
This commit is contained in:
parent
9e29a47cf8
commit
3f1f075421
5 changed files with 32 additions and 0 deletions
|
@ -85,12 +85,18 @@ void fromwire_${subtype.name}(const u8 **cursor, size_t *plen, ${subtype.type_na
|
||||||
% endfor
|
% endfor
|
||||||
% endif
|
% endif
|
||||||
% for msg in messages:
|
% for msg in messages:
|
||||||
|
% if msg.if_token:
|
||||||
|
#if ${msg.if_token}
|
||||||
|
% endif
|
||||||
/* WIRE: ${msg.name.upper()} */
|
/* WIRE: ${msg.name.upper()} */
|
||||||
% for c in msg.msg_comments:
|
% for c in msg.msg_comments:
|
||||||
/* ${c} */
|
/* ${c} */
|
||||||
% endfor
|
% endfor
|
||||||
u8 *towire_${msg.name}(const tal_t *ctx${''.join([f.arg_desc_to() for f in msg.fields.values()])});
|
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()])});
|
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
|
% endfor
|
||||||
|
|
||||||
|
|
|
@ -210,6 +210,9 @@ ${static}const struct tlv_record_type tlvs_${tlv.name}[] = {
|
||||||
% endfor ## END TLV's
|
% endfor ## END TLV's
|
||||||
% for msg in messages: ## START Wire Messages
|
% for msg in messages: ## START Wire Messages
|
||||||
|
|
||||||
|
% if msg.if_token:
|
||||||
|
#if ${msg.if_token}
|
||||||
|
% endif
|
||||||
/* WIRE: ${msg.name.upper()} */
|
/* WIRE: ${msg.name.upper()} */
|
||||||
% for c in msg.msg_comments:
|
% for c in msg.msg_comments:
|
||||||
/*${c} */
|
/*${c} */
|
||||||
|
@ -322,4 +325,7 @@ bool fromwire_${msg.name}(${'const tal_t *ctx, ' if msg.needs_context() else ''}
|
||||||
% endfor
|
% endfor
|
||||||
return cursor != NULL;
|
return cursor != NULL;
|
||||||
}
|
}
|
||||||
|
% if msg.if_token:
|
||||||
|
#endif /* ${msg.if_token} */
|
||||||
|
% endif
|
||||||
% endfor ## END Wire Messages
|
% endfor ## END Wire Messages
|
||||||
|
|
|
@ -356,6 +356,7 @@ class Message(FieldSet):
|
||||||
self.struct_prefix = struct_prefix
|
self.struct_prefix = struct_prefix
|
||||||
self.enumname = None
|
self.enumname = None
|
||||||
self.msg_comments = comments
|
self.msg_comments = comments
|
||||||
|
self.if_token = None
|
||||||
|
|
||||||
def has_option(self):
|
def has_option(self):
|
||||||
return self.option is not None
|
return self.option is not None
|
||||||
|
@ -369,6 +370,9 @@ class Message(FieldSet):
|
||||||
return self.struct_prefix + "_" + self.name
|
return self.struct_prefix + "_" + self.name
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
def add_if(self, if_token):
|
||||||
|
self.if_token = if_token
|
||||||
|
|
||||||
|
|
||||||
class Tlv(object):
|
class Tlv(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
|
@ -518,6 +522,7 @@ def main(options, args=None, output=sys.stdout, lines=None):
|
||||||
genline = next_line(args, lines)
|
genline = next_line(args, lines)
|
||||||
|
|
||||||
comment_set = []
|
comment_set = []
|
||||||
|
token_name = None
|
||||||
|
|
||||||
# Create a new 'master' that serves as the coordinator for the file generation
|
# Create a new 'master' that serves as the coordinator for the file generation
|
||||||
master = Master()
|
master = Master()
|
||||||
|
@ -530,8 +535,12 @@ def main(options, args=None, output=sys.stdout, lines=None):
|
||||||
if not bool(line):
|
if not bool(line):
|
||||||
master.add_comments(comment_set)
|
master.add_comments(comment_set)
|
||||||
comment_set = []
|
comment_set = []
|
||||||
|
token_name = None
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if len(tokens) > 2:
|
||||||
|
token_name = tokens[1]
|
||||||
|
|
||||||
if token_type == 'subtype':
|
if token_type == 'subtype':
|
||||||
subtype, _, _ = master.add_type(tokens[1])
|
subtype, _, _ = master.add_type(tokens[1])
|
||||||
|
|
||||||
|
@ -632,6 +641,11 @@ def main(options, args=None, output=sys.stdout, lines=None):
|
||||||
comment_set = []
|
comment_set = []
|
||||||
elif token_type.startswith('#include'):
|
elif token_type.startswith('#include'):
|
||||||
master.add_include(token_type)
|
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('#'):
|
elif token_type.startswith('#'):
|
||||||
comment_set.append(token_type[1:])
|
comment_set.append(token_type[1:])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <ccan/short_types/short_types.h>
|
#include <ccan/short_types/short_types.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TEST_IFDEF 0
|
||||||
|
|
||||||
enum test_enum {
|
enum test_enum {
|
||||||
TEST_ONE,
|
TEST_ONE,
|
||||||
TEST_TWO,
|
TEST_TWO,
|
||||||
|
|
|
@ -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_1,test_features,,option_short_id
|
||||||
msgdata,test_msg,extension_2,test_short_id,,option_one,option_two
|
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
|
msgtype,test_tlv1,2
|
||||||
msgdata,test_tlv1,test_struct,test_short_id,
|
msgdata,test_tlv1,test_struct,test_short_id,
|
||||||
msgdata,test_tlv1,tlv,test_n1,
|
msgdata,test_tlv1,tlv,test_n1,
|
||||||
|
|
Loading…
Add table
Reference in a new issue