1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#!/bin/bash
ARGS=("$@")
set -eo pipefail {0}
## If EX_DOC is not set to a file, we search the PATH for it using command -v
if [ ! -f "${EX_DOC}" ]; then
EX_DOC=$(command -v ex_doc || true)
fi
if [ -z "${EX_DOC}" ]; then
echo -n "Could not find ex_doc! "
read -p "Do you want to download latest ex_doc from github? (y/n)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
if $ERL_TOP/otp_build download_ex_doc; then
read -p "Press any key to continue..." -n 1 -r
echo "continuing"
EX_DOC=$(command -v ex_doc || true)
else
exit 1
fi
else
exit 1
fi
fi
## The below bash magic captures the output of stderr into OUTPUT while still printing
## everything we get to stdout and stderr. This is done by:
## 1. duplicating the stdout (1) and stderr (2) streams to fd 3 and 4 respectively.
exec 3>&1 4>&2
## Running the command where we redirect stderr to fd 1 and stdout to fd 3.
## We then use tee on the stderr (which is now fd 1) to print that to fd 4
export ERL_LIBS=/usr/lib/elixir/lib
OUTPUT="$( { "${EX_DOC}" "${ARGS[@]}"; } 2>&1 1>&3 )"
## Close fd 3 and 4
exec 3>&- 4>&-
echo "${OUTPUT}"
## If EX_DOC_WARNINGS_AS_ERRORS is not explicitly turned on
## and any .app file is missing, we turn off warnings as errors
if [ "${EX_DOC_WARNINGS_AS_ERRORS}" != "true" ]; then
for app in $ERL_TOP/lib/*/; do
if [ ! -f $app/ebin/*.app ]; then
EX_DOC_WARNINGS_AS_ERRORS=false
fi
done
fi
if [ "${EX_DOC_WARNINGS_AS_ERRORS}" != "false" ]; then
if echo "${OUTPUT}" | grep "warning:" 1>/dev/null; then
echo "ex_doc emitted warnings"
## Touch the config file in order to re-trigger make
if [ -f "docs.exs" ]; then
touch "docs.exs"
fi
exit 1;
fi
fi
|