summaryrefslogtreecommitdiffstats
path: root/admin/build-doc
blob: 7a23c7d4b9f11f1bbfefd53490f7550180a99672 (plain)
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
#!/bin/sh

cd "$(dirname "$0")"
cd ..
TOPDIR=`pwd`

install -d -m0755 build-doc

if command -v dpkg >/dev/null; then
    packages=`cat ${TOPDIR}/doc_deps.deb.txt`
    for package in $packages; do
    if [ "$(dpkg --status -- $package 2>&1 | sed -n 's/^Status: //p')" != "install ok installed" ]; then
        # add a space after old values
        missing="${missing:+$missing }$package"
    fi
    done
    if [ -n "$missing" ]; then
        echo "$0: missing required packages, please install them:" 1>&2
        echo "sudo apt-get install -o APT::Install-Recommends=true $missing" 1>&2
        exit 1
    fi
elif command -v yum >/dev/null; then
    python_package="python$(rpm --eval '%{python3_pkgversion}')"
    for package in "$python_package"-devel "$python_package"-pip "$python_package"-virtualenv doxygen ditaa ant libxml2-devel libxslt-devel "$python_package"-Cython graphviz; do
	if ! rpm -q --whatprovides $package >/dev/null ; then
		missing="${missing:+$missing }$package"
	fi
    done
    if [ -n "$missing" ]; then
        echo "$0: missing required packages, please install them:" 1>&2
        echo "yum install $missing"
        exit 1
    fi
else
    for command in virtualenv doxygen ant ditaa cython; do
	command -v "$command" > /dev/null;
	ret_code=$?
	if [ $ret_code -ne 0 ]; then
            # add a space after old values
	    missing="${missing:+$missing }$command"
	fi
    done
    if [ -n "$missing" ]; then
	echo "$0: missing required command, please install them:" 1>&2
	echo "$missing"
	exit 1
    fi
fi

# Don't enable -e until after running all the potentially-erroring checks
# for availability of commands
set -e

cat $TOPDIR/src/osd/PG.h $TOPDIR/src/osd/PG.cc | $TOPDIR/doc/scripts/gen_state_diagram.py > $TOPDIR/doc/dev/peering_graph.generated.dot

cd build-doc

[ -z "$vdir" ] && vdir="$TOPDIR/build-doc/virtualenv"

if [ ! -e $vdir ]; then
    virtualenv --python=python3 --system-site-packages $vdir
fi
$vdir/bin/pip install --quiet -r $TOPDIR/admin/doc-requirements.txt

install -d -m0755 \
    $TOPDIR/build-doc/output/html \
    $TOPDIR/build-doc/output/man

# To avoid having to build librbd to build the Python bindings to build the docs,
# create a dummy librbd.so that allows the module to be imported by sphinx.
# the module are imported by the "automodule::" directive.
mkdir -p $vdir/lib
export LD_LIBRARY_PATH="$vdir/lib"
export PYTHONPATH=$TOPDIR/src/pybind

# FIXME(sileht): I dunno how to pass the include-dirs correctly with pip
# for build_ext step, it should be:
# --global-option=build_ext --global-option="--cython-include-dirs $TOPDIR/src/pybind/rados/"
# but that doesn't work, so copying the file in the rbd module directly, that's ok for docs
for bind in rados rbd cephfs rgw; do
    if [ ${bind} != rados ]; then
        cp -f $TOPDIR/src/pybind/rados/rados.pxd $TOPDIR/src/pybind/${bind}/
    fi
    ln -sf lib${bind}.so.1 $vdir/lib/lib${bind}.so
    gcc -shared -o $vdir/lib/lib${bind}.so.1 -xc /dev/null
    BUILD_DOC=1 \
        CFLAGS="-iquote$TOPDIR/src/include" \
        CPPFLAGS="-iquote$TOPDIR/src/include" \
        LDFLAGS="-L$vdir/lib -Wl,--no-as-needed" \
        $vdir/bin/pip install --upgrade $TOPDIR/src/pybind/${bind}
    # rgwfile_version(), librgw_create(), rgw_mount()
    # since py3.5, distutils adds postfix in between ${bind} and so
    lib_fn=$vdir/lib/python*/*-packages/${bind}.*.so
    if [ ! -e $lib_fn ]; then
       lib_fn=$vdir/lib/python*/*-packages/${bind}.so
    fi
    nm $lib_fn | grep -E "U (lib)?${bind}" | \
        awk '{ print "void "$2"(void) {}" }' | \
        gcc -shared -o $vdir/lib/lib${bind}.so.1 -xc -
    if [ ${bind} != rados ]; then
        rm -f $TOPDIR/src/pybind/${bind}/rados.pxd
    fi
done

if [ -z "$@" ]; then
    sphinx_targets="html man"
else
    sphinx_targets=$@
fi
for target in $sphinx_targets; do
    builder=$target
    case $target in
        html)
            builder=dirhtml
            extra_opt="-D graphviz_output_format=svg"
            ;;
        man)
            extra_opt="-t man"
            ;;
    esac
    # Build with -W so that warnings are treated as errors and this fails
    $vdir/bin/sphinx-build -W -a -b $builder $extra_opt -d doctrees \
                           $TOPDIR/doc $TOPDIR/build-doc/output/$target


done

# build the releases.json. this reads in the yaml version and dumps
# out the json representation of the same file. the resulting releases.json
# should be served from the root of hosted site.
$vdir/bin/python << EOF > $TOPDIR/build-doc/output/html/releases.json
from __future__ import print_function
import datetime
import json
import yaml

def json_serialize(obj):
    if isinstance(obj, datetime.date):
        return obj.isoformat()

with open("$TOPDIR/doc/releases/releases.yml", 'r') as fp:
    releases = yaml.load(fp)
    print(json.dumps(releases, indent=2, default=json_serialize))
EOF

#
# Build and install JavaDocs
#
JAVADIR=$TOPDIR/src/java

# Clean and build JavaDocs
rm -rf $JAVADIR/doc
ant -buildfile $JAVADIR/build.xml docs

# Create clean target directory
JAVA_OUTDIR=$TOPDIR/build-doc/output/html/api/libcephfs-java/javadoc
rm -rf $JAVA_OUTDIR
mkdir $JAVA_OUTDIR

# Copy JavaDocs to target directory
cp -a $JAVADIR/doc/* $JAVA_OUTDIR/