]> begriffs open source - cmsis-driver-validation/blob - DoxyGen/gen_doc.sh
Update GitHub Actions runner to ubuntu-22.04 (#18)
[cmsis-driver-validation] / DoxyGen / gen_doc.sh
1 #!/bin/bash
2 # Version: 1.1
3 # Date: 2022-11-07
4 # This bash script generates CMSIS-Driver Documentation:
5 #
6 # Pre-requisites:
7 # - bash shell (for Windows: install git for Windows)
8 # - doxygen 1.9.6
9 # - git
10
11 set -o pipefail
12
13 DIRNAME=$(dirname $(realpath $0))
14 DOXYGEN=$(which doxygen)
15 REQ_DXY_VERSION="1.9.6"
16 REQUIRED_GEN_PACK_LIB="0.6.1"
17
18 ############ gen-pack library ###########
19
20 function install_lib() {
21   local URL="https://github.com/Open-CMSIS-Pack/gen-pack/archive/refs/tags/v$1.tar.gz"
22   echo "Downloading gen_pack lib to '$2'"
23   mkdir -p "$2"
24   curl -L "${URL}" -s | tar -xzf - --strip-components 1 -C "$2" || exit 1
25 }
26
27 function load_lib() {
28   if [[ -d ${GEN_PACK_LIB} ]]; then
29     . "${GEN_PACK_LIB}/gen-pack"
30     return 0
31   fi
32   local GLOBAL_LIB="/usr/local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
33   local USER_LIB="${HOME}/.local/share/gen-pack/${REQUIRED_GEN_PACK_LIB}"
34   if [[ ! -d "${GLOBAL_LIB}" && ! -d "${USER_LIB}" ]]; then
35     echo "Required gen-pack lib not found!" >&2
36     install_lib "${REQUIRED_GEN_PACK_LIB}" "${USER_LIB}"
37   fi
38
39   if [[ -d "${GLOBAL_LIB}" ]]; then
40     . "${GLOBAL_LIB}/gen-pack"
41   elif [[ -d "${USER_LIB}" ]]; then
42     . "${USER_LIB}/gen-pack"
43   else
44     echo "Required gen-pack lib is not installed!" >&2
45     exit 1
46   fi
47 }
48
49 load_lib
50 find_git
51
52 #########################################
53
54 if [[ ! -f "${DOXYGEN}" ]]; then
55   echo "Doxygen not found!" >&2
56   echo "Did you miss to add it to PATH?"
57   exit 1
58 else
59   version=$("${DOXYGEN}" --version | sed -E 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
60   echo "DOXYGEN is ${DOXYGEN} at version ${version}"
61   if [[ "${version}" != "${REQ_DXY_VERSION}" ]]; then
62     echo " >> Version is different from ${REQ_DXY_VERSION} !" >&2
63   fi
64 fi
65
66 if [ -z "$VERSION" ]; then
67   VERSION_FULL=$(git_describe)
68   VERSION=${VERSION_FULL%+*}
69 else
70   VERSION_FULL=${VERSION}
71 fi
72
73 echo "Generating documentation ..."
74
75 pushd $DIRNAME > /dev/null
76
77 rm -rf ${DIRNAME}/../Documentation/html
78 sed -e "s/{projectNumber}/${VERSION}/" "${DIRNAME}/CMSIS_DV.dxy.in" \
79   > "${DIRNAME}/CMSIS_DV.dxy"
80
81 PACK_CHANGELOG_MODE="tag"
82 DEV=$(pdsc_release_desc "${DIRNAME}/../ARM.CMSIS-Driver_Validation.pdsc")
83 git_changelog -f html -d "${DEV}" > src/history.txt
84
85 echo "${DOXYGEN} CMSIS_DV.dxy"
86 "${DOXYGEN}" CMSIS_DV.dxy
87 popd > /dev/null
88
89 if [[ $2 != 0 ]]; then
90   cp -f "${DIRNAME}/templates/search.css" "${DIRNAME}/../Documentation/html/search/"
91 fi
92
93 projectName=$(grep -E "PROJECT_NAME\s+=" "${DIRNAME}/CMSIS_DV.dxy" | sed -r -e 's/[^"]*"([^"]+)"/\1/')
94 datetime=$(date -u +'%a %b %e %Y %H:%M:%S')
95 year=$(date -u +'%Y')
96 if [[ "${year}" != "2022" ]]; then
97   year="2022-${year}"
98 fi
99 sed -e "s/{datetime}/${datetime}/" "${DIRNAME}/templates/footer.js.in" \
100   | sed -e "s/{year}/${year}/" \
101   | sed -e "s/{projectName}/${projectName}/" \
102   | sed -e "s/{projectNumber}/${VERSION}/" \
103   | sed -e "s/{projectNumberFull}/${VERSION_FULL}/" \
104   > "${DIRNAME}/../Documentation/html/footer.js"
105
106 exit 0