1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:04:44 -07:00

go.tools/cmd/godoc: fix app engine version; update build script and readme

R=golang-dev, dsymonds, bradfitz
CC=golang-dev
https://golang.org/cl/12897045
This commit is contained in:
Andrew Gerrand 2013-10-03 14:29:16 +10:00
parent 1d95d02fef
commit 3a3a765782
5 changed files with 40 additions and 43 deletions

View File

@ -1,7 +1,3 @@
Copyright 2011 The Go Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
godoc on appengine
------------------
@ -13,6 +9,9 @@ Prerequisites
* Go sources at tip under $GOROOT
* Godoc sources at tip inside $GOPATH
(go get -d code.google.com/p/go.tools/cmd/godoc)
Directory structure
-------------------
@ -24,8 +23,8 @@ Directory structure
app-engine release and version of godoc):
app.yaml
code.google.com/p/go.tools/cmd/godoc
godoc.zip
godoc/
index.split.*
* The app.yaml file is set up per app engine documentation.
@ -40,9 +39,6 @@ Directory structure
- url: /.*
script: _go_app
* The godoc/ directory contains a copy of the files under $GOROOT/src/cmd/godoc
with doc.go excluded (it belongs to pseudo-package "documentation")
Configuring and running godoc
-----------------------------
@ -51,11 +47,10 @@ To configure godoc, run
bash setup-godoc-app.bash
to create the godoc.zip, index.split.*, and godoc/appconfig.go files
based on $GOROOT and $APPDIR. See the script for details on usage.
to prepare an $APPDIR as described above. See the script for details on usage.
To run godoc locally, using the app-engine emulator, run
To run godoc locally, using the App Engine development server, run
<path to google_appengine>/dev_appserver.py $APPDIR
<path to go_appengine>/dev_appserver.py $APPDIR
godoc should come up at http://localhost:8080 .

View File

@ -15,11 +15,15 @@ import (
"path"
"code.google.com/p/go.tools/godoc"
"code.google.com/p/go.tools/godoc/static"
"code.google.com/p/go.tools/godoc/vfs"
"code.google.com/p/go.tools/godoc/vfs/mapfs"
"code.google.com/p/go.tools/godoc/vfs/zipfs"
)
func init() {
playEnabled = true
log.Println("initializing godoc ...")
log.Printf(".zip file = %s", zipFilename)
log.Printf(".zip GOROOT = %s", zipGoroot)
@ -35,6 +39,7 @@ func init() {
}
// rc is never closed (app running forever)
fs.Bind("/", zipfs.New(rc, zipFilename), goroot, vfs.BindReplace)
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
corpus := godoc.NewCorpus(fs)
corpus.Verbose = false

View File

@ -26,6 +26,7 @@ const (
var (
blogServer http.Handler // set by blogInit
blogInitOnce sync.Once
playEnabled bool
)
func init() {
@ -59,7 +60,7 @@ func blogInit() {
ContentPath: filepath.Join(root, "content"),
TemplatePath: filepath.Join(root, "template"),
HomeArticles: 5,
PlayEnabled: *showPlayground,
PlayEnabled: playEnabled,
})
if err != nil {
log.Fatal(err)

View File

@ -186,6 +186,8 @@ func main() {
flag.Usage = usage
flag.Parse()
playEnabled = *showPlayground
// Check usage: either server and no args, command line and args, or index creation mode
if (*httpAddr != "" || *urlFlag != "") != (flag.NArg() == 0) && !*writeIndex {
usage()
@ -195,11 +197,6 @@ func main() {
if *zipfile == "" {
// use file system of underlying OS
fs.Bind("/", vfs.OS(*goroot), "/", vfs.BindReplace)
if *templateDir != "" {
fs.Bind("/lib/godoc", vfs.OS(*templateDir), "/", vfs.BindBefore)
} else {
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
}
} else {
// use file system specified via .zip file (path separator must be '/')
rc, err := zip.OpenReader(*zipfile)
@ -209,6 +206,11 @@ func main() {
defer rc.Close() // be nice (e.g., -writeIndex mode)
fs.Bind("/", zipfs.New(rc, *zipfile), *goroot, vfs.BindReplace)
}
if *templateDir != "" {
fs.Bind("/lib/godoc", vfs.OS(*templateDir), "/", vfs.BindBefore)
} else {
fs.Bind("/lib/godoc", mapfs.New(static.Files), "/", vfs.BindReplace)
}
// Bind $GOPATH trees into Go root.
for _, p := range filepath.SplitList(build.Default.GOPATH) {

View File

@ -21,7 +21,8 @@
ZIPFILE=godoc.zip
INDEXFILE=godoc.index
SPLITFILES=index.split.
CONFIGFILE=godoc/appconfig.go
GODOC=code.google.com/p/go.tools/cmd/godoc
CONFIGFILE=$GODOC/appconfig.go
error() {
echo "error: $1"
@ -29,9 +30,15 @@ error() {
}
getArgs() {
if [ -z $APPENGINE_SDK ]; then
error "APPENGINE_SDK environment variable not set"
fi
if [ ! -x $APPENGINE_SDK/go ]; then
error "couldn't find go comment in $APPENGINE_SDK"
fi
if [ -z $GOROOT ]; then
GOROOT=$(go env GOROOT)
echo "GOROOT not set explicitly, using $GOROOT instead"
echo "GOROOT not set explicitly, using go env value instead"
fi
if [ -z $APPDIR ]; then
if [ $# == 0 ]; then
@ -45,9 +52,6 @@ getArgs() {
if [ ! -d $GOROOT ]; then
error "$GOROOT is not a directory"
fi
if [ ! -x $GOROOT/bin/godoc ]; then
error "$GOROOT/bin/godoc does not exist or is not executable"
fi
if [ -e $APPDIR ]; then
error "$APPDIR exists; check and remove it before trying again"
fi
@ -57,18 +61,13 @@ getArgs() {
echo "APPDIR = $APPDIR"
}
copyGodoc() {
echo "*** copy $GOROOT/src/cmd/godoc to $APPDIR/godoc"
cp -r $GOROOT/src/cmd/godoc $APPDIR/godoc
}
copyGoPackages() {
echo "*** copy $GOROOT/src/pkg/go to $APPDIR/newgo and rewrite imports"
cp -r $GOROOT/src/pkg/go $APPDIR/newgo
find $APPDIR/newgo -type d -name testdata | xargs rm -r
gofiles=$(find $APPDIR -name '*.go')
sed -i '' 's_^\(."\)\(go/[a-z]*\)"$_\1new\2"_' $gofiles
sed -i '' 's_^\(import "\)\(go/[a-z]*\)"$_\1new\2"_' $gofiles
fetchGodoc() {
echo "*** Fetching godoc (if not already in GOPATH)"
unset GOBIN
go=$APPENGINE_SDK/go
$go get -d -tags appengine $GODOC
mkdir -p $APPDIR/$GODOC
cp $(find $($go list -f '{{.Dir}}' $GODOC) -type f -depth 1) $APPDIR/$GODOC/
}
makeAppYaml() {
@ -87,16 +86,12 @@ EOF
makeZipfile() {
echo "*** make $APPDIR/$ZIPFILE"
zip -q -r $APPDIR/$ZIPFILE $GOROOT -i \*.go -i \*.html -i \*.xml -i \*.css -i \*.js -i \*.txt -i \*.c -i \*.h -i \*.s -i \*.png -i \*.jpg -i \*.sh -i \*.ico
zip -q -r $APPDIR/$ZIPFILE $GOROOT/*
}
makeIndexfile() {
echo "*** make $APPDIR/$INDEXFILE"
OUT=/tmp/godoc.out
$GOROOT/bin/godoc -write_index -index_files=$APPDIR/$INDEXFILE -zip=$APPDIR/$ZIPFILE 2> $OUT
if [ $? != 0 ]; then
error "$GOROOT/bin/godoc failed - see $OUT for details"
fi
GOPATH= godoc -write_index -index_files=$APPDIR/$INDEXFILE -zip=$APPDIR/$ZIPFILE
}
splitIndexfile() {
@ -129,8 +124,7 @@ EOF
getArgs "$@"
set -e
mkdir $APPDIR
copyGodoc
copyGoPackages
fetchGodoc
makeAppYaml
makeZipfile
makeIndexfile