2018-07-23 15:06:04 -07:00
|
|
|
#!/usr/bin/env bash
|
2016-08-23 13:29:02 +09:30
|
|
|
|
2021-05-21 14:49:05 +09:30
|
|
|
if [ $# = 0 ]; then
|
|
|
|
|
echo 'Usage: mockup.sh <filename> [SYMBOLS...]' >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
UPDIRNAME=$(dirname "$(dirname "$1")")
|
|
|
|
|
shift
|
|
|
|
|
|
2021-06-21 15:32:19 +05:30
|
|
|
function process_line {
|
|
|
|
|
LINE=$1
|
2016-08-23 13:29:02 +09:30
|
|
|
case "$LINE" in
|
|
|
|
|
*undefined\ reference\ to*)
|
2019-12-13 21:26:15 +01:00
|
|
|
# file.cc:(.text+0x10): undefined reference to `foo()'
|
2016-08-23 13:29:02 +09:30
|
|
|
LINE=${LINE#*undefined reference to \`}
|
2018-04-03 22:23:57 +02:00
|
|
|
echo "${LINE%\'*}"
|
2016-08-23 13:29:02 +09:30
|
|
|
;;
|
2019-12-13 21:26:15 +01:00
|
|
|
*undefined\ symbol:*)
|
|
|
|
|
# ld: error: undefined symbol: foo()
|
|
|
|
|
echo "${LINE#*undefined symbol: }"
|
|
|
|
|
;;
|
tools-make: add mock parser for clang ld output
According to #3226, it looks like clang's LD error format has changed.
This patch adds the new format so we can parse the mocks successfully.
Apple clang version 11.0.3 (clang-1103.0.32.29)
```
checking for ANSI C header files... Undefined symbols for architecture x86_64:
"_fromwire_amount_msat", referenced from:
_fromwire_tlv_test_n1_tlv3 in ccj4zKdV.o
"_fromwire_bool", referenced from:
_fromwire_test_msg in ccj4zKdV.o
_fromwire_test_msg_option_short_id in ccj4zKdV.o
_fromwire_test_msg_option_one in ccj4zKdV.o
_fromwire_test_msg_option_two in ccj4zKdV.o
"_fromwire_test_enum", referenced from:
_fromwire_test_msg in ccj4zKdV.o
_fromwire_test_msg_option_short_id in ccj4zKdV.o
_fromwire_test_msg_option_one in ccj4zKdV.o
_fromwire_test_msg_option_two in ccj4zKdV.o
"_fromwire_tlvs", referenced from:
_fromwire_test_tlv1 in ccj4zKdV.o
_fromwire_test_tlv2 in ccj4zKdV.o
_fromwire_test_tlv3 in ccj4zKdV.o
"_fromwire_tu32", referenced from:
_fromwire_tlv_test_n2_tlv2 in ccj4zKdV.o
"_fromwire_tu64", referenced from:
_fromwire_tlv_test_n1_tlv1 in ccj4zKdV.o
_fromwire_tlv_test_n2_tlv1 in ccj4zKdV.o
"_fromwire_u16", referenced from:
_fromwire_test_features in ccj4zKdV.o
_fromwire_subtype_var_assign in ccj4zKdV.o
_fromwire_subtype_arrays in ccj4zKdV.o
_fromwire_tlv_test_n1_tlv4 in ccj4zKdV.o
_fromwire_tlv_test_n3_tlv3 in ccj4zKdV.o
_fromwire_test_msg in ccj4zKdV.o
_fromwire_test_tlv1 in ccj4zKdV.o
...
"_fromwire_u32", referenced from:
_fromwire_tlv_test_n3_tlv3 in ccj4zKdV.o
_fromwire_test_msg in ccj4zKdV.o
_fromwire_test_msg_option_short_id in ccj4zKdV.o
_fromwire_test_msg_option_one in ccj4zKdV.o
_fromwire_test_msg_option_two in ccj4zKdV.o
"_fromwire_u64", referenced from:
_fromwire_test_short_id in ccj4zKdV.o
_fromwire_tlv_test_n3_tlv3 in ccj4zKdV.o
"_fromwire_u8", referenced from:
_fromwire_subtype_var_assign in ccj4zKdV.o
_fromwire_subtype_var_len in ccj4zKdV.o
_fromwire_subtype_varlen_varsize in ccj4zKdV.o
_fromwire_tlv_test_n3_tlv3 in ccj4zKdV.o
"_fromwire_u8_array", referenced from:
_fromwire_test_features in ccj4zKdV.o
_fromwire_subtype_arrays in ccj4zKdV.o
_fromwire_tlv_test_n3_tlv3 in ccj4zKdV.o
_fromwire_test_msg in ccj4zKdV.o
_fromwire_test_msg_option_short_id in ccj4zKdV.o
_fromwire_test_msg_option_one in ccj4zKdV.o
_fromwire_test_msg_option_two in ccj4zKdV.o
...
```
Changelog-Fixed: Build for macOS Catalina / Apple clang v11.0.3 fixed
2020-05-29 16:13:28 -05:00
|
|
|
*,\ referenced\ from:*)
|
|
|
|
|
# Apple clang version 11.0.3 (clang-1103.0.32.29)
|
|
|
|
|
# "_towire", referenced from:
|
|
|
|
|
LINE=${LINE#\"_}
|
|
|
|
|
echo "${LINE%\"*}"
|
|
|
|
|
;;
|
2016-08-23 13:29:02 +09:30
|
|
|
*)
|
2021-06-21 15:32:19 +05:30
|
|
|
return
|
2016-08-23 13:29:02 +09:30
|
|
|
;;
|
2021-06-21 15:32:19 +05:30
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
|
# With no args, read stdin to scrape compiler output.
|
|
|
|
|
# shellcheck disable=SC2046
|
|
|
|
|
set -- $(while read -r LINE; do
|
|
|
|
|
process_line "$LINE"; done | LC_ALL=C sort -u)
|
2016-08-23 13:29:02 +09:30
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
for SYMBOL; do
|
2022-07-08 19:22:11 +09:30
|
|
|
STUB=""
|
2017-12-15 20:44:54 +10:30
|
|
|
# If there are multiple declarations, pick first (eg. common/memleak.h
|
|
|
|
|
# has notleak_ as a declaration, and then an inline).
|
2021-05-21 14:49:05 +09:30
|
|
|
# Also, prefer local headers over generic ones.
|
|
|
|
|
WHERE=$(shopt -s nullglob; grep -nH "^[a-zA-Z0-9_ (),]* [*]*$SYMBOL(" "$UPDIRNAME"/*.h ./*/*.h | head -n1)
|
2021-09-01 16:54:23 -07:00
|
|
|
if [ -z "$WHERE" ]; then
|
2022-07-08 19:22:11 +09:30
|
|
|
WHERE=$(shopt -s nullglob; grep -nH "^extern [a-zA-Z0-9_ (),]* [*]*$SYMBOL;" "$UPDIRNAME"/*.h ./*/*.h | head -n1)
|
|
|
|
|
STUB=";"
|
|
|
|
|
if [ -z "$WHERE" ]; then
|
|
|
|
|
echo "/* Could not find declaration for $SYMBOL */"
|
|
|
|
|
continue
|
|
|
|
|
fi
|
2016-08-23 13:29:02 +09:30
|
|
|
fi
|
2017-12-10 13:41:10 +01:00
|
|
|
|
2016-08-23 13:29:02 +09:30
|
|
|
FILE=${WHERE%%:*}
|
|
|
|
|
FILE_AND_LINE=${WHERE%:*}
|
|
|
|
|
LINE=${FILE_AND_LINE#*:}
|
2018-04-03 22:23:57 +02:00
|
|
|
END=$(tail -n "+${LINE}" < "$FILE" | grep -n ';$');
|
2016-08-23 13:29:02 +09:30
|
|
|
NUM=${END%%:*}
|
|
|
|
|
|
2022-07-08 19:22:11 +09:30
|
|
|
if [ -z "$STUB" ]; then
|
|
|
|
|
if grep -q "$SYMBOL.*mock empty" "$FILE"; then
|
|
|
|
|
STUB="{ }"
|
|
|
|
|
else
|
|
|
|
|
# \n on RHS is a GNU extension, and we want to work on FreeBSD
|
|
|
|
|
# shellcheck disable=SC1004
|
|
|
|
|
STUB='\
|
2019-09-06 14:11:05 +09:30
|
|
|
{ fprintf(stderr, "'$SYMBOL' called!\\n"); abort(); }'
|
2022-07-08 19:22:11 +09:30
|
|
|
fi
|
2019-09-06 14:11:05 +09:30
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "/* Generated stub for $SYMBOL */"
|
|
|
|
|
|
2025-10-14 10:36:43 +10:30
|
|
|
tail -n "+${LINE}" < "$FILE" | head -n "$NUM" | $SED 's/^extern *//' | $SED 's/PRINTF_FMT([^)]*)//' | $SED 's/NON_NULL_ARGS([^)]*)//' | $SED 's/NO_NULL_ARGS//g' | $SED 's/NORETURN//g' | $SED 's/RETURNS_NONNULL//g' | $SED 's/LAST_ARG_NULL//g' | $SED 's/WARN_UNUSED_RESULT//g' | $SED 's/,/ UNNEEDED,/g' | $SED 's/\([a-z0-9A-Z*_]* [a-z0-9A-Z*_]*\));/\1 UNNEEDED);/' | $SED "s/;\$/$STUB/" | $SED 's/[[:space:]]*$//'
|
2016-08-23 13:29:02 +09:30
|
|
|
done
|