Skip to content

Commit

Permalink
check: make sure all files outside contrib/ include "config.h" first.
Browse files Browse the repository at this point in the history
And turn "" includes into full-path (which makes it easier to put
config.h first, and finds some cases check-includes.sh missed
previously).

config.h sets _GNU_SOURCE which really needs to be done before any
'#includes': we mainly got away with it with glibc, but other platforms
like Alpine may have stricter requirements.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Dec 5, 2021
1 parent bdabef9 commit 4ffda34
Show file tree
Hide file tree
Showing 246 changed files with 351 additions and 102 deletions.
11 changes: 6 additions & 5 deletions bitcoin/base58.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// Copyright (c) 2009-2012 The Bitcoin Developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "address.h"
#include "base58.h"
#include "privkey.h"
#include "pubkey.h"
#include "shadouble.h"
#include "config.h"
#include <bitcoin/address.h>
#include <bitcoin/base58.h>
#include <bitcoin/privkey.h>
#include <bitcoin/pubkey.h>
#include <bitcoin/shadouble.h>
#include <common/utils.h>
#include <wally_core.h>

Expand Down
3 changes: 2 additions & 1 deletion bitcoin/chainparams.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "chainparams.h"
#include "config.h"
#include <bitcoin/chainparams.h>
#include <ccan/array_size/array_size.h>
#include <ccan/tal/str/str.h>
#include <common/utils.h>
Expand Down
1 change: 1 addition & 0 deletions bitcoin/feerate.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/feerate.h>

u32 feerate_from_style(u32 feerate, enum feerate_style style)
Expand Down
1 change: 1 addition & 0 deletions bitcoin/preimage.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/preimage.h>
#include <wire/wire.h>

Expand Down
3 changes: 2 additions & 1 deletion bitcoin/privkey.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "privkey.h"
#include "config.h"
#include <bitcoin/privkey.h>
#include <ccan/str/hex/hex.h>
#include <common/type_to_string.h>
#include <wire/wire.h>
Expand Down
5 changes: 3 additions & 2 deletions bitcoin/pubkey.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "privkey.h"
#include "pubkey.h"
#include "config.h"
#include <assert.h>
#include <bitcoin/privkey.h>
#include <bitcoin/pubkey.h>
#include <ccan/mem/mem.h>
#include <ccan/str/hex/hex.h>
#include <common/type_to_string.h>
Expand Down
11 changes: 6 additions & 5 deletions bitcoin/script.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "address.h"
#include "locktime.h"
#include "preimage.h"
#include "pubkey.h"
#include "script.h"
#include "config.h"
#include <assert.h>
#include <bitcoin/address.h>
#include <bitcoin/locktime.h>
#include <bitcoin/preimage.h>
#include <bitcoin/pubkey.h>
#include <bitcoin/script.h>
#include <ccan/endian/endian.h>
#include <ccan/mem/mem.h>
#include <common/utils.h>
Expand Down
3 changes: 2 additions & 1 deletion bitcoin/shadouble.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "shadouble.h"
#include "config.h"
#include <bitcoin/shadouble.h>
#include <ccan/mem/mem.h>
#include <common/type_to_string.h>
#include <wire/wire.h>
Expand Down
1 change: 1 addition & 0 deletions bitcoin/short_channel_id.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/short_channel_id.h>
#include <ccan/tal/str/str.h>
#include <common/type_to_string.h>
Expand Down
13 changes: 7 additions & 6 deletions bitcoin/signature.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#include "privkey.h"
#include "pubkey.h"
#include "script.h"
#include "shadouble.h"
#include "signature.h"
#include "tx.h"
#include "config.h"
#include <assert.h>
#include <bitcoin/privkey.h>
#include <bitcoin/psbt.h>
#include <bitcoin/pubkey.h>
#include <bitcoin/script.h>
#include <bitcoin/shadouble.h>
#include <bitcoin/signature.h>
#include <bitcoin/tx.h>
#include <ccan/mem/mem.h>
#include <common/type_to_string.h>
#include <wire/wire.h>
Expand Down
1 change: 1 addition & 0 deletions bitcoin/test/run-bitcoin_block_from_hex.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include "../block.c"
#include "../psbt.c"
#include "../shadouble.c"
Expand Down
3 changes: 2 additions & 1 deletion bitcoin/varint.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "varint.h"
#include "config.h"
#include <bitcoin/varint.h>

size_t varint_size(varint_t v)
{
Expand Down
5 changes: 5 additions & 0 deletions ccan_compat.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#ifndef LIGHTNING_CCAN_COMPAT_H
#define LIGHTNING_CCAN_COMPAT_H

/* Magical file included from config.h (ie. everywhere) which renames
* sha256 routines so they don't clash with libwally-core's internal ones */

/* So, for obvious reasons, this is an exception to the usual rule that we
#include "config.h"
* in all files. */
#define sha256(sha, p, size) ccan_sha256(sha, p, size)
#define sha256_init(ctx) ccan_sha256_init(ctx)
#define sha256_update(ctx, p, size) ccan_sha256_update(ctx, p, size)
Expand Down
1 change: 1 addition & 0 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* reading and writing synchronously we could deadlock if we hit buffer
* limits, unlikely as that is.
*/
#include "config.h"
#include <ccan/asort/asort.h>
#include <ccan/cast/cast.h>
#include <ccan/mem/mem.h>
Expand Down
1 change: 1 addition & 0 deletions channeld/commit_tx.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/script.h>
#include <channeld/commit_tx.h>
#include <common/htlc_trim.h>
Expand Down
1 change: 1 addition & 0 deletions channeld/test/run-commit_tx.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <inttypes.h>
#include <stdio.h>
#include <common/type_to_string.h>
Expand Down
1 change: 1 addition & 0 deletions channeld/test/run-full_channel.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include "../../common/blockheight_states.c"
#include "../../common/channel_id.c"
#include "../../common/fee_states.c"
Expand Down
4 changes: 2 additions & 2 deletions channeld/watchtower.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "watchtower.h"

#include "config.h"
#include <bitcoin/feerate.h>
#include <bitcoin/script.h>
#include <channeld/watchtower.h>
#include <common/features.h>
#include <common/htlc_tx.h>
#include <common/keyset.h>
Expand Down
1 change: 1 addition & 0 deletions closingd/closingd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/script.h>
#include <ccan/cast/cast.h>
#include <ccan/fdpass/fdpass.h>
Expand Down
3 changes: 2 additions & 1 deletion common/addr.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "addr.h"
#include "config.h"
#include <bitcoin/address.h>
#include <bitcoin/base58.h>
#include <bitcoin/script.h>
#include <common/addr.h>
#include <common/bech32.h>

char *encode_scriptpubkey_to_addr(const tal_t *ctx,
Expand Down
1 change: 1 addition & 0 deletions common/base32.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/str/base32/base32.h>
#include <common/base32.h>

Expand Down
4 changes: 2 additions & 2 deletions common/bech32.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "bech32.h"

#include "config.h"
#include <assert.h>
#include <common/bech32.h>
#include <string.h>

static uint32_t bech32_polymod_step(uint32_t pre) {
Expand Down
3 changes: 2 additions & 1 deletion common/bech32_util.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "bech32_util.h"
#include "config.h"
#include <ccan/tal/str/str.h>
#include <common/bech32.h>
#include <common/bech32_util.h>

static u8 get_bit(const u8 *src, size_t bitoff)
{
Expand Down
3 changes: 2 additions & 1 deletion common/billboard.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "billboard.h"
#include "config.h"
#include <ccan/ccan/tal/str/str.h>
#include <common/billboard.h>
#include <common/utils.h>

char *billboard_message(const tal_t *ctx,
Expand Down
1 change: 1 addition & 0 deletions common/bip32.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <common/bip32.h>
#include <wally_bip32.h>
#include <wire/wire.h>
Expand Down
1 change: 1 addition & 0 deletions common/blindedpath.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/cast/cast.h>
#include <common/blindedpath.h>
#include <common/blinding.h>
Expand Down
1 change: 1 addition & 0 deletions common/blinding.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/privkey.h>
#include <bitcoin/pubkey.h>
#include <common/blinding.h>
Expand Down
1 change: 1 addition & 0 deletions common/blockheight_states.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/array_size/array_size.h>
#include <ccan/cast/cast.h>
#include <ccan/tal/str/str.h>
Expand Down
1 change: 1 addition & 0 deletions common/bolt11.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/address.h>
#include <bitcoin/script.h>
#include <ccan/array_size/array_size.h>
Expand Down
1 change: 1 addition & 0 deletions common/bolt11_json.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/address.h>
#include <bitcoin/base58.h>
#include <bitcoin/script.h>
Expand Down
1 change: 1 addition & 0 deletions common/bolt12.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/chainparams.h>
#include <ccan/tal/str/str.h>
#include <common/bech32_util.h>
Expand Down
1 change: 1 addition & 0 deletions common/bolt12_merkle.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/cast/cast.h>
#include <ccan/ilog/ilog.h>
#include <ccan/mem/mem.h>
Expand Down
1 change: 1 addition & 0 deletions common/channel_config.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <common/channel_config.h>
#include <wire/wire.h>

Expand Down
1 change: 1 addition & 0 deletions common/channel_id.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/pubkey.h>
#include <bitcoin/tx.h>
#include <common/channel_id.h>
Expand Down
1 change: 1 addition & 0 deletions common/channel_type.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/array_size/array_size.h>
#include <common/channel_type.h>

Expand Down
8 changes: 4 additions & 4 deletions common/close_tx.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "bitcoin/script.h"
#include "bitcoin/tx.h"
#include "close_tx.h"
#include "permute_tx.h"
#include "config.h"
#include <assert.h>
#include <bitcoin/script.h>
#include <common/close_tx.h>
#include <common/permute_tx.h>
#include <common/utils.h>

struct bitcoin_tx *create_close_tx(const tal_t *ctx,
Expand Down
3 changes: 2 additions & 1 deletion common/configdir.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "configdir.h"
#include "config.h"
#include <assert.h>
#include <bitcoin/chainparams.h>
#include <ccan/cast/cast.h>
Expand All @@ -7,6 +7,7 @@
#include <ccan/tal/grab_file/grab_file.h>
#include <ccan/tal/path/path.h>
#include <ccan/tal/str/str.h>
#include <common/configdir.h>
#include <common/utils.h>
#include <common/version.h>

Expand Down
1 change: 1 addition & 0 deletions common/crypto_state.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <common/crypto_state.h>
#include <wire/wire.h>

Expand Down
1 change: 1 addition & 0 deletions common/crypto_sync.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/read_write_all/read_write_all.h>
#include <common/crypto_sync.h>
#include <common/cryptomsg.h>
Expand Down
1 change: 1 addition & 0 deletions common/daemon_conn.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/fdpass/fdpass.h>
#include <ccan/io/fdpass/fdpass.h>
#include <common/daemon_conn.h>
Expand Down
1 change: 1 addition & 0 deletions common/decode_array.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/cast/cast.h>
#include <common/decode_array.h>
#include <wire/peer_wire.h>
Expand Down
1 change: 1 addition & 0 deletions common/derive_basepoints.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/crypto/hkdf_sha256/hkdf_sha256.h>
#include <common/derive_basepoints.h>
#include <common/utils.h>
Expand Down
1 change: 1 addition & 0 deletions common/descriptor_checksum.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/short_types/short_types.h>
#include <common/descriptor_checksum.h>
#include <stdlib.h>
Expand Down
1 change: 1 addition & 0 deletions common/dijkstra.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Without this, gheap is *really* slow! Comment out for debugging. */
#define NDEBUG
#include "config.h"
#include <ccan/cast/cast.h>
#include <common/dijkstra.h>
#include <common/gossmap.h>
Expand Down
1 change: 1 addition & 0 deletions common/ecdh_hsmd.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <common/ecdh_hsmd.h>
#include <hsmd/hsmd_wiregen.h>
#include <wire/wire_sync.h>
Expand Down
3 changes: 2 additions & 1 deletion common/features.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "features.h"
#include "config.h"
#include <assert.h>
#include <ccan/array_size/array_size.h>
#include <ccan/tal/str/str.h>
#include <common/features.h>
#include <wire/peer_wire.h>

enum feature_copy_style {
Expand Down
1 change: 1 addition & 0 deletions common/fee_states.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/array_size/array_size.h>
#include <ccan/cast/cast.h>
#include <ccan/tal/str/str.h>
Expand Down
1 change: 1 addition & 0 deletions common/gossip_rcvd_filter.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/crypto/siphash24/siphash24.h>
#include <ccan/htable/htable.h>
#include <common/gossip_rcvd_filter.h>
Expand Down
1 change: 1 addition & 0 deletions common/hash_u5.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/endian/endian.h>
#include <common/hash_u5.h>
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions common/hmac.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/privkey.h>
#include <ccan/array_size/array_size.h>
#include <ccan/mem/mem.h>
Expand Down
1 change: 1 addition & 0 deletions common/hsm_encryption.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <common/hsm_encryption.h>
#include <termios.h>
#include <unistd.h>
Expand Down
1 change: 1 addition & 0 deletions common/htlc_state.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/array_size/array_size.h>
#include <common/htlc.h>
#include "htlc_state_names_gen.h"
Expand Down
1 change: 1 addition & 0 deletions common/htlc_trim.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <common/htlc_trim.h>
#include <common/htlc_tx.h>

Expand Down
1 change: 1 addition & 0 deletions common/htlc_tx.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/preimage.h>
#include <bitcoin/script.h>
#include <common/htlc_tx.h>
Expand Down
1 change: 1 addition & 0 deletions common/htlc_wire.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <ccan/array_size/array_size.h>
#include <ccan/cast/cast.h>
#include <ccan/crypto/shachain/shachain.h>
Expand Down
1 change: 1 addition & 0 deletions common/initial_commit_tx.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "config.h"
#include <bitcoin/script.h>
#include <ccan/array_size/array_size.h>
#include <common/initial_commit_tx.h>
Expand Down
3 changes: 2 additions & 1 deletion common/io_lock.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "io_lock.h"
#include "config.h"
#include <assert.h>
#include <ccan/io/io_plan.h>
#include <common/io_lock.h>

struct io_lock {
bool locked;
Expand Down
Loading

0 comments on commit 4ffda34

Please sign in to comment.