Skip to content

Commit

Permalink
update-mocks: prefer to find function defs from local includes.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rustyrussell committed May 22, 2021
1 parent d868d44 commit 2e3e4a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion tools/mockup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/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
# With no args, read stdin to scrape compiler output.
# shellcheck disable=SC2046
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tools/update-mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2e3e4a5

Please sign in to comment.