37
37
# errors.
38
38
# --debug
39
39
# Run `make` with the --debug option.
40
+ # --default-version=VERSION
41
+ # By default the current version is symlinked as the default version,
42
+ # provide an alternative version to override this.
40
43
#
41
44
# BUILD
42
45
# The format(s) to build the documentation in - default html.
51
54
# `latexpdf`
52
55
# For building PDF documentation.
53
56
# `clean`
54
- # Removes all builds (rose make-docs clean <build> will force a
55
- # complete re-build ).
57
+ # Removes all built documentation for the current rose version.
58
+ # (use `rm -rf doc` to remove all documentation ).
56
59
#
57
60
# DEVELOPMENT BUILDS
58
61
# For development purposes use the following BUILDs:
65
68
# -----------------------------------------------------------------------------
66
69
set -e
67
70
set -o pipefail
71
+ shopt -s extglob
68
72
69
73
# Move into rose directory
70
- cd " $( dirname $0 ) /../"
74
+ cd " $( dirname " $0 " ) /../"
71
75
72
- VENV_PATH=' venv' # Path for virtualenv.
73
- USING_VENV=false # Set to `true` when the virtualenv is being used.
74
- SPHINX_PATH=sphinx # Path to the sphinx directory.
75
-
76
- venv-activate () {
77
- USING_VENV=true
78
- . " ${VENV_PATH} /bin/activate"
79
- }
80
-
81
- venv-install () {
82
- venv-destroy
83
- virtualenv --python=python2.7 " ${VENV_PATH} "
84
- venv-activate
85
- pip install sphinx
86
- pip install sphinx_rtd_theme
87
- pip install sphinxcontrib-httpdomain
88
- pip install hieroglyph
89
- }
90
-
91
- venv-deactivate () {
92
- deactivate > /dev/null 2>&1 || true
93
- }
94
-
95
- venv-destroy () {
96
- venv-deactivate
97
- rm -rf " ${VENV_PATH} "
98
- }
76
+ # Path for virtualenv.
77
+ VENV_PATH=' venv'
78
+ # Set to `true` when the virtualenv is being used.
79
+ USING_VENV=false
80
+ # Path to the sphinx directory.
81
+ SPHINX_PATH=sphinx
82
+ # pick up official rose version
83
+ . " ${ROSE_HOME} /rose-version"
84
+ # documentation root output directory
85
+ DOCS_DIR=" ${ROSE_HOME} /doc"
86
+ # documentation output directory for this version
87
+ BUILD_DIR=" ${DOCS_DIR} /${ROSE_VERSION} "
88
+ # glob for documented rose versions
89
+ DOC_VERSIONS=! (* .html| .git| doc| versions.json| " ${DEFAULT_ALIAS} " )
90
+ # glob for documentation formats within a rose version
91
+ DOC_FORMATS=! (* .html| doctrees)
99
92
93
+ # is the virtualenv command available
100
94
if which virtualenv > /dev/null 2>&1 ; then
101
95
VENV_COMPLIANT=true
102
96
else
@@ -109,7 +103,9 @@ FORCE=false
109
103
DEV_MODE=false
110
104
DEBUG=' '
111
105
BUILDS=' '
112
- SPHINXOPTS=' '
106
+ SPHINX_OPTS=' '
107
+ DEFAULT_ALIAS=' doc'
108
+ DEFAULT_VERSION=
113
109
while [[ $# -gt 0 ]]; do
114
110
case $1 in
115
111
--venv)
@@ -125,13 +121,18 @@ while [[ $# -gt 0 ]]; do
125
121
shift
126
122
;;
127
123
--strict)
128
- SPHINXOPTS= ' SPHINXOPTS =-aEW'
124
+ SPHINX_OPTS= ' SPHINX_OPTS =-aEW'
129
125
shift
130
126
;;
131
127
--debug)
132
128
DEBUG=' --debug'
133
129
shift
134
130
;;
131
+ --default-version)
132
+ DEFAULT_VERSION=" $2 "
133
+ shift
134
+ shift
135
+ ;;
135
136
* )
136
137
BUILDS=" ${BUILDS} $1 "
137
138
shift
@@ -142,6 +143,79 @@ if [[ -z "${BUILDS}" ]]; then
142
143
BUILDS=' html'
143
144
fi
144
145
146
+
147
+ venv-activate () {
148
+ USING_VENV=true
149
+ . " ${VENV_PATH} /bin/activate"
150
+ }
151
+
152
+ venv-install () {
153
+ venv-destroy
154
+ virtualenv --python=python2.7 " ${VENV_PATH} "
155
+ venv-activate
156
+ pip install sphinx
157
+ pip install sphinx_rtd_theme
158
+ pip install sphinxcontrib-httpdomain
159
+ pip install hieroglyph
160
+ }
161
+
162
+ venv-deactivate () {
163
+ deactivate > /dev/null 2>&1 || true
164
+ }
165
+
166
+ venv-destroy () {
167
+ venv-deactivate
168
+ rm -rf " ${VENV_PATH} "
169
+ }
170
+
171
+ json_list () {
172
+ # write out a bash array as a JSON list
173
+ echo -n " [\" $( local IFS=' ,' ; echo " $* " | sed ' s/,/", "/g' ; ) \" ]"
174
+ }
175
+
176
+ version_file () {
177
+ # output the dictionary {"version": ["build", ...]} in JSON format
178
+ DOCS_DIR=" $1 "
179
+ DEFAULT_ALIAS=" $2 "
180
+
181
+ echo ' {'
182
+ # scrape filesystem for list of rose versions which have built docs
183
+ VERSIONS=( $( cd " ${DOCS_DIR} " ; echo $DOC_VERSIONS ) )
184
+ for version in " ${VERSIONS[@]} " ; do
185
+ # scrape filesystem to get list of formats this version is available in
186
+ formats=( $( cd " ${DOCS_DIR} /${version} " ; echo $DOC_FORMATS ) )
187
+ list=" \" ${version} \" : $( json_list ${formats} ) "
188
+ if [[ $version == " ${VERSIONS[$(( ${#VERSIONS[@]} - 1 ))]}" ]]; then
189
+ # JSON doesn't permit a comma after the last item in a collection
190
+ echo " ${list} "
191
+ else
192
+ echo " ${list} ,"
193
+ fi
194
+ done
195
+ echo ' }'
196
+ }
197
+
198
+ html_redirect () {
199
+ # write an html file to $2 which auto-redirects to the relative path $1
200
+ SRC=" $1 "
201
+ DEST=" $2 "
202
+
203
+ cat > " $2 " << __HTML__
204
+ <!DOCTYPE html>
205
+ <html>
206
+ <head>
207
+ <title>Rose Documentation</title>
208
+ <meta http-equiv="REFRESH" content="0;url=$1 ">
209
+ </head>
210
+ <body>
211
+ <p>If not automatically redirected, please click
212
+ <a href="$1 ">Rose Documentation</a>.</p>
213
+ </body>
214
+ </html>
215
+ __HTML__
216
+ }
217
+
218
+
145
219
# Use virtualenv if present and requested or if we are in development mode.
146
220
if " ${DEV_MODE} " || " ${VENV_MODE} " ; then
147
221
if ! " ${VENV_COMPLIANT} " ; then
@@ -174,7 +248,7 @@ if ! rose-check-software --doc >/dev/null; then
174
248
175
249
echo
176
250
echo ' The documentation can still be built by installing dependencies'
177
- echo ' in a python virtual enironment (virtualenv). This environment'
251
+ echo ' in a python virtual environment (virtualenv). This environment'
178
252
echo " will be created in rose/${VENV_PATH} and will be removed after"
179
253
echo ' use. To keep the virtualenv for future builds run this command'
180
254
echo ' with the "--dev" option.'
@@ -198,9 +272,25 @@ if ! rose-check-software --doc >/dev/null; then
198
272
fi
199
273
fi
200
274
201
- # Run sphinx make.
202
- if make ${DEBUG} -C " ${SPHINX_PATH} " ${BUILDS} ${SPHINXOPTS} ; then
275
+ # makefile argument to set the output directory for this build
276
+ SPHINX_OPTS=" ${SPHINX_OPTS} BUILDDIR=${DOCS_DIR} /${ROSE_VERSION} "
277
+
278
+ # run sphinx-build
279
+ if make ${DEBUG} -C " ${SPHINX_PATH} " ${BUILDS} ${SPHINX_OPTS} ; then
203
280
RET=0
281
+ # output file containing details of all versions and formats the
282
+ # documentation has been built in (locally) for the version / format
283
+ # switching pane
284
+ version_file " ${DOCS_DIR} " " ${DEFAULT_ALIAS} " > " ${DOCS_DIR} /versions.json"
285
+ # symlink this version as the default
286
+ (
287
+ cd " ${DOCS_DIR} "
288
+ rm " ${DEFAULT_ALIAS} " 2> /dev/null || true
289
+ ln -s " ${DEFAULT_VERSION:- $ROSE_VERSION } " " ${DEFAULT_ALIAS} "
290
+ )
291
+ # symlink landing pages
292
+ html_redirect " ${DEFAULT_ALIAS} /html/index.html" ' doc/index.html'
293
+ html_redirect " html/index.html" " doc/${ROSE_VERSION} /index.html"
204
294
else
205
295
RET=1
206
296
fi
0 commit comments