1#!/bin/bash
2#
3# Runs doxygen and stores its results in the skia-autogen repo, so that they
4# can be browsed at http://skia-autogen.googlecode.com/svn/docs/html/index.html
5#
6# The DOXYGEN_TEMPDIR env variable is the working directory within which we will
7# check out the code, generate documentation, and store the doxygen log
8# (by default, /tmp/skia-doxygen). The DOXYGEN_COMMIT env variable determines
9# whether docs should be commited (true by default).
10#
11# Sample Usage:
12#  export DOXYGEN_TEMPDIR=/tmp/doxygen
13#  export DOXYGEN_COMMIT=false
14#  bash update-doxygen.sh
15
16function check_out_docs {
17  svn checkout https://skia-autogen.googlecode.com/svn/docs  # writeable
18  ret_code=$?
19  if [ $ret_code != 0 ]; then
20    # docs directory does not exist, skia-autogen must have been reset.
21    # Create a non svn docs directory instead.
22    mkdir docs
23  fi
24}
25
26# Prepare a temporary dir and check out Skia trunk and docs.
27cd
28DOXYGEN_TEMPDIR=${DOXYGEN_TEMPDIR:-/tmp/skia-doxygen}
29DOXYGEN_COMMIT=${DOXYGEN_COMMIT:-true}
30
31mkdir -p $DOXYGEN_TEMPDIR
32cd $DOXYGEN_TEMPDIR
33
34if [ -d "trunk" ]; then
35  svn update --accept theirs-full trunk
36else
37  svn checkout http://skia.googlecode.com/svn/trunk  # read-only
38fi
39if [ -d "docs" ]; then
40  svn update --accept theirs-full docs
41  svn info docs
42  ret_code=$?
43  if [ $ret_code != 0 ]; then
44    # This is not a valid SVN checkout.
45    rm -rf docs
46    check_out_docs
47  fi
48else
49  check_out_docs
50fi
51
52if [ ! -f "docs/static_footer.txt" ]; then
53  cp trunk/tools/doxygen_footer.txt docs/static_footer.txt
54fi
55
56# Run Doxygen.
57cd trunk
58doxygen Doxyfile
59ret_code=$?
60if [ $ret_code != 0 ]; then
61  echo "Error while executing Doxygen command"
62  exit $ret_code
63fi
64
65cd ../docs
66
67# Add any newly created files to Subversion.
68NEWFILES=$(svn status | grep ^\? | awk '{print $2}')
69if [ -n "$NEWFILES" ]; then
70  svn add $NEWFILES
71fi
72
73# We haven't updated the timestamp footer yet... if there are no changes
74# yet, just exit. (We'll wait until there are any actual doc changes before
75# updating the timestamp and committing changes to the repository.)
76MODFILES=$(svn status | grep ^[AM])
77if [ -z "$MODFILES" ]; then
78  echo "No documentation updates, exiting early."
79  exit 0
80fi
81
82# Update the timestamp footer.
83cat >iframe_footer.html <<EOF
84<html><body>
85<address style="text-align: right;"><small>
86Generated on $(date) for skia by
87<a href="http://www.doxygen.org/index.html">doxygen</a>
88$(doxygen --version) </small></address>
89</body></html>
90EOF
91
92# Make sure that all files have the correct mimetype.
93find . -name '*.html' -exec svn propset svn:mime-type text/html '{}' \;
94find . -name '*.css'  -exec svn propset svn:mime-type text/css '{}' \;
95find . -name '*.js'   -exec svn propset svn:mime-type text/javascript '{}' \;
96find . -name '*.gif'  -exec svn propset svn:mime-type image/gif '{}' \;
97find . -name '*.png'  -exec svn propset svn:mime-type image/png '{}' \;
98
99# Output files with documentation updates.
100echo -e "\n\nThe following are the documentation updates:"
101echo $MODFILES
102
103if $DOXYGEN_COMMIT ; then
104  # Commit the updated docs to the subversion repo.
105  svn commit --message 'commit doxygen-generated documentation'
106fi
107