forked from erlang/otp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_doc_wrapper.in
executable file
·52 lines (43 loc) · 1.46 KB
/
ex_doc_wrapper.in
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
#!/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
OUTPUT="$( { escript@EXEEXT@ "${EX_DOC}" "${ARGS[@]}"; } 2>&1 1>&3 | tee /dev/fd/4 )"
## Close fd 3 and 4
exec 3>&- 4>&-
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