Debian Codegraph @

build_tools/make_xml_documentation

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #!/bin/shscip-shell filesystem . . `/bin/sh`.
2 # shellcheck disable=SC2154
3
4 PROGNAME="${0##*/}"
5
6 tmp_output_file=/tmp/xmldoc.$$.xml
7
8 cleanupscip-shell shell shell-project 0.0.0 cleanup().() {
9 [scip-shell system . . `[`. -f "$tmp_output_file" ] && rmscip-shell system . . rm. "$tmp_output_file"
10 }
11
12 trap cleanup EXIT
13
14 # Fail on errors
15 set -e
16
17 usagescip-shell shell shell-project 0.0.0 usage().() {
18 catscip-shell system . . cat. <<-EOF
19 Usage: ${PROGNAME} --command=(create_xml | print_dependencies)
20 --source-tree=<asterisk_source_tree> [ --mod-subdirs=<subdir_search_list> ]
21 [ --with-moduleinfo ] [--for-wiki ] [ --validate ]
22 [ --output-file=<output_xml_file> ]
23 [ --core-output-file=<core_output_xml_file> ]
24
25 command:
26 print_dependencies: Print the source files that have documentation
27 for use by "make" as dependencies.
28 create_xml: Create the actual XML output file.
29
30 source-tree: The path to the Asterisk source tree.
31
32 mod-subdirs: A quoted, space-separated list of module sub-directories
33 to search for documentation. Defaults to
34 "channels pbx apps codecs formats cdr cel bridges funcs tests main res addons"
35
36 with-moduleinfo: Include the "MODULEINFO" block from source files.
37 Default is to not include MODULEINFO
38
39 for-wiki: Perform special post processing for wiki documentation.
40 This creates two output files and therefore needs both
41 <output-file> and <core-output-file>.
42 Default is to not perform wiki post-processing.
43
44 validate: Run xmllint or xmlstarlet to validate output-file.
45
46 output-file: The XML file to write to if the command was
47 "create_xml".
48
49 core-output-file: The additional XML file to write to if the command was
50 "create_xml" with "for-wiki".
51
52 EOF
53 }
54
55 with_moduleinfo=0
56 for_wiki=0
57 validate=0
58 command=""
59 mod_subdirs="channels pbx apps codecs formats cdr cel bridges funcs tests main res addons"
60 source_tree=""
61 output_file=""
62 core_output_file=""
63
64 for arg in "$@" ; do
65 case ${arg} in
66 --for-wiki)
67 for_wiki=1
68 ;;
69 --with-moduleinfo)
70 with_moduleinfo=1
71 ;;
72 --validate)
73 validate=1
74 ;;
75 --command=*)
76 command=${arg#*=}
77 ;;
78 --source-tree=*)
79 source_tree=${arg#*=}
80 ;;
81 --mod-subdirs=*)
82 mod_subdirs="${arg#*=}"
83 ;;
84 --output-file=*)
85 output_file=${arg#*=}
86 ;;
87 --core-output-file=*)
88 core_output_file=${arg#*=}
89 ;;
90 -h|--help)
91 usagescip-shell shell shell-project 0.0.0 usage().
92 exit 0
93 ;;
94 *)
95 echoscip-shell system . . echo. "unknown option '${arg}'."
96 usagescip-shell shell shell-project 0.0.0 usage().
97 exit 1
98 ;;
99 esac
100 done
101
102 if [scip-shell system . . `[`. "${command}" = "" ] ; then
103 echoscip-shell system . . echo. "No command specified"
104 usagescip-shell shell shell-project 0.0.0 usage().
105 exit 1
106 fi
107
108 if [scip-shell system . . `[`. "${source_tree}" = "" ] ; then
109 echoscip-shell system . . echo. "No source-tree specified"
110 usagescip-shell shell shell-project 0.0.0 usage().
111 exit 1;
112 fi
113
114 if [scip-shell system . . `[`. ! -d "${source_tree}" ] ; then
115 echoscip-shell system . . echo. "Asterisk source tree '${source_tree}' doesn't exist."
116 exit 1
117 fi
118
119 if [scip-shell system . . `[`. ! -f "${source_tree}/makeopts" ] ; then
120 echoscip-shell system . . echo. "There's no 'makeopts' in '${source_tree}'. Maybe you need to run ./configure?"
121 exit 1
122 fi
123
124 # This script is normally run from the top-level Makefile which
125 # will set the tools variables to actual paths, or ':' if
126 # the tool isn't found. If this script is run from the
127 # command line for testing purposes however, we'll need to
128 # set some sane defaults.
129 if [scip-shell system . . `[`. "${GREP}" = "" ] ; then GREP="grep" ; fi
130 if [scip-shell system . . `[`. "${FIND}" = "" ] ; then FIND="find" ; fi
131 if [scip-shell system . . `[`. "${AWK}" = "" ] ; then AWK="awk" ; fi
132 if [scip-shell system . . `[`. "${DIRNAME}" = "" ] ; then DIRNAME="dirname" ; fi
133 if [scip-shell system . . `[`. "${BASENAME}" = "" ] ; then BASENAME="basename" ; fi
134 if [scip-shell system . . `[`. "${SED}" = "" ] ; then SED="sed" ; fi
135 if [scip-shell system . . `[`. "${CAT}" = "" ] ; then CAT="cat" ; fi
136 if [scip-shell system . . `[`. "${XMLLINT}" = "" ] ; then XMLLINT="xmllint" ; fi
137 if [scip-shell system . . `[`. "${XMLSTARLET}" = "" ] ; then XMLSTARLET="xmlstarlet" ; fi
138
139 if [scip-shell system . . `[`. "${for_wiki}" -eq "1" ] || [scip-shell system . . `[`. "${validate}" -eq "1" ]; then
140 if [scip-shell system . . `[`. "${XMLLINT}${XMLSTARLET}" = "::" ] ; then
141 echoscip-shell system . . echo. "Either xmllint or xmlstarlet is required for wiki post-processing or validation."
142 exit 1
143 fi
144 fi
145
146 make_absolutescip-shell shell shell-project 0.0.0 make_absolute().() {
147 case "$1" in
148 /*) echoscip-shell system . . echo. "$1" ;;
149 *) echoscip-shell system . . echo. "$source_tree/$1" ;;
150 esac
151 }
152
153 if [scip-shell system . . `[`. "${command}" = "print_dependencies" ] ; then
154 for subdir in ${mod_subdirs} ; do
155 subpath=$(make_absolutescip-shell shell shell-project 0.0.0 make_absolute(). "$subdir")
156 ${FIND} "${subpath}" \( -name '*.c' -o -name '*.cc' -o -name '*.xml' \) \
157 -exec ${GREP} -l -E '(language="en_US"|appdocsxml.dtd)' '{}' \;
158 done
159 exit
160 fi
161
162 if [scip-shell system . . `[`. "${command}" != "create_xml" ] ; then
163 echoscip-shell system . . echo. "Command '${command}' is invalid."
164 usagescip-shell shell shell-project 0.0.0 usage().
165 exit 1
166 fi
167
168 if [scip-shell system . . `[`. "${output_file}" = "" ] ; then
169 echoscip-shell system . . echo. "output-file is required for command '${command}'."
170 usagescip-shell shell shell-project 0.0.0 usage().
171 exit 1;
172 fi
173
174 output_dir=$(${DIRNAME} "${output_file}")
175 if [scip-shell system . . `[`. ! -d "${output_dir}" ] ; then
176 echoscip-shell system . . echo. "output destination directory '${output_dir}' doesn't exist."
177 exit 1
178 fi
179
180 if [scip-shell system . . `[`. "${for_wiki}" -eq "1" ] && [scip-shell system . . `[`. "${core_output_file}" = "" ] ; then
181 echoscip-shell system . . echo. "core-output-file is required for command '${command}' and 'for-wiki'."
182 usagescip-shell shell shell-project 0.0.0 usage().
183 exit 1;
184 fi
185
186 core_output_dir=$(${DIRNAME} "${core_output_file}")
187 if [scip-shell system . . `[`. ! -d "${core_output_dir}" ] ; then
188 echoscip-shell system . . echo. "core destination directory '${core_output_dir}' doesn't exist."
189 exit 1
190 fi
191
192 ${CAT} > "${output_file}" <<-EOF
193 <?xml version="1.0" encoding="UTF-8"?>
194 <!DOCTYPE docs SYSTEM "appdocsxml.dtd">
195 <?xml-stylesheet type="text/xsl" href="appdocsxml.xslt"?>
196 <docs xmlns:xi="http://www.w3.org/2001/XInclude">
197 EOF
198
199 printfscip-shell system . . printf. "Building Documentation For: "
200
201 for subdir in ${mod_subdirs} ; do
202 printfscip-shell system . . printf. "%s " "${subdir}"
203 subdir_path=$(make_absolutescip-shell shell shell-project 0.0.0 make_absolute(). "$subdir")
•204 for i in $(${FIND} "${subdir_path}" -name '*.c' -or -name '*.cc' | LC_ALL=C sortscip-shell system . . sort.); do
205 if [scip-shell system . . `[`. "${with_moduleinfo}" -eq "1" ] ; then
206 MODULEINFO=$(${AWK} -f "${source_tree}/build_tools/get_moduleinfo" "${i}")
207 if [scip-shell system . . `[`. "${MODULEINFO}" != "" ] ; then
208 ${CAT} >> "${output_file}" <<-EOF
209 <module language="en_US" name="$(${BASENAME} "${i}" .c)">
210 ${MODULEINFO}
211 </module>
212 EOF
213 fi
214 fi
215 if [scip-shell system . . `[`. "${for_wiki}" -eq "1" ] ; then
216 ${PYTHON} build_tools/get_documentation.py < "${i}" > "${tmp_output_file}"
217 else
218 ${AWK} -f "${source_tree}/build_tools/get_documentation" "${i}" > "${tmp_output_file}"
219 fi
220 if [scip-shell system . . `[`. "${subdir}" = "main" ] ; then
221 # Force the module to be "builtin" if the source is in the main directory.
222 mn="builtin"
223 else
224 # Otherwise, let's just get the basename of the module.
225 bn=${i##*/}
226 mn=${bn%%.*}
227 fi
228 # Set the module name on specific elements
229 ${SED} -r -e "s/<(manager|managerEvent|managerEventInstance|function|application|info)\s+([^>]+)>/<\1 \2 module=\"${mn}\">/g" "${tmp_output_file}" >> "${output_file}"
230 done
•231 for i in $(${FIND} "${subdir_path}" -name '*.xml' | LC_ALL=C sortscip-shell system . . sort.) ; do
232 ${GREP} -q "appdocsxml.dtd" "${i}" || continue
233 if [scip-shell system . . `[`. "${validate}" -eq "1" ] ;then
234 if [scip-shell system . . `[`. "${XMLLINT}" != ":" ] ; then
235 ${XMLLINT} --dtdvalid "${source_tree}/doc/appdocsxml.dtd" --path "${source_tree}/doc" --noout "${i}" || { echoscip-shell system . . echo. "" ; exit 1 ; }
236 else
237 ${XMLSTARLET} val -q -d "${source_tree}/doc/appdocsxml.dtd" "${i}" ||
238 ${XMLSTARLET} val -e -d "${source_tree}/doc/appdocsxml.dtd" "${i}" || { echoscip-shell system . . echo. "" ; exit 1 ; }
239 fi
240 fi
241 ${SED} -r "/^\s*(<[?]xml|<.DOCTYPE|<.?docs)/d" "${i}" > "${tmp_output_file}"
242 dirname=${i%/*}
243 if [scip-shell system . . `[`. "${dirname}" != "${subdir_path}" ] ; then
244 # If we're in a subdirectory like channels/pjsip, we need to check channels/Makefile
245 # to see which module xml files in this directory belong to.
246 bn=${dirname##*/}
247 mn=$(${SED} -n -r -e "s/^[$]\(call MOD_ADD_C,([^,]+),[$]\(wildcard\s+${bn}\/.*/\1/gp" "${subdir_path}/Makefile")
248 else
249 if [scip-shell system . . `[`. "${subdir}" = "main" ] ; then
250 # Force the module to be "builtin" if the XML is in the main directory.
251 mn="builtin"
252 else
253 # Otherwise the xml should have be "<module>_doc.xml" suffix so
254 # get the basename then strip the suffix.
255 bn=${i##*/}
256 mn=${bn%%_doc.xml}
257 fi
258 fi
259 # Set the module name on specific elements
260 ${SED} -r -e "s/<(manager|managerEvent|managerEventInstance|function|application|info)\s+([^>]+)>/<\1 \2 module=\"${mn}\">/g" "${tmp_output_file}" >> "${output_file}"
261 done
262 done
263
264 echoscip-shell system . . echo. "</docs>" >> "${output_file}"
265 echoscip-shell system . . echo. ""
266 # Some entries may already have a module attribute so remove the dup.
267 # It's easier to do this once on the entire file rather on a source-by-source basis.
268 cpscip-shell system . . cp. "${output_file}" "${tmp_output_file}"
269 ${SED} -r -e 's/module="([^"]+)"\s+module="([^"]+)">/module="\1">/g' "${tmp_output_file}" > "${output_file}"
270
271
272 if [scip-shell system . . `[`. "${for_wiki}" -eq "1" ] ; then
273 ${PYTHON} build_tools/post_process_documentation.py -i "${output_file}" -o "${core_output_file}"
274 fi
275
276 if [scip-shell system . . `[`. "${validate}" -eq "1" ] ;then
277 if [scip-shell system . . `[`. "${XMLLINT}" != ":" ] ; then
278 ${XMLLINT} --dtdvalid "${source_tree}/doc/appdocsxml.dtd" --path "${source_tree}/doc" --noout "${output_file}" || exit 1
279 else
280 ${XMLSTARLET} val -q -d "${source_tree}/doc/appdocsxml.dtd" "${output_file}" ||
281 ${XMLSTARLET} val -e -d "${source_tree}/doc/appdocsxml.dtd" "${output_file}" || { echoscip-shell system . . echo. "" ; exit 1 ; }
282 fi
283 fi
284