File: update-doxygen-doc.sh

package info (click to toggle)
roboptim-core 2.0-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,488 kB
  • ctags: 1,160
  • sloc: cpp: 5,388; sh: 395; ansic: 387; makefile: 25; python: 19
file content (315 lines) | stat: -rwxr-xr-x 8,526 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/bin/sh
# Copyright (C) 2010 Thomas Moulard, JRL, CNRS/AIST.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

 # ------ #
 # README #
 # ------ #

# This script updates the Doxygen documentation on Github.
#
# - it checkouts locally the gh-pages of the current repository,
# - it copy the local Doxygen documentation,
# - it creates a commit and push the modification.
#
# This scripts makes several assumptions on the project structure:
# 1. It should be launched from the documentation build directory
#    I.e. _build/doc
#
# 2. The documentation is generated in the doxygen-html directory
#    of the doc build directory.
#
# 3. The documentation is updated through `make doc` in the top build
#    directory.
#
# If doxygen.cmake is used, 2 and 3 will be respected.
#

# Override the locale.
LC_ALL='C'
export LC_ALL

me=$0
bme=`basename "$0"`


 # ----------------------- #
 # Cross-links management. #
 # ----------------------- #
#
# This stores the doxygen /online/ documentation
# so that installdox can be called to fix links before upload.
#
# Please note that this script makes the assumption that the unstable
# documentation should be used for cross-links which is not what we
# want.

# FIXME: find a way to link against the "real" corresponding version.

ia="abstract-robot-dynamics"
ia="$ia jrl-mathtools jrl-mal jrl-dynamics jrl-walkgen"
ia="$ia dynamic-graph dg-middleware"
ia="$ia sot-core sot-dynamic sot-pattern-generator"
ia="$ia sot-openhrp sot-openhrp-scripts"
installdox_args="$ia"

iu="http://laas.github.com/abstract-robot-dynamics/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/jrl-mathtools/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/jrl-mal/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/jrl-dynamics/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/jrl-walkgen/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/dynamic-graph/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/dg-middleware/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/sot-core/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/sot-dynamic/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/sot-pattern-generator/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/sot-openhrp/doxygen/HEAD/"
iu="$iu http://jrl-umi3218.github.com/sot-openhrp-scripts/doxygen/HEAD/"
installdox_urls="$iu"

  # ----------------------- #
  # Customizable variables. #
  # ----------------------- #

: ${GIT=/usr/bin/git}

  # ---------------- #
  # Helper functions #
  # ---------------- #

set_colors()
{
  red='';    lred=''
  green='';  lgreen=''
  yellow=''; lyellow=''
  blue='';   lblue=''
  purple=''; lpurple=''
  cyan='';   lcyan=''
  grey='';   lgrey=''
  white='';  lwhite=''
  std=''
}

set_nocolors()
{
  red=;    lred=
  green=;  lgreen=
  yellow=; lyellow=
  blue=;   lblue=
  purple=; lpurple=
  cyan=;   lcyan=
  grey=;   lgrey=
  white=;  lwhite=
  std=
}

# abort err-msg
abort()
{
  echo "update-doxygen-doc.sh: ${lred}abort${std}: $@" \
  | sed '1!s/^[ 	]*/             /' >&2
  exit 1
}

# warn msg
warn()
{
  echo "update-doxygen-doc.sh: ${lred}warning${std}: $@" \
  | sed '1!s/^[ 	]*/             /' >&2
}

# notice msg
notice()
{
  echo "update-doxygen-doc.sh: ${lyellow}notice${std}: $@" \
  | sed '1!s/^[ 	]*/              /' >&2
}

# yesno question
yesno()
{
  printf "$@ [y/N] "
  read answer || return 1
  case $answer in
    y* | Y*) return 0;;
    *)       return 1;;
  esac
  return 42 # should never happen...
}


  # -------------------- #
  # Actions definitions. #
  # -------------------- #

version()
{
    echo 'update-doxygen-doc.sh - provided by @PROJECT_NAME@ @PROJECT_VERSION@
Copyright (C) 2010 JRL, CNRS/AIST.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.'
}

help()
{
    echo 'Usage: update-doxygen-doc.sh [action]
Actions:
  --help, -h		      Print this message and exit.
  --version, -v		      Print the script version and exit.
  --doc-version VERSION       Update the documentation of a stable
                              release to github.
                              VERSION by default is HEAD but can be
                              changed to vX.Y.Z to update the documentation
                              of a released version.
'

Report bugs to http://github.com/jrl-umi3218/jrl-cmakemodules/issues
For more information, see http://github.com/jrl-umi3218/jrl-cmakemodules
}

  # ------------------- #
  # `main' starts here. #
  # ------------------- #

# Define colors if stdout is a tty.
if test -t 1; then
  set_colors
else # stdout isn't a tty => don't print colors.
  set_nocolors
fi

# For dev's:
test "x$1" = x--debug && shift && set -x

doc_version=HEAD

remote_url=`${GIT} config remote.origin.url`

case $1 in
    version | v | --version | -version)
	shift
	version
	;;
    help | h | --help | -help)
	shift
	help
	;;
    --doc-version)
	doc_version=$2
	shift; shift
	;;
    --remote-url)
	remote_url=$2
	;;
    '')
	;;
    *)
	echo "update-doxygen-doc.sh: ${lred}invalid option${std}: $1"
	shift
	help
	exit 1
	;;
esac


# Main starts here...
echo "* Checkout ${doc_version}..."
${GIT} checkout --quiet $doc_version

echo "* Generating the documentation..."
(cd .. && make doc) 2> /dev/null > /dev/null || \
 abort "failed to generate the documentation"

echo "* Creating the temporary directory..."
tmp=`mktemp -d` || abort "cannot create the temporary directory"
trap "rm -rf -- '$tmp'" EXIT


build_docdir=`pwd`

head_commit=`${GIT} log --format=oneline HEAD^.. | cut -d' ' -f1`


echo "Remote url:" $remote_url


echo "* Clone the project..."
cd $tmp
${GIT} clone --quiet --depth 1 $remote_url project \
 || abort "failed to clone the package repository"
cd project \
 || abort "failed to change directory"

echo "* Checkout the github web pages..."
${GIT} checkout --quiet -b gh-pages origin/gh-pages \
 || abort "failed to checkout gh-pages (does the branch exist?)"

echo "* Copy the documentation..."
git rm --quiet -rf doxygen/$doc_version
mkdir -p doxygen/$doc_version
cp -rf $build_docdir/doxygen-html/* doxygen/$doc_version/ \
 || abort "failed to copy the documentation"

if test -x "$tmp/project/doxygen/$doc_version/installdox"; then
    echo "* Run installdox to fix documentation cross-links..."

    cd $tmp/project/doxygen/$doc_version/ || abort "Failed to change directory."

    # Patch installdox to never abort.
    # installdox normally checks that _all_ links are substituted.
    # This is not what we want, we call installdox one dependency at a time
    # to avoid resolving documentation dependencies manually.
    sed 's|&usage();||g' installdox > installdox.fixed
    chmod 755 installdox.fixed

    i=1
    for doxytag in $installdox_args; do
	url=`echo "$installdox_urls" | cut -d' ' -f$i`
	./installdox.fixed -q -l ${doxytag}.doxytag@$url \
	    2> /dev/null > /dev/null \
	    || true
	i=$((i+1))
    done
    cd $tmp/project || abort "Failed to change directory."
fi

echo "* Generate the commit..."
${GIT} add doxygen/$doc_version \
 || abort "failed to add the updated documentation to the git index"

echo "Update $doc_version Doxygen documentation.
Source commit id: $head_commit" >> $tmp/commit_msg
commit_status=`${GIT} status -s`

# Make sure that there is something to commit.
# If this is not the case, the documentation is already
# up-to-date and the commit should not be generated.
if test -n "$commit_status"; then
  ${GIT} commit --quiet -F $tmp/commit_msg \
   || abort "failed to generate the git commit"

  echo "* Push the generated commit..."
  ${GIT} push origin gh-pages

  echo "${lgreen}Documentation updated with success!${std}"
else
    notice "Github pages documentation is already up-to-date."
fi

# Clean up the tmp directory
rm -rf $tmp

trap - EXIT