3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 function die_on_docs_error () {
21 # Source this fragment if you want to abort on any failure.
24 # - DOCS_EXIT_STATUS - Set by a generation function.
26 # - die - Print to stderr and exit.
30 if [[ "${DOCS_EXIT_STATUS}" != "0" ]]; then
31 die "Failed to generate docs!" "${DOCS_EXIT_STATUS}"
35 function generate_docs () {
37 # Generate docs content.
40 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
42 # - DOCS_EXIT_STATUS - Exit status of docs generation.
44 # - die - Print to stderr and exit.
48 pushd "${TOOLS_DIR}"/doc_gen || die "Pushd failed!"
53 # Remove the old build:
54 rm -rf ${BUILD_DIR} || true
55 rm -rf ${WORKING_DIR} || true
57 # Create working directories
58 mkdir -p "${BUILD_DIR}" || die "Mkdir failed!"
59 mkdir -p "${WORKING_DIR}"/resources/libraries/python/ || die "Mkdir failed!"
60 mkdir -p "${WORKING_DIR}"/resources/libraries/robot/ || die "Mkdir failed!"
61 mkdir -p "${WORKING_DIR}"/tests/ || die "Mkdir failed!"
63 # Copy the Sphinx source files:
64 cp -r src/* ${WORKING_DIR}/ || die "Copy the Sphinx source files failed!"
66 # Copy the source files to be processed:
67 from_dir="${RESOURCES_DIR}/libraries/python/"
68 to_dir="${WORKING_DIR}/resources/libraries/python/"
69 dirs="${from_dir} ${to_dir}"
70 rsync -ar --include='*/' --include='*.py' --exclude='*' ${dirs} || {
74 from_dir="${RESOURCES_DIR}/libraries/robot/"
75 to_dir="${WORKING_DIR}/resources/libraries/robot/"
76 dirs="${from_dir} ${to_dir}"
77 rsync -ar --include='*/' --include '*.robot' --exclude '*' ${dirs} || {
80 touch ${to_dir}/index.robot || {
81 die "Touch index.robot file failed!"
84 # Due to hoststack tests having dots in the name of suite, tests will become
85 # disabled as spihnxdoc cannot properly work with the path. gen_rst
86 # is generating dots scheme. The solution is to rename suites as
87 # having dots is misleading with robot framework naming conventions.
89 #from_dir="${CSIT_DIR}/tests/"
90 #to_dir="${WORKING_DIR}/tests/"
91 #dirs="${from_dir} ${to_dir}"
92 #rsync -ar --include='*/' --include '*.robot' --exclude '*' ${dirs} || {
96 find ${WORKING_DIR}/ -type d -exec echo {} \; -exec touch {}/__init__.py \;
98 python3 gen_rst.py || die "Generate .rst files failed!"
100 # Generate the documentation:
101 DATE=$(date -u '+%d-%b-%Y') || die "Get date failed!"
104 all_options+=("-c" "${WORKING_DIR}")
106 all_options+=("-b" "html")
108 all_options+=("-D" "version="${GERRIT_BRANCH:-master}"")
109 all_options+=("${WORKING_DIR}" "${BUILD_DIR}/")
112 sphinx-build "${all_options[@]}"
113 DOCS_EXIT_STATUS="$?"
117 function generate_report () {
119 # Generate report content.
122 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
123 # - ${GERRIT_BRANCH} - Gerrit branch used for release tagging.
125 # - DOCS_EXIT_STATUS - Exit status of report generation.
127 # - die - Print to stderr and exit.
131 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
133 # Set default values in config array.
139 # Create working directories.
140 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
142 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
144 all_options=("pal.py")
145 all_options+=("--specification" "specifications/report")
146 all_options+=("--release" "${GERRIT_BRANCH:-master}")
147 all_options+=("--week" $(date "+%V"))
148 all_options+=("--logging" "INFO")
149 all_options+=("--force")
152 python "${all_options[@]}"
153 DOCS_EXIT_STATUS="$?"
158 function generate_report_local () {
160 # Generate report from local content.
163 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
164 # - ${CSIT_REPORT_FILENAME} - Source filename.
165 # - ${CSIT_REPORT_DIRECTORYNAME} - Source directory.
166 # - ${CSIT_REPORT_INSTALL_DEPENDENCIES} - Whether to install dependencies.
167 # - ${CSIT_REPORT_INSTALL_LATEX} - Whether to install latex.
169 # - DOCS_EXIT_STATUS - Exit status of report generation.
171 # - die - Print to stderr and exit.
175 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
177 filename="${CSIT_REPORT_FILENAME-}"
178 directoryname="${CSIT_REPORT_DIRECTORYNAME-}"
179 install_dependencies="${CSIT_REPORT_INSTALL_DEPENDENCIES:-1}"
180 install_latex="${CSIT_REPORT_INSTALL_LATEX:-0}"
182 # Set default values in config array.
188 # Install system dependencies.
189 if [[ ${install_dependencies} -eq 1 ]] ;
191 sudo apt -y update || die "APT update failed!"
192 sudo apt -y install libxml2 libxml2-dev libxslt-dev \
193 build-essential zlib1g-dev unzip || die "APT install failed!"
196 if [[ ${install_latex} -eq 1 ]] ;
198 sudo apt -y update || die "APT update failed!"
199 sudo apt -y install xvfb texlive-latex-recommended \
200 texlive-fonts-recommended texlive-fonts-extra texlive-latex-extra \
201 latexmk wkhtmltopdf inkscape || die "APT install failed!"
202 target="/usr/share/texlive/texmf-dist/web2c/texmf.cnf"
203 sudo sed -i.bak 's/^\(main_memory\s=\s\).*/\110000000/' "${target}" || {
204 die "Patching latex failed!"
208 # Create working directories.
209 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
211 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
213 all_options=("pal.py")
214 all_options+=("--specification" "specifications/report_local")
215 all_options+=("--release" "${RELEASE:-master}")
216 all_options+=("--week" "${WEEK:-1}")
217 all_options+=("--logging" "INFO")
218 all_options+=("--force")
219 if [[ ${filename} != "" ]]; then
220 all_options+=("--input-file" "${filename}")
222 if [[ ${directoryname} != "" ]]; then
223 all_options+=("--input-directory" "${directoryname}")
227 python "${all_options[@]}"
228 DOCS_EXIT_STATUS="$?"
233 function generate_trending () {
235 # Generate trending content.
238 # - ${TOOLS_DIR} - Path to existing resources subdirectory "tools".
240 # - DOCS_EXIT_STATUS - Exit status of trending generation.
242 # - die - Print to stderr and exit.
246 pushd "${TOOLS_DIR}"/presentation || die "Pushd failed!"
248 # Set default values in config array.
253 # Create working directories.
254 mkdir "${DIR[WORKING]}" || die "Mkdir failed!"
256 export PYTHONPATH=`pwd`:`pwd`/../../../ || die "Export failed!"
258 all_options=("pal.py")
259 all_options+=("--specification" "specifications/trending")
260 all_options+=("--logging" "INFO")
261 all_options+=("--force")
264 python "${all_options[@]}"
265 DOCS_EXIT_STATUS="$?"