forked from PaddlePaddle/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gendoc.sh
executable file
·93 lines (75 loc) · 2.82 KB
/
gendoc.sh
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /bin/bash
CURDIR=$(pwd)
FLUIDDOCDIR=${FLUIDDOCDIR:=/FluidDoc}
OUTPUTDIR=${OUTPUTDIR:=/docs}
CONFIGDIR=${CONFIGDIR:=${FLUIDDOCDIR}/ci_scripts/doc-build-config}
VERSIONSTR=${VERSIONSTR:=develop}
OUTPUTFORMAT=${OUTPUTFORMAT:=html}
DOCROOT=${FLUIDDOCDIR}/docs/
APIROOT=${DOCROOT}/api/
export DOCROOT
# install paddle if not installed yet.
# PADDLE_WHL is defined in ci_start.sh
pip3 list --disable-pip-version-check | grep paddlepaddle > /dev/null
if [ $? -ne 0 ] ; then
pip3 install --no-cache-dir -i https://mirror.baidu.com/pypi/simple ${PADDLE_WHL}
fi
cd ${APIROOT}
python ./gen_doc.py
if [ -f ./copy_codes_from_en_doc.py ] && [ -f ./api_info_all.json ] ; then
python ./copy_codes_from_en_doc.py --api-info ./api_info_all.json ${DOCROOT}
fi
if [ -f ${FLUIDDOCDIR}/ci_scripts/hooks/pre-doc-compile.sh ] ; then
${FLUIDDOCDIR}/ci_scripts/hooks/pre-doc-compile.sh
fi
thread=2
tmp_fifofile=/tmp/$$.fifo #脚本运行的当前进程ID号作为文件名
mkfifo $tmp_fifofile #新建一个随机fifo管道文件
exec 6<>$tmp_fifofile #定义文件描述符6指向这个fifo管道文件
rm $tmp_fifofile #清空管道内容
# for循环 往 fifo管道文件中写入$thread个空行
for ((i=0;i<$thread;i++));do
echo
done >&6
sphinx_thread=12
for lang in en zh ; do
read -u6
{
mkdir -p ${OUTPUTDIR}/${lang}/${VERSIONSTR}
/usr/local/bin/sphinx-build -b ${OUTPUTFORMAT} -j ${sphinx_thread} -d /var/doctrees -c ${CONFIGDIR}/${lang} ${DOCROOT} ${OUTPUTDIR}/${lang}/${VERSIONSTR}
if [ "${OUTPUTFORMAT}" = "html" ] ; then
INDEXFILE="${OUTPUTDIR}/${lang}/${VERSIONSTR}/index_${lang}.html"
if [ "${lang}" = "zh" ] ; then
INDEXFILE="${OUTPUTDIR}/${lang}/${VERSIONSTR}/index_cn.html"
fi
if [ ! -f ${INDEXFILE} ] ; then
/usr/local/bin/sphinx-build -b ${OUTPUTFORMAT} -j ${sphinx_thread} -d /var/doctrees -c ${CONFIGDIR}/${lang} ${DOCROOT} ${OUTPUTDIR}/${lang}/${VERSIONSTR}
fi
if [ "${lang}" = "en" ] ; then
if [ -f /root/post_filter_htmls.py ] && [ ! -f ${FLUIDDOCDIR}/ci_scripts/hooks/post-doc-compile.sh ] ; then
python /root/post_filter_htmls.py ${OUTPUTDIR}/${lang}/${VERSIONSTR}/api/
fi
fi
fi
echo >&6
} &
done
wait #等到后台的进程都执行完毕
exec 6>&- ##删除文件描述符6
if [ -f ${FLUIDDOCDIR}/ci_scripts/hooks/post-doc-compile.sh ] ; then
${FLUIDDOCDIR}/ci_scripts/hooks/post-doc-compile.sh ${OUTPUTDIR} ${VERSIONSTR}
fi
if [ "${VERSIONSTR:0:2}" = "1." ] ; then
echo Done
exit 0
fi
mkdir -p ${OUTPUTDIR}/en/${VERSIONSTR}/gen_doc_output
for f in alias_api_mapping api_label display_doc_list not_display_doc_list api_info_dict.json api_info_all.json ; do
if [ -f ${APIROOT}/${f} ] ; then
cp ${APIROOT}/${f} ${OUTPUTDIR}/en/${VERSIONSTR}/gen_doc_output
fi
done
# TODO: upload OUTPUTDIR to bos
echo Done
cd ${CURDIR}
exit 0