From 2e3e4a50ec90cfef3dd696f4f143008b8c9f0701 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 21 May 2021 14:49:05 +0930 Subject: [PATCH] update-mocks: prefer to find function defs from local includes. This matters for: - common/wallet.h vs wallet/wallet.h - common/gossip_store.h vs gossipd/gossip_store.h - common/json.h vs lightningd/json.h - common/ping.h vs lightningd/ping.h Signed-off-by: Rusty Russell --- tools/mockup.sh | 11 ++++++++++- tools/update-mocks.sh | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tools/mockup.sh b/tools/mockup.sh index c8a8a2215..9686b14cf 100755 --- a/tools/mockup.sh +++ b/tools/mockup.sh @@ -1,5 +1,13 @@ #!/usr/bin/env bash +if [ $# = 0 ]; then + echo 'Usage: mockup.sh [SYMBOLS...]' >&2 + exit 1 +fi + +UPDIRNAME=$(dirname "$(dirname "$1")") +shift + if [ $# -eq 0 ]; then # With no args, read stdin to scrape compiler output. # shellcheck disable=SC2046 @@ -29,7 +37,8 @@ fi for SYMBOL; do # If there are multiple declarations, pick first (eg. common/memleak.h # has notleak_ as a declaration, and then an inline). - WHERE=$(grep -nH "^[a-zA-Z0-9_ (),]* [*]*$SYMBOL(" ./*/*.h | head -n1) + # Also, prefer local headers over generic ones. + WHERE=$(shopt -s nullglob; grep -nH "^[a-zA-Z0-9_ (),]* [*]*$SYMBOL(" "$UPDIRNAME"/*.h ./*/*.h | head -n1) if [ x"$WHERE" = x ]; then echo "/* Could not find declaration for $SYMBOL */" continue diff --git a/tools/update-mocks.sh b/tools/update-mocks.sh index 4e071883e..140ca7717 100755 --- a/tools/update-mocks.sh +++ b/tools/update-mocks.sh @@ -30,7 +30,7 @@ if [ -n "$START" ]; then if grep -q 'too many errors emitted.*-error-limit=0' "${BASE}.err"; then LDFLAGS=-Wl,-error-limit=0 make_binary || : fi - tools/mockup.sh < "${BASE}.err" >> "${BASE}.stubs" + tools/mockup.sh "$FILE" < "${BASE}.err" >> "${BASE}.stubs" # If there are no link errors, maybe compile fail for other reason? if ! grep -F -q 'Generated stub for' "${BASE}.stubs"; then cat "${BASE}.err"