Skip to content

Commit 8d18ce9

Browse files
committed
otp: Add support for warnings as errors for ex_doc
We check the output of ex_doc to see if there are any warnings emitted and if there are then we exit the build.
1 parent 3f2487d commit 8d18ce9

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

erts/configure

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7331,7 +7331,6 @@ fi
73317331
done
73327332

73337333
if test -z "$EX_DOC"; then
7334-
EX_DOC="$ERL_TOP/make/ex_doc_wrapper"
73357334
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: No 'ex_doc' command found: it will (optionally) be downloaded when building the HTML documentation " >&5
73367335
printf "%s\n" "$as_me: WARNING: No 'ex_doc' command found: it will (optionally) be downloaded when building the HTML documentation " >&2;}
73377336
fi

erts/configure.ac

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ fi
474474

475475
AC_CHECK_PROGS(EX_DOC, ex_doc)
476476
if test -z "$EX_DOC"; then
477-
EX_DOC="$ERL_TOP/make/ex_doc_wrapper"
478477
AC_MSG_WARN([No 'ex_doc' command found: it will (optionally) be downloaded when building the HTML documentation ])
479478
fi
480479

lib/common_test/doc/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ include $(ERL_TOP)/make/$(TARGET)/otp.mk
2626
include ../vsn.mk
2727
VSN=$(COMMON_TEST_VSN)
2828
APPLICATION=common_test
29+
EX_DOC_WARNINGS_AS_ERRORS=false
2930

3031
# ----------------------------------------------------
3132
# Release Target

make/doc.mk

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,17 @@ else
5252
DOC_TARGETS?=html
5353
endif
5454

55+
EX_DOC_WARNINGS_AS_ERRORS?=true
56+
5557
docs: $(DOC_TARGETS)
5658

5759
chunks:
5860

5961
HTML_DEPS?=$(wildcard $(APP_EBIN_DIR)/*.beam) $(wildcard *.md) $(wildcard */*.md) $(wildcard assets/*)
6062

61-
$(HTMLDIR)/index.html: $(HTML_DEPS) docs.exs
62-
$(gen_verbose)ERL_FLAGS="-pz $(ERL_TOP)/erts/ebin" \
63-
$(EX_DOC) $(EX_DOC_FORMATS) --homepage-url "$(INDEX_DIR)/index.html" "$(APPLICATION)" $(VSN) $(APP_EBIN_DIR) -o "$(HTMLDIR)" -c $(ERL_TOP)/make/ex_doc.exs
63+
$(HTMLDIR)/index.html: $(HTML_DEPS) docs.exs $(ERL_TOP)/make/ex_doc.exs
64+
$(gen_verbose)EX_DOC_WARNINGS_AS_ERRORS=$(EX_DOC_WARNINGS_AS_ERRORS) ERL_FLAGS="-pz $(ERL_TOP)/erts/ebin" \
65+
$(ERL_TOP)/make/ex_doc_wrapper $(EX_DOC_FORMATS) --homepage-url "$(INDEX_DIR)/index.html" "$(APPLICATION)" $(VSN) $(APP_EBIN_DIR) -o "$(HTMLDIR)" -c $(ERL_TOP)/make/ex_doc.exs
6466

6567
html: $(HTMLDIR)/index.html
6668

make/ex_doc_wrapper

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ ARGS=("$@")
44

55
set -eo pipefail {0}
66

7-
if command -v ex_doc &> /dev/null; then
8-
exec ex_doc "${ARGS[@]}"
9-
else
7+
EX_DOC=$(command -v ex_doc || true)
8+
9+
if [ -z "${EX_DOC}" ]; then
1010
echo -n "Could not find ex_doc! "
1111
read -p "Do you want to download latest ex_doc from github? (y/n)? " -n 1 -r
1212
echo
@@ -15,11 +15,35 @@ else
1515
if $ERL_TOP/otp_build download_ex_doc; then
1616
read -p "Press any key to continue..." -n 1 -r
1717
echo "continuing"
18-
exec ex_doc "${ARGS[@]}"
18+
EX_DOC=$(command -v ex_doc || true)
1919
else
2020
exit 1
2121
fi
2222
else
2323
exit 1
2424
fi
2525
fi
26+
27+
## The below bash magic captures the output of stderr into OUTPUT while still printing
28+
## everything we get to stdout and stderr. This is done by:
29+
30+
## 1. duplicating the stdout (1) and stderr (2) streams to fd 3 and 4 respectively.
31+
exec 3>&1 4>&2
32+
33+
## Running the command where we redirect stderr to fd 1 and stdout to fd 3.
34+
## We then use tee on the stderr (which is now fd 1) to print that to fd 4
35+
OUTPUT="$( { "${EX_DOC}" "${ARGS[@]}"; } 2>&1 1>&3 | tee /dev/fd/4 )"
36+
37+
## Close fd 3 and 4
38+
exec 3>&- 4>&-
39+
40+
if [ "${EX_DOC_WARNINGS_AS_ERRORS}" != "false" ]; then
41+
if echo "${OUTPUT}" | grep "warning:" 1>/dev/null; then
42+
echo "ex_doc emitted warnings"
43+
## Touch the config file in order to re-trigger make
44+
if [ -f "docs.exs" ]; then
45+
touch "docs.exs"
46+
fi
47+
exit 1;
48+
fi
49+
fi

0 commit comments

Comments
 (0)