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 <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2021-05-21 14:49:05 +09:30
parent d868d4470a
commit 2e3e4a50ec
2 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [ $# = 0 ]; then
echo 'Usage: mockup.sh <filename> [SYMBOLS...]' >&2
exit 1
fi
UPDIRNAME=$(dirname "$(dirname "$1")")
shift
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
# With no args, read stdin to scrape compiler output. # With no args, read stdin to scrape compiler output.
# shellcheck disable=SC2046 # shellcheck disable=SC2046
@ -29,7 +37,8 @@ fi
for SYMBOL; do for SYMBOL; do
# If there are multiple declarations, pick first (eg. common/memleak.h # If there are multiple declarations, pick first (eg. common/memleak.h
# has notleak_ as a declaration, and then an inline). # 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 if [ x"$WHERE" = x ]; then
echo "/* Could not find declaration for $SYMBOL */" echo "/* Could not find declaration for $SYMBOL */"
continue continue

View File

@ -30,7 +30,7 @@ if [ -n "$START" ]; then
if grep -q 'too many errors emitted.*-error-limit=0' "${BASE}.err"; then if grep -q 'too many errors emitted.*-error-limit=0' "${BASE}.err"; then
LDFLAGS=-Wl,-error-limit=0 make_binary || : LDFLAGS=-Wl,-error-limit=0 make_binary || :
fi 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 there are no link errors, maybe compile fail for other reason?
if ! grep -F -q 'Generated stub for' "${BASE}.stubs"; then if ! grep -F -q 'Generated stub for' "${BASE}.stubs"; then
cat "${BASE}.err" cat "${BASE}.err"