Mercurial > hg > soundsoftware-site
changeset 203:1e55195bca45 feature_20
Pull doc extractor script out into separate javadoc, doxygen, and controller scripts
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Mon, 07 Feb 2011 16:46:28 +0000 |
parents | 0d1c6fa50d3a |
children | 292cde42265a 984e4ee774f1 |
files | extra/soundsoftware/extract-docs.sh extra/soundsoftware/extract-doxygen.sh extra/soundsoftware/extract-javadoc.sh |
diffstat | 3 files changed, 168 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/soundsoftware/extract-docs.sh Mon Feb 07 16:46:28 2011 +0000 @@ -0,0 +1,79 @@ +#!/bin/bash + +# Run this script from anywhere + +# Enumerate Hg repos; make sure they're up to date; extract docs for +# each + +hgdir="/var/hg" +docdir="/var/doc" + +progdir=$(dirname $0) +case "$progdir" in + /*) ;; + *) progdir="$(pwd)/$progdir" ;; +esac + +types="javadoc doxygen" + +for x in $types; do + if [ ! -x "$progdir/extract-$x.sh" ]; then + echo "Helper script not available: $progdir/extract-$x.sh" + exit 1 + fi +done + +for projectdir in "$hgdir"/* ; do + + if [ -d "$projectdir" ] && [ -d "$projectdir/.hg" ]; then + + project=$(basename "$projectdir") + echo "Found Hg repo: $projectdir for project $project" + + ##!!! do as www-data: + ( cd "$projectdir" ; sudo -u www-data hg -q update ) || exit 1 + + tmpdir=$(mktemp -d "$docdir/tmp_XXXXXX") + + case "$tmpdir" in + /*) ;; + *) echo "Temporary directory creation failed"; exit 1;; + esac + + targetdir="$docdir/$project" + + echo "Temporary dir is $tmpdir, eventual target is $targetdir" + + ##!!! do as docs user: + for x in $types; do + if "$progdir/extract-$x.sh" "$project" "$tmpdir"; then + break + else + echo "Failed to extract via type $x" + fi + done + + if [ -f "$tmpdir/index.html" ]; then + echo "Processing resulted in an index.html being created, looks good!" + if [ ! -d "$targetdir" ] || [ ! -f "$targetdir/index.html" ]; then +# # If we have just written something to a doc directory that was +# # previously empty, we should switch on Embedded for this project + echo "This project hasn't had doc extracted before -- I should switch on Embedded for it at this point" + fi + + if [ -d "$targetdir" ]; then + mv "$targetdir" "$targetdir"_"$$" && \ + mv "$tmpdir" "$targetdir" && \ + rm -rf "$targetdir"_"$$" + else + echo "Processing resulted in no index.html, skipping" + mv "$tmpdir" "$targetdir" + fi + + else + # generated nothing (useful) + rm -rf "$tmpdir" + fi + fi +done +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extra/soundsoftware/extract-doxygen.sh Mon Feb 07 16:46:28 2011 +0000 @@ -0,0 +1,60 @@ +#!/bin/bash + +hgdir="/var/hg" +docdir="/var/doc" + +project="$1" +targetdir="$2" + +projectdir="$hgdir/$project" + +if [ -z "$project" ] || [ -z "$targetdir" ]; then + echo "Usage: $0 <project> <targetdir>" + exit 2 +fi + +if [ ! -d "$projectdir" ] || [ ! -d "$projectdir/.hg" ]; then + echo "No hg repo found at $projectdir" + exit 1 +fi + +if [ ! -d "$targetdir" ]; then + echo "Target dir $targetdir not found" + exit 1 +fi + +if [ -f "$targetdir/index.html" ]; then + echo "Target dir $targetdir already contains index.html" + exit 1 +fi + +doxyfile=$(find "$projectdir" -type f -name Doxyfile -print | head -1) + +if [ -z "$doxyfile" ]; then + echo "No Doxyfile found for project $project" + exit 1 +fi + +echo "Project $project contains a Doxyfile at $doxyfile" + +cd "$projectdir" || exit 1 + +# hmm. should be a whitelist + +cat "$doxyfile" | \ + grep -vi OUTPUT_DIRECTORY | \ + grep -vi HTML_OUTPUT | \ + grep -vi SEARCHENGINE | \ + grep -vi HAVE_DOT | \ + grep -vi DOT_FONTNAME | \ + grep -vi DOT_FONTPATH | \ + grep -vi DOT_TRANSPARENT | \ + sed -e '$a OUTPUT_DIRECTORY='"$targetdir" \ + -e '$a HTML_OUTPUT = .' \ + -e '$a SEARCHENGINE = NO' \ + -e '$a HAVE_DOT = YES' \ + -e '$a DOT_FONTNAME = FreeMono' \ + -e '$a DOT_FONTPATH = /usr/share/fonts/truetype/freefont' \ + -e '$a DOT_TRANSPARENT = YES' | \ + doxygen - +
--- a/extra/soundsoftware/extract-javadoc.sh Fri Feb 04 18:40:21 2011 +0000 +++ b/extra/soundsoftware/extract-javadoc.sh Mon Feb 07 16:46:28 2011 +0000 @@ -1,40 +1,31 @@ -#!/bin/sh +#!/bin/bash -# Run this script from /var/doc/<project-name> +hgdir="/var/hg" +docdir="/var/doc" -# Find Hg repo and update it. We should separate this process into -# two, first the update (run as www-data) and then the extraction (run -# as an otherwise totally unprivileged user without write permission -# on www-data/code stuff) +project="$1" +targetdir="$2" -docdir=$(pwd) -name=$(basename $(pwd)) -hgdir="/var/hg/$name" -echo "Extracting doc for $name" -if [ ! -d "$hgdir" ]; then - echo "Error: No $hgdir found for project $name" - exit 1 +projectdir="$hgdir/$project" + +if [ -z "$project" ] || [ -z "$targetdir" ]; then + echo "Usage: $0 <project> <targetdir>" + exit 2 fi -( cd "$hgdir" ; hg update ) || exit 1 -# Identify either a Doxyfile or some Java packages +if [ ! -d "$projectdir" ] || [ ! -d "$projectdir/.hg" ]; then + echo "No hg repo found at $projectdir" + exit 1 +fi -# TODO: Doxyfile +if [ ! -d "$targetdir" ]; then + echo "Target dir $targetdir not found" + exit 1 +fi -doxyfile=`find "$hgdir" -type f -name Doxyfile -print | head -1` - -if [ -z "$doxyfile" ]; then - echo "No Doxyfile: skipping" -else - echo "This project contains a Doxyfile:" - echo "$doxyfile" - - -# hmm. should be a whitelist - - ( cd "$hgdir" && grep -vi OUTPUT_DIRECTORY "$doxyfile" | grep -vi HTML_OUTPUT | grep -vi SEARCHENGINE | grep -vi HAVE_DOT | grep -vi DOT_FONTNAME | grep -vi DOT_FONTPATH | grep -vi DOT_TRANSPARENT | \ - sed -e '$a OUTPUT_DIRECTORY='"$docdir" -e '$a HTML_OUTPUT = .' -e '$a SEARCHENGINE = NO' -e '$a HAVE_DOT = YES' -e '$a DOT_FONTNAME = FreeMono' -e '$a DOT_FONTPATH = /usr/share/fonts/truetype/freefont' -e '$a DOT_TRANSPARENT = YES' | doxygen - ) - +if [ -f "$targetdir/index.html" ]; then + echo "Target dir $targetdir already contains index.html" + exit 1 fi # Identify Java files whose packages match the trailing parts of their @@ -45,7 +36,8 @@ # Regexp match is very rough; check what is actually permitted for # package declarations -find "$hgdir" -type f -name \*.java -exec grep '^ *package [a-zA-Z][a-zA-Z0-9\._-]*; *$' \{\} /dev/null \; | +find "$projectdir" -type f -name \*.java \ + -exec grep '^ *package [a-zA-Z][a-zA-Z0-9\._-]*; *$' \{\} /dev/null \; | sed -e 's/\/[^\/]*: *package */:/' -e 's/; *$//' | sort | uniq | ( current_prefix= @@ -54,7 +46,7 @@ echo "Looking at $package in $filepath" packagepath=${package//./\/} prefix=${filepath%$packagepath} - prefix=${prefix:=$hgdir} + prefix=${prefix:=$projectdir} if [ "$prefix" = "$filepath" ]; then echo "Package $package does not match suffix of path $filepath, skipping" continue @@ -62,7 +54,7 @@ if [ "$prefix" != "$current_prefix" ]; then if [ -n "$current_packages" ]; then echo "Running Javadoc for packages $current_packages from prefix $current_prefix" - javadoc -sourcepath "$current_prefix" -d . -subpackages $current_packages + javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages fi current_prefix="$prefix" current_packages= @@ -70,39 +62,13 @@ current_packages="$current_packages $package" fi done - prefix=${prefix:=$hgdir} + prefix=${prefix:=$projectdir} if [ -n "$current_packages" ]; then echo "Running Javadoc for packages $current_packages in prefix $current_prefix" - javadoc -sourcepath "$current_prefix" -d . -subpackages $current_packages + javadoc -sourcepath "$current_prefix" -d "$targetdir" -subpackages $current_packages fi ) -# This is very rough; check what is actually permitted for package -# declarations +# for exit code: +[ -f "$targetdir/index.html" ] -# java_packages=`find "$hgdir" -type f -name \*.java -print | \ -# xargs grep -h '^ *package [a-zA-Z][a-zA-Z0-9\._-]* *; *' | \ -# sort | uniq | \ -# sed -e 's/^ *package //' -e 's/ *; *$//'` - -# echo "This project contains Java packages:" -# echo "$java_packages" - -# if [ -z "$java_packages" ]; then -# echo "No Java packages: skipping" -# exit 0 -# fi - - -# # This won't work if code is in a subdir, -# # e.g. src/com/example/project/Hello.java - -# # We need to convert the package name back to a path, and check -# # whether that matches the tail of the path to a java file that -# # declares itself to be in that package... but we don't have that list -# # of java files to hand here... hm - -# javadoc -sourcepath "$hgdir" -d . -subpackages $java_packages -verbose - -# # If we have just written something to a doc directory that was -# # previously empty, we should switch on Embedded for this project