Debian Codegraph @

doc/pasdoc/mk_docs.sh

raw symbols SCIP
1 #!/bin/bash
2 set -eu
3
4 # Use pipefail to fail if the "pasdoc"
5 # command in "pasdoc ... | grep ..." pipe fails.
6 # See http://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another
7 set -o pipefail
8
9 # Generates docs for all units in castle_game_engine/src.
10 # $1 is format (allowed values as for pasdoc's --format option),
11 # docs will be placed in subdirectory $1 of current dir
12 # so $1 means also subdirectory name.
13 #
14 # If you will not supply argument $2,
15 # then documentation for almost every unit in castle_game_engine/src
16 # (without automatically generated fonts units
17 # and without units that pasdoc can't correctly parse)
18 # will be generated.
19 #
20 # Else documentation for units $2...${$#} (all these arguments
21 # should be filenames of units relative to $CASTLE_ENGINE_UNITS_PATH
22 # directory) will be generated.
23 # E.g.: ./mk_docs.sh html audio/alutils.pas
24 # This is useful for quickly checking generated documentation
25 # for some particular unit, because generating documentation
26 # for all units takes a while.
27
28 # "os-native path" in this file means "under Windows it must
29 # *not* be Cygwin/MinGW/MSys/Git-for-Windows POSIX path,
30 # because I pass it to pasdoc as filename".
31
32 # TARGET_OS is windows lub unix.
33 # This says which subdirectories of sources are meaningfull
34 # (e.g. add base/unix/ or base/windows/ to include file path ?).
35 # Moreover pasdoc will be run with --define $TARGET_OS.
36 TARGET_OS=unix
37
38 CASTLE_ENGINE_UNITS_PATH=../../src/
39
40 # Autodetect if we're under Cygwin/MinGW/MSys/Git-for-Windows --
41 # so paths from Unix tools (like pwd) need conversion to Windows-native.
42 #if uname | grep --quiet -i cygwin; then # not good, does not detect MinGW/MSys
43 if which cygpath > /dev/null; then
44 CYGWIN_OR_SIMILAR='t'
45 else
46 CYGWIN_OR_SIMILAR=''
47 fi
48
49 PASDOC_FORMAT="$1"
50 shift 1
51
52 # calculate OUTPUT_PATH (os-native path)
53 OUTPUT_PATH=`pwd`/
54 if [ -n "$CYGWIN_OR_SIMILAR" ]; then
55 OUTPUT_PATH="`cygpath --windows \"$OUTPUT_PATH\"`"
56 fi
57
58 FIND='find'
59 if [ -n "$CYGWIN_OR_SIMILAR" ]; then
60 FIND='/bin/find' # On Cygwin, make sure to use Cygwin's find, not the one from Windows
61 fi
62
63 # calculate PASDOC_CACHE (os-native path)
64 # I use --cache-dir with pasdoc, as this greatly speeds up generation
65 # of these docs.
66 #
67 # (However, this presents possibe threat, because cache timestamp is based
68 # on unit source file timestamp. So when some unit myunit.pas will include
69 # myinclude.inc then cache will NOT be updated when myinclude.inc file
70 # changes. So I'll have to remember to call `make clean-cache' here before
71 # regenerating docs.)
72 PASDOC_CACHE="${OUTPUT_PATH}cache/"
73 mkdir -p "$PASDOC_CACHE"
74
75 # finish calculating OUTPUT_PATH
76 OUTPUT_PATH="$OUTPUT_PATH""$PASDOC_FORMAT"/
77 mkdir -p "$OUTPUT_PATH"
78
79 cd "$CASTLE_ENGINE_UNITS_PATH"
80
81 # calculate TMP_PAS_LIST (os-native path)
82 TMP_PAS_LIST=/tmp/mk_docs_list
83 if [ -n "$CYGWIN_OR_SIMILAR" ]; then
84 TMP_PAS_LIST="`cygpath --windows \"$TMP_PAS_LIST\"`"
85 fi
86
87 # make sure we have clean way to create "$TMP_PAS_LIST"
88 rm -f "$TMP_PAS_LIST"
89
90 # Now generate $TMP_PAS_LIST contents -- those are units we want to
91 # be documented by pasdoc.
92
93 if (( $# == 0 )); then
94 # We don't generate docs for
95 #
96 # - Automatically generated units (fonts).
97 #
98 # - Internal units.
99 # All the non-internal units should have nice PasDoc documentation.
100 #
101 # Internal units sometimes have internal API, sometimes they even
102 # describe an "external API", not interesting to CGE developers,
103 # like castleinternalpk3dconnexion.pas and castleinternaltdxinput_tlb.pas.
104 #
105 # There are two units that are "somewhat internal":
106 # glext.pas, castlegles.pas. We want them to be treated as internal
107 # for most games. But sometimes users can also use them directly,
108 # to do some advanced tricks (direct OpenGL / OpenGLES rendering,
109 # mixed with CGE rendering).
110 # In any case, their docs are not ready for PasDoc (and never will be
111 # --- this is OpenGL and OpenGL ES API).
112 #
113 # Exception: we still generate docs for castlevectorsinternal*.pas.
114 # Although these units are not supposed to be used directly,
115 # but they document API of TVector3 and TVector3Double.
116
117 "${FIND}" . \
118 '(' -type f -iname '*.pas' \
119 -not '(' \
120 '(' -iwholename '*/base/android/*.pas' ')' -or \
121 '(' -iwholename '*/castlelib_dynloader.pas' ')' -or \
122 '(' -iwholename '*/castlegles.pas' ')' -or \
123 '(' -iname 'x3dloadinternal*.pas' ')' -or \
124 '(' -iname 'castleinternal*.pas' ')' -or \
125 '(' -iname 'fmx.castleinternal*.pas' ')' -or \
126 '(' -iname 'castleshapeinternal*.pas' ')' -or \
127 '(' -iname 'kraft.pas' ')' -or \
128 '(' -iname 'dglopengl*.pas' ')' -or \
129 '(' -iname 'castlegl.pas' ')' -or \
130 '(' -iwholename '*/compatibility/*' ')' -or \
131 '(' -iwholename '*/deprecated_units/*' ')' -or \
132 '(' -iwholename '*/pasgltf/*' ')' -or \
133 '(' -iwholename '*/vampyre_imaginglib/*' ')' -or \
134 '(' -iwholename '*/x3d/nodes_specification/*' ')' -or \
135 '(' -iwholename '*fonts/castletexturefont_*.pas' ')' \
136 ')' \
137 -print ')' >> "$TMP_PAS_LIST"
138 else
139 # Put all "$@" arguments in file "$TMP_PAS_LIST",
140 # separated by newlines
141 for FFF; do
142 echo "$FFF" >> "$TMP_PAS_LIST"
143 done
144 fi
145
146 PASDOC_INCLUDE_DIRS="\
147 --include common_includes/\
148 --include transform/\
149 --include scene/\
150 --include scene/load/\
151 --include scene/load/spine/\
152 --include scene/load/md3/\
153 --include scene/load/collada/\
154 --include scene/x3d/\
155 --include audio/\
156 --include base/\
157 --include base/$TARGET_OS/\
158 --include base_rendering/\
159 --include fonts/
160 --include fonts/$TARGET_OS/\
161 --include images/\
162 --include window/\
163 --include window/$TARGET_OS/\
164 --include window/gtk/
165 "
166
167 if [ "${PASDOC_FORMAT}" = 'html' ]; then
168 FORMAT_OPTIONS='--use-tipue-search'
169 else
170 FORMAT_OPTIONS=''
171 fi
172
173 # Run pasdoc.
174 #
175 # Filter result through grep.
176 # Thanks to "set -o pipefail" defined above, failure of "pasdoc"
177 # will still cause the entire script to fail.
178 #
179 # We filter out some known pasdoc bugs/missing features:
180 # - lack of @groupbegin/groupend implementation for now,
181 # - reporting as missing links the exceptions from standard units.
182
183 pasdoc \
184 --format "$PASDOC_FORMAT" \
185 $PASDOC_INCLUDE_DIRS \
186 --output "$OUTPUT_PATH" \
187 --define "$TARGET_OS" \
188 --define FPC --define VER3 --define VER3_0 --define VER3_2_0 --define PASDOC \
189 --write-uses-list \
190 --title "Castle Game Engine" \
191 --source "$TMP_PAS_LIST" \
192 --cache-dir "$PASDOC_CACHE" \
193 --auto-abstract \
194 --introduction=../doc/pasdoc/introduction.pasdoc \
195 --auto-link \
196 --auto-link-exclude=../doc/pasdoc/auto_link_exclude.txt \
197 --external-class-hierarchy=../doc/pasdoc/external_class_hierarchy.txt \
198 --visible-members public,published,automated,protected \
199 --html-head ../doc/pasdoc/html-parts/head.html \
200 --html-body-begin ../doc/pasdoc/html-parts/body-begin.html \
201 --html-body-end ../doc/pasdoc/html-parts/body-end.html \
202 --css ../doc/pasdoc/html-parts/cge-pasdoc.css \
203 $FORMAT_OPTIONS
204
205 # TODO: Commented out grep filtering -- fails with "Disk Full" on GH Actions,
206 # seems some problem with pipes.
207 #
208 # \
209 # | \
210 # grep --ignore-case --invert-match --fixed-strings \
211 # --regexp='Tag "groupbegin" is not implemented yet, ignoring' \
212 # --regexp='Tag "groupend" is not implemented yet, ignoring' \
213 # --regexp='Could not resolve link "EConvertError"' \
214 # --regexp='Could not resolve link "EReadError"' \
215 # --regexp='Could not resolve link "Exception"' \
216 # --regexp='Could not resolve link "EOSError"' \
217 # --regexp='Could not resolve link "EInvalidArgument"' \
218 # --regexp='Could not resolve link "EFOpenError"' \
219 # --regexp='Could not resolve link "EStreamError"'
220
221 # Not anymore:
222 # We hide protected members, for now. Makes a cleaner documentation,
223 # more useful for engine users, not interested in engine internals.
224
225 # \
226 # --graphviz-classes --link-gv-classes jpg \
227 # --graphviz-uses --link-gv-uses jpg
228
229 # Useful to find new items for auto_link_exclude.txt:
230 # grep for "Automatically linked identifier", remove duplicates,
231 # and see which ones shouldn't be autolinked.
232 # --verbosity=3
233
234 # Classes graph is too large, dot answers with
235 # dot: width (135399 >= 32768) is too large.
236 # and then segfaults.
237 #dot -Tjpg -o"$OUTPUT_PATH"GVClasses.jpg "$OUTPUT_PATH"GVClasses.dot
238
239 # Units graph is possible, but still very large for human eye
240 # and so practically useless for us now...
241 #dot -Tjpg -o"$OUTPUT_PATH"GVUses.jpg "$OUTPUT_PATH"GVUses.dot
242
243 # clean after ourselves
244 rm -f "$TMP_PAS_LIST"