Skip to content

Instantly share code, notes, and snippets.

@yiding
Created July 11, 2014 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yiding/6c2fdb058da69c7ad0ea to your computer and use it in GitHub Desktop.
Save yiding/6c2fdb058da69c7ad0ea to your computer and use it in GitHub Desktop.
Generate local hoogle instance based on installed packages, uses ninja to build
#!/bin/bash
cd $(dirname $0)
OUTDIR=_out
mkdir -p $OUTDIR
OUTNINJA=$OUTDIR/build.ninja
cat << EOF > $OUTNINJA
rule ln
command = ln -s \$in \$out
rule hoo
command = hoogle convert \$in
rule combine
command = hoogle combine -o \$out \$in
EOF
COMBINE_DEPS=""
for pfx in $(ghc-pkg dump | grep haddock-html | awk '-F:[ ]*' '{ print $2 }'); do
name=$(echo "$pfx" | sed -E -n 's,^.*doc/(.+)-[^-]+/html$,\1,p')
if [ -z "$name" ]; then
name=$(echo "$pfx" | sed -E -n 's,^.*ghc/html/libraries/(.+)-[^-]+$,\1,p')
fi
if [ -z "$name" ]; then
echo "Unknown dir structure: $pfx"
exit 1
fi
if [ -f "$pfx/$name.txt" ]; then
cat << EOF >> $OUTNINJA
build $name.txt: ln $pfx/$name.txt
build $name.hoo: hoo $name.txt
haddock = $pfx
EOF
COMBINE_DEPS="$COMBINE_DEPS $name.hoo"
fi
done
cat << EOF >> $OUTNINJA
build default.hoo: combine $COMBINE_DEPS
EOF
ninja -C $OUTDIR
exec hoogle server -d $OUTDIR -p 9000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment