Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: fix developer mode compilation on FreeBSD #3344

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tools/mockup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ if [ $# -eq 0 ]; then
set -- $(while read -r LINE; do
case "$LINE" in
*undefined\ reference\ to*)
# file.cc:(.text+0x10): undefined reference to `foo()'
LINE=${LINE#*undefined reference to \`}
echo "${LINE%\'*}"
;;
*undefined\ symbol:*)
# ld: error: undefined symbol: foo()
echo "${LINE#*undefined symbol: }"
;;
*)
continue
;;
Expand Down
15 changes: 13 additions & 2 deletions tools/update-mocks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,31 @@ trap 'mv $BASE.old $FILE; rm -f $BASE.*' EXIT
START=$(grep -F -n '/* AUTOGENERATED MOCKS START */' "$FILE" | cut -d: -f1)
END=$(grep -F -n '/* AUTOGENERATED MOCKS END */' "$FILE" | cut -d: -f1)

function make_binary() {
$MAKE "${FILE/%.c/}" 2> "${BASE}.err" >/dev/null
}

if [ -n "$START" ]; then
mv "$FILE" "${BASE}.old"
echo "${FILE}:"
head -n "$START" "${BASE}.old" > "$FILE"
tail -n +"$END" "${BASE}.old" >> "$FILE"
# Try to make binary.
if ! $MAKE "${FILE/%.c/}" 2> "${BASE}.err" >/dev/null; then
if ! make_binary; then
# Some linkers (e.g. LLVM's one) don't print all errors. If this is the
# case, then re-run, asking them to do so. Search for something like
# this in the output:
# ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
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"
# 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"
exit 1
fi
sed -n 's,.*Generated stub for \(.*\) .*,\t\1,p' < "${BASE}.stubs"
sed -n 's,.*Generated stub for \(.*\) .*, \1,p' < "${BASE}.stubs"
head -n "$START" "${BASE}.old" > "$FILE"
cat "${BASE}.stubs" >> "$FILE"
tail -n +"$END" "${BASE}.old" >> "$FILE"
Expand Down