3 export PATH=$PATH:/usr/local/bin/
6 SRC_DIR=${SRC_DIR:-docs}
7 INDEX_RST=${INDEX_RST:-index.rst}
8 BUILD_DIR=${BUILD_DIR:-build}
9 OUTPUT_DIR=${OUTPUT_DIR:-output}
10 RELENG_DIR=${RELENG_DIR:-releng}
11 GERRIT_COMMENT=${GERRIT_COMMENT:-}
15 from docutils import core, nodes
18 with open('index.rst', 'r') as file:
20 doctree = core.publish_doctree(data,
21 settings_overrides={'report_level': 5,
23 if isinstance(doctree[0], nodes.title):
26 for c in doctree.children:
27 if isinstance(c, nodes.section):
33 revision="$(git rev-parse --short HEAD)"
34 rev_full="$(git rev-parse HEAD)"
35 version="$(git describe --abbrev=0 2> /dev/null || echo draft) ($revision)"
36 project="$(basename $(git rev-parse --show-toplevel))"
37 html_notes="\n Revision: $rev_full\n\n Build date: |today|"
38 default_conf='releng/docs/etc/conf.py'
39 opnfv_logo='releng/docs/etc/opnfv-logo.png'
41 function check_rst_doc() {
44 if ! which doc8 > /dev/null ; then
45 echo "Error: 'doc8' not found. Exec 'sudo pip install doc8' first."
48 # Note: This check may fail in many jobs for building project docs, since
49 # the old sample has lines more than 120. We ignore failures on this
50 # check right now, but these have to be fixed before OPNFV B release.
51 _out=$(doc8 --max-line-length 120 --ignore D000 "$_src") || {
52 _msg='Error: rst validatino (doc8) has failed, please fix the following error(s).'
53 _errs=$(echo "$_out" | sed -n -e "/^$_src/s/^/ /p")
55 echo -e "$_msg\n$_errs"
57 [[ -n "$GERRIT_COMMENT" ]] && echo -e "$_msg\n$_errs" >> "$GERRIT_COMMENT"
61 function add_html_notes() {
64 find "$_src" -name '*.rst' | while read file
66 if grep -q -e ' _sha1_' "$file" ; then
67 # TODO: remove this, once old templates were removed from all repos.
69 echo "Warn: '_sha1_' was found in [$file], use the latest document template."
70 echo " See https://wiki.opnfv.org/documentation/tools ."
72 sed -i "s/ _sha1_/ $git_sha1/g" "$file"
74 sed -i -e "\$a\\\n.. only:: html\n$html_notes" "$file"
78 function prepare_src_files() {
80 [[ -e "$BUILD_DIR/src" ]] && rm -rf "$BUILD_DIR/src"
81 cp -r "$SRC_DIR" "$BUILD_DIR/src"
82 add_html_notes "$BUILD_DIR/src"
85 function add_config() {
90 if ! grep -q -e "^$_param = " "$_conf" ; then
91 echo "Adding '$_param' into $_conf ..."
92 echo "$_param = $_val" >> "$_conf"
96 function is_top_dir() {
97 [[ "$1" == "$SRC_DIR" ]]
100 function generate_name_for_top_dir() {
101 for suffix in '' '.top' '.all' '.master' '_' '__' '___'
103 _name="$(basename $SRC_DIR)$suffix"
104 [[ -e "$SRC_DIR/$_name" ]] && continue
109 echo "Error: cannot find name for top directory [$SRC_DIR]"
113 function generate_name() {
116 if is_top_dir "$_dir" ; then
117 _name=$(generate_name_for_top_dir $SRC_DIR)
119 _name="${_dir#$SRC_DIR/}"
126 check_rst_doc $SRC_DIR
128 if [[ ! -d "$RELENG_DIR" ]] ; then
129 echo "Error: $RELENG_DIR dir not found. See https://wiki.opnfv.org/documentation/tools ."
135 find $SRC_DIR -name $INDEX_RST -printf '%h\n' | while read dir
137 name=$(generate_name $dir)
138 src="$BUILD_DIR/src${dir#$SRC_DIR}"
139 build="$BUILD_DIR/$name"
140 output="$OUTPUT_DIR/$name"
144 echo "#################${dir//?/#}"
145 echo "Building DOCS in $dir"
146 echo "#################${dir//?/#}"
149 [[ ! -f "$conf" ]] && cp "$default_conf" "$conf"
150 title=$(cd $src; python -c "$get_title_script")
151 latex_conf="[('index', '$name.tex', \"$title\", 'OPNFV', 'manual'),]"
152 add_config "$conf" 'latex_documents' "$latex_conf"
153 add_config "$conf" 'release' "u'$version'"
154 add_config "$conf" 'version' "u'$version'"
155 add_config "$conf" 'project' "u'$project'"
156 add_config "$conf" 'copyright' "u'$(date +%Y), OPNFV'"
157 cp -f $opnfv_logo "$src/opnfv-logo.png"
161 sphinx-build -b html -t html -E "$src" "$output"
163 # Note: PDF creation may fail in project doc builds.
164 # We allow this build job to be marked as succeeded with
165 # failure in PDF creation, but leave message to fix it.
166 # Any failure has to be fixed before OPNFV B release.
168 sphinx-build -b latex -t pdf -E "$src" "$build" && \
169 make -C "$build" LATEXOPTS='--interaction=nonstopmode' all-pdf
171 mv "$build/$name.pdf" "$output"
173 msg="Error: PDF creation for $dir has failed, please fix source rst file(s)."
177 [[ -n "$GERRIT_COMMENT" ]] && echo "$msg" >> "$GERRIT_COMMENT"
180 if is_top_dir "$dir" ; then
181 mv "$output"/* "$OUTPUT_DIR"/