Skip to content

Commit

Permalink
Makefile: use generic rules to make spec-derived sources.
Browse files Browse the repository at this point in the history
Now we use the same Makefile rules for all CSV->C generation.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell authored and niftynei committed Sep 1, 2020
1 parent a00179d commit 8150d28
Show file tree
Hide file tree
Showing 74 changed files with 212 additions and 227 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ SHA256STAMP = echo '$(2) SHA256STAMP:$(1)'`cat $^ | sha256sum | cut -c1-64` >> $
%_wiregen.c: %_wire.csv $(WIRE_GEN_DEPS)
@if $(call SHA256STAMP_CHANGED,exp-$(EXPERIMENTAL_FEATURES)-); then $(call VERBOSE,"wiregen $@",tools/generate-wire.py --page impl $($@_args) ${@:.c=.h} `basename $< .csv` < $< > $@ && $(call SHA256STAMP,exp-$(EXPERIMENTAL_FEATURES)-,//)); fi

%_printgen.h: %_wire.csv $(WIRE_GEN_DEPS)
@if $(call SHA256STAMP_CHANGED,exp-$(EXPERIMENTAL_FEATURES)-); then $(call VERBOSE,"printgen $@",tools/generate-wire.py -s -P --page header $($@_args) $@ `basename $< .csv` < $< > $@ && $(call SHA256STAMP,exp-$(EXPERIMENTAL_FEATURES)-,//)); fi

%_printgen.c: %_wire.csv $(WIRE_GEN_DEPS)
@if $(call SHA256STAMP_CHANGED,exp-$(EXPERIMENTAL_FEATURES)-); then $(call VERBOSE,"printgen $@",tools/generate-wire.py -s -P --page impl $($@_args) ${@:.c=.h} `basename $< .csv` < $< > $@ && $(call SHA256STAMP,exp-$(EXPERIMENTAL_FEATURES)-,//)); fi

include external/Makefile
include bitcoin/Makefile
include common/Makefile
Expand Down Expand Up @@ -485,7 +491,7 @@ clean:
$(RM) $(CCAN_OBJS) $(CDUMP_OBJS) $(ALL_OBJS)
$(RM) $(ALL_PROGRAMS) $(ALL_PROGRAMS:=.o)
$(RM) $(ALL_TEST_PROGRAMS) $(ALL_TEST_PROGRAMS:=.o)
$(RM) gen_*.h ccan/tools/configurator/configurator
$(RM) gen_*.h */gen_* ccan/tools/configurator/configurator
$(RM) ccan/ccan/cdump/tools/cdump-enumstr.o
find . -name '*gcda' -delete
find . -name '*gcno' -delete
Expand Down
2 changes: 1 addition & 1 deletion channeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ check-whitespace: $(LIGHTNINGD_CHANNEL_SRC_NOGEN:%=check-whitespace/%) $(LIGHTNI
clean: lightningd/channel-clean

lightningd/channel-clean:
$(RM) $(LIGHTNINGD_CHANNEL_OBJS) channeld/gen_*
$(RM) $(LIGHTNINGD_CHANNEL_OBJS)

-include channeld/test/Makefile
24 changes: 12 additions & 12 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
#include <secp256k1.h>
#include <sodium/crypto_aead_chacha20poly1305.h>
#include <stdio.h>
#include <wire/gen_common_wire.h>
#include <wire/gen_onion_wire.h>
#include <wire/common_wiregen.h>
#include <wire/onion_wiregen.h>
#include <wire/peer_wire.h>
#include <wire/wire.h>
#include <wire/wire_io.h>
Expand Down Expand Up @@ -1736,8 +1736,8 @@ static void handle_peer_shutdown(struct peer *peer, const u8 *shutdown)
static bool channeld_handle_custommsg(const u8 *msg)
{
#if DEVELOPER
enum wire_type type = fromwire_peektype(msg);
if (type % 2 == 1 && !wire_type_is_defined(type)) {
enum peer_wire type = fromwire_peektype(msg);
if (type % 2 == 1 && !peer_wire_is_defined(type)) {
/* The message is not part of the messages we know how to
* handle. Assuming this is a custommsg, we just forward it to the
* master. */
Expand All @@ -1755,7 +1755,7 @@ static bool channeld_handle_custommsg(const u8 *msg)
/* Peer sends onion msg. */
static void handle_onion_message(struct peer *peer, const u8 *msg)
{
enum onion_type badreason;
enum onion_wire badreason;
struct onionpacket op;
struct secret ss, *blinding_ss;
struct pubkey *blinding_in;
Expand All @@ -1775,7 +1775,7 @@ static void handle_onion_message(struct peer *peer, const u8 *msg)
badreason = parse_onionpacket(onion, TOTAL_PACKET_SIZE, &op);
if (badreason != 0) {
status_debug("onion msg: can't parse onionpacket: %s",
onion_type_name(badreason));
onion_wire_name(badreason));
return;
}

Expand Down Expand Up @@ -2031,7 +2031,7 @@ static void handle_unexpected_reestablish(struct peer *peer, const u8 *msg)

static void peer_in(struct peer *peer, const u8 *msg)
{
enum wire_type type = fromwire_peektype(msg);
enum peer_wire type = fromwire_peektype(msg);

/* Only count soft errors if the channel has locked-in already;
* otherwise we can't cancel a channel before it has opened.
Expand Down Expand Up @@ -2065,7 +2065,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
peer_failed(peer->pps,
&peer->channel_id,
"%s (%u) before funding locked",
wire_type_name(type), type);
peer_wire_name(type), type);
}
}

Expand Down Expand Up @@ -2136,7 +2136,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
peer_failed(peer->pps,
&peer->channel_id,
"Peer sent unknown message %u (%s)",
type, wire_type_name(type));
type, peer_wire_name(type));
}

static void resend_revoke(struct peer *peer)
Expand Down Expand Up @@ -2475,7 +2475,7 @@ static bool capture_premature_msg(const u8 ***shit_lnd_says, const u8 *msg)
return false;

status_debug("Stashing early %s msg!",
wire_type_name(fromwire_peektype(msg)));
peer_wire_name(fromwire_peektype(msg)));

tal_arr_expand(shit_lnd_says, tal_steal(*shit_lnd_says, msg));
return true;
Expand Down Expand Up @@ -2583,7 +2583,7 @@ static void peer_reconnect(struct peer *peer,
peer_failed(peer->pps,
&peer->channel_id,
"bad reestablish msg: %s %s",
wire_type_name(fromwire_peektype(msg)),
peer_wire_name(fromwire_peektype(msg)),
tal_hex(msg, msg));
}

Expand Down Expand Up @@ -3162,7 +3162,7 @@ static void req_in(struct peer *peer, const u8 *msg)
}

/* Now handle common messages. */
switch ((enum common_wire_type)t) {
switch ((enum common_wire)t) {
#if DEVELOPER
case WIRE_CUSTOMMSG_OUT:
channeld_send_custommsg(peer, msg);
Expand Down
2 changes: 1 addition & 1 deletion channeld/channeld_htlc.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <common/amount.h>
#include <common/htlc.h>
#include <common/pseudorand.h>
#include <wire/gen_onion_wire.h>
#include <wire/onion_wiregen.h>

struct htlc {
/* What's the status. */
Expand Down
2 changes: 1 addition & 1 deletion closingd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@ check-whitespace: $(LIGHTNINGD_CLOSING_SRC_NOGEN:%=check-whitespace/%) $(LIGHTNI
clean: closingd-clean

closingd-clean:
$(RM) $(LIGHTNINGD_CLOSING_OBJS) closingd/gen_*
$(RM) $(LIGHTNINGD_CLOSING_OBJS)

-include closingd/test/Makefile
2 changes: 1 addition & 1 deletion closingd/closingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static void do_reconnect(struct per_peer_state *pps,
&next_commitment_point)) {
peer_failed(pps, channel_id,
"bad reestablish msg: %s %s",
wire_type_name(fromwire_peektype(channel_reestablish)),
peer_wire_name(fromwire_peektype(channel_reestablish)),
tal_hex(tmpctx, channel_reestablish));
}
status_debug("Got reestablish commit=%"PRIu64" revoke=%"PRIu64,
Expand Down
2 changes: 1 addition & 1 deletion common/decode_array.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <ccan/cast/cast.h>
#include <common/decode_array.h>
#include <common/utils.h>
#include <wire/gen_peer_wire.h>
#include <wire/peer_wiregen.h>
#include <wire/wire.h>
#include <zlib.h>

Expand Down
4 changes: 2 additions & 2 deletions common/dev_disconnect.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <wire/gen_peer_wire.h>
#include <wire/peer_wiregen.h>

#if DEVELOPER
/* We move the fd if and only if we do a disconnect. */
Expand Down Expand Up @@ -71,7 +71,7 @@ enum dev_disconnect dev_disconnect(int pkt_type)
if (!dev_disconnect_count)
next_dev_disconnect();

if (!streq(wire_type_name(pkt_type), dev_disconnect_line+1))
if (!streq(peer_wire_name(pkt_type), dev_disconnect_line+1))
return DEV_DISCONNECT_NORMAL;

if (--dev_disconnect_count != 0) {
Expand Down
2 changes: 1 addition & 1 deletion common/gossip_rcvd_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <common/gossip_rcvd_filter.h>
#include <common/memleak.h>
#include <common/pseudorand.h>
#include <wire/gen_peer_wire.h>
#include <wire/peer_wiregen.h>

static u64 msg_key(const u8 *msg)
{
Expand Down
2 changes: 1 addition & 1 deletion common/gossip_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <errno.h>
#include <inttypes.h>
#include <unistd.h>
#include <wire/gen_peer_wire.h>
#include <wire/peer_wiregen.h>

void gossip_setup_timestamp_filter(struct per_peer_state *pps,
u32 first_timestamp,
Expand Down
2 changes: 1 addition & 1 deletion common/gossmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <wire/gen_peer_wire.h>
#include <wire/peer_wiregen.h>

/* We need this global to decode indexes for hash functions */
static struct gossmap *map;
Expand Down
2 changes: 1 addition & 1 deletion common/htlc_wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max)
{
struct failed_htlc *failed = tal(ctx, struct failed_htlc);
enum onion_type badonion;
enum onion_wire badonion;

failed->id = fromwire_u64(cursor, max);
badonion = fromwire_u16(cursor, max);
Expand Down
4 changes: 2 additions & 2 deletions common/htlc_wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <common/amount.h>
#include <common/htlc.h>
#include <common/sphinx.h>
#include <wire/gen_onion_wire.h>
#include <wire/onion_wiregen.h>

struct bitcoin_tx;
struct shachain;
Expand Down Expand Up @@ -54,7 +54,7 @@ struct failed_htlc {
struct sha256 *sha256_of_onion;
/* WIRE_INVALID_ONION_VERSION, WIRE_INVALID_ONION_KEY or
* WIRE_INVALID_ONION_HMAC (ie. must have BADONION) */
enum onion_type badonion;
enum onion_wire badonion;

/* Otherwise, this is the onion ready to send to them. */
const struct onionreply *onion;
Expand Down
2 changes: 1 addition & 1 deletion common/onion.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <common/ecdh.h>
#include <common/sphinx.h>
#include <sodium/crypto_aead_chacha20poly1305.h>
#include <wire/gen_onion_wire.h>
#include <wire/onion_wiregen.h>

/* BOLT #4:
*
Expand Down
2 changes: 1 addition & 1 deletion common/ping.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <common/ping.h>
#include <common/status.h>
#include <common/version.h>
#include <wire/gen_peer_wire.h>
#include <wire/peer_wiregen.h>

bool check_ping_make_pong(const tal_t *ctx, const u8 *ping, u8 **pong)
{
Expand Down
2 changes: 1 addition & 1 deletion common/read_peer_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ bool handle_peer_gossip_or_error(struct per_peer_state *pps,
/* They're talking about a different channel? */
if (is_wrong_channel(msg, channel_id, &actual)) {
status_debug("Rejecting %s for unknown channel_id %s",
wire_type_name(fromwire_peektype(msg)),
peer_wire_name(fromwire_peektype(msg)),
type_to_string(tmpctx, struct channel_id, &actual));
sync_crypto_write(pps,
take(towire_errorfmt(NULL, &actual,
Expand Down
2 changes: 1 addition & 1 deletion common/sphinx.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ u8 *serialize_onionpacket(
return dst;
}

enum onion_type parse_onionpacket(const u8 *src,
enum onion_wire parse_onionpacket(const u8 *src,
const size_t srclen,
struct onionpacket *dest)
{
Expand Down
4 changes: 2 additions & 2 deletions common/sphinx.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <common/hmac.h>
#include <secp256k1.h>
#include <sodium/randombytes.h>
#include <wire/gen_onion_wire.h>
#include <wire/onion_wiregen.h>

struct node_id;

Expand Down Expand Up @@ -164,7 +164,7 @@ u8 *serialize_onionpacket(
* @srclen: length of the @src (must be TOTAL_PACKET_SIZE)
* @dest: the destination into which we should parse the packet
*/
enum onion_type parse_onionpacket(const u8 *src,
enum onion_wire parse_onionpacket(const u8 *src,
const size_t srclen,
struct onionpacket *dest);

Expand Down
2 changes: 1 addition & 1 deletion common/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void status_peer_io_short(enum log_level iodir,
{
status_peer_debug(peer, "%s %s",
iodir == LOG_IO_OUT ? "peer_out" : "peer_in",
wire_type_name(fromwire_peektype(p)));
peer_wire_name(fromwire_peektype(p)));
}

void status_peer_io(enum log_level iodir,
Expand Down
4 changes: 2 additions & 2 deletions common/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ALL_TEST_PROGRAMS += $(COMMON_TEST_PROGRAMS)
ALL_OBJS += $(COMMON_TEST_PROGRAMS:=.o)

# Sphinx test wants to decode TLVs.
common/test/run-sphinx: wire/gen_onion_wire.o wire/towire.o wire/fromwire.o
common/test/run-sphinx: wire/onion_wiregen.o wire/towire.o wire/fromwire.o

common/test/run-param \
common/test/run-json: \
Expand All @@ -25,7 +25,7 @@ common/test/run-json: \
common/wireaddr.o \
common/type_to_string.o \
wire/fromwire.o \
wire/gen_onion_wire.o \
wire/onion_wiregen.o \
wire/towire.o

update-mocks: $(COMMON_TEST_SRC:%=update-mocks/%)
Expand Down
2 changes: 1 addition & 1 deletion common/wire_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <common/type_to_string.h>
#include <common/utils.h>
#include <common/wire_error.h>
#include <wire/gen_peer_wire.h>
#include <wire/peer_wiregen.h>

u8 *towire_errorfmtv(const tal_t *ctx,
const struct channel_id *channel,
Expand Down
2 changes: 1 addition & 1 deletion connectd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CONNECTD_COMMON_OBJS := \
common/wire_error.o \
gossipd/gossipd_wiregen.o \
lightningd/gossip_msg.o \
wire/gen_onion_wire.o
wire/onion_wiregen.o

$(LIGHTNINGD_CONNECT_OBJS): $(LIGHTNINGD_HEADERS) $(LIGHTNINGD_CONNECT_HEADERS)

Expand Down
2 changes: 1 addition & 1 deletion connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
#include <wire/gen_peer_wire.h>
#include <wire/peer_wire.h>
#include <wire/peer_wiregen.h>
#include <wire/wire_io.h>
#include <wire/wire_sync.h>
#include <zlib.h>
Expand Down
Loading

0 comments on commit 8150d28

Please sign in to comment.