OPAM-DOC with multiple OCaml packages
OPAM-DOC
The tool ocamldoc
shipped with the standard distribution of the
OCaml compiler suffers from some limitations because it doesn't have
access to all the information it needs. Notably, if you want to build
the documentation of some package a
that depends on some package
b
, you'll find out that the documentation of the package a
will
not automatically refer to the documentation of the package b
.
Well, opamdoc solves this problem and it's very nice.
On this site, which is work in progress, you can find a list of packages with their descriptions. This list is built using opam2web. And each package description links to its documentation. And the documentation for all packages is built as a whole, which means that if the documentation of a package links to all other packages on which it depends. Isn't it nice? :)
Install and run opamdoc
opamdoc is still under active development, the current step is finding and fixing remaining issues and packaging.
If you want to use opamdoc now, here's some instructions based on Anil's instructions, which are those:
opam remote add opamdoc git://github.com/avsm/opamdoc-dev opam switch 4.01.0beta1+opamdoc eval `opam config env` opam install opamdoc opamdoc-rebuild opamdoc-generate open ~/.opam/4.01.0beta1+opamdoc/opamhtml/index.html
opamdoc-rebuild
builds a database of cmt/cmd files in~/.opam/4.01.0beta1+opamdoc/opamdoc
.opamdoc-generate
builds a package HTML list in~/.opam/4.01.0beta+opamdoc/opamhtml
.
Well, they work quite well, except opamdoc-rebuild
uses .cmd
files as a base, whereas
it should use .cmt
files instead because sometimes .cmt
files exist while .cmd
don't.
This is a problem for a few packages (Core
is one of them).
My advice: if something doesn't work as expect,
please open an issue,
and if you want to customize the way the documentation is built,
don't hesitate to edit opamdoc-rebuild
and/or opamdoc-generate
(they are Bash scripts).
A few notes about those instructions
The first line, which is opam remote add opamdoc git://github.com/avsm/opamdoc-dev
,
will give sense to the second one, which is opam switch 4.01.0beta1+opamdoc
.
And 4.01.0beta1+opamdoc
is a customised compiler that produces on the side the .cm{t,d}{,i}
files
that are used by opamdoc. Using it is very convenient! If you don't use it, you need to produce
those files in an other way of your choice (really? you want to go through such trouble?).
Note that opamdoc is written in such a way that it would ask a lot of work to make it work with versions of the compiler prior to 4.01.0 because it uses features introduced by this very version.
Just in case, here follow the customised version of opamdoc-rebuild
and opamdoc-generate
that
I used to build the documentation available on http://ocaml-redesign.github.io/pkg/docs/.
opamdoc-rebuild
Here's my customised version of opamdoc-rebuild
:
#!/usr/bin/env bash
# Rebuild the cmd/cmt archive in ~/.opam/<switch>/opamdoc
# Copies all the cmt/cmti/cmd files found in the OPAM build
# dir into a single directory structure, separated by MD5
# to keep files distinct.
set -e
#dry=echo
SWITCH=$(opam switch show)
if [ "${SWITCH}" = "system" ]; then
echo Must be using a custom OPAM switch for this to work.
exit 1
fi
function calc_md5_for_file()
{
if builtin command -v md5 > /dev/null; then
md5=$(cat $1 | md5)
elif builtin command -v md5sum > /dev/null ; then
md5=$(cat $1 | md5sum | awk '{print $1}')
else
echo "Neither md5 nor md5sum were found in the PATH"
exit 1
fi
}
BASE="$(dirname $(dirname $(ocamlc -where)))"
BUILD=${BASE}/build
DOC=${BASE}/opamdoc
rm -rf ${DOC}
mkdir -p ${DOC}
PKGS=$(find ${BUILD}/ -mindepth 1 -maxdepth 1 -type d "$@")
echo ${PKGS}
for pkg in ${PKGS}; do
pkgname=$(basename $pkg)
echo $pkgname
mkdir -p ${DOC}/$pkgname
CMTS=$(find ${pkg} -type f -name '*.cmt')
for cmt in ${CMTS}; do
d=$(dirname $cmt)
calc_md5_for_file "$cmt";
f=$(basename $cmt .cmt)
mkdir -p ${DOC}/$pkgname/$md5
r=${DOC}/$pkgname/$md5/$f
for ext in cmt cmti cmd cmdi cmi ; do
if [ -e $d/$f.$ext ]; then
$dry cp $d/$f.$ext $r.$ext
fi
done
done
done
opamdoc-generate
Here's my customised version of opamdoc-generate
.
#!/usr/bin/env bash
# Rebuild the cmd/cmt archive in ~/.opam/<switch>/opamdoc
# Copies all the cmt/cmti/cmd files found in the OPAM build
# dir into a single directory structure, separated by MD5
# to keep files distinct.
set -e
#dry=echo
SWITCH=$(opam switch show)
if [ "${SWITCH}" = "system" ]; then
echo Must be using a custom OPAM switch for this to work.
exit 1
fi
OPAMDOC=${OPAMDOC:-opamdoc}
BASE="$(dirname $(dirname $(ocamlc -where)))"
BUILD=${BASE}/build
DOC=${BASE}/opamdoc
HTML=${BASE}/opamhtml
rm -rf ${HTML}
mkdir -p ${HTML}
# Grab the build dir in reverse mtime order to get the
# ordering of generation "correct".
PKGS=$(ls -1tr $BUILD)
rm -rf $HTML
mkdir -p $HTML
cd $HTML
for pkg in ${PKGS}; do
fs="$(find $DOC/$pkg -type f)"
if [ "$fs" != "" ]; then
name=$(echo $pkg | awk -F. '{print $1}')
echo $pkg $name
$dry $OPAMDOC -p $name $fs
fi
done
Enjoy.
started on 2013-09-24 01:50:14+01:00, (re)generated on 2014-01-15 15:14:11+00:00