1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:24:41 -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 godoc on appengine
------------------ ------------------
@ -13,6 +9,9 @@ Prerequisites
* Go sources at tip under $GOROOT * 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 Directory structure
------------------- -------------------
@ -24,8 +23,8 @@ Directory structure
app-engine release and version of godoc): app-engine release and version of godoc):
app.yaml app.yaml
code.google.com/p/go.tools/cmd/godoc
godoc.zip godoc.zip
godoc/
index.split.* index.split.*
* The app.yaml file is set up per app engine documentation. * The app.yaml file is set up per app engine documentation.
@ -40,9 +39,6 @@ Directory structure
- url: /.* - url: /.*
script: _go_app 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 Configuring and running godoc
----------------------------- -----------------------------
@ -51,11 +47,10 @@ To configure godoc, run
bash setup-godoc-app.bash bash setup-godoc-app.bash
to create the godoc.zip, index.split.*, and godoc/appconfig.go files to prepare an $APPDIR as described above. See the script for details on usage.
based on $GOROOT and $APPDIR. 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 . godoc should come up at http://localhost:8080 .

View File

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

View File

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

View File

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

View File

@ -21,7 +21,8 @@
ZIPFILE=godoc.zip ZIPFILE=godoc.zip
INDEXFILE=godoc.index INDEXFILE=godoc.index
SPLITFILES=index.split. SPLITFILES=index.split.
CONFIGFILE=godoc/appconfig.go GODOC=code.google.com/p/go.tools/cmd/godoc
CONFIGFILE=$GODOC/appconfig.go
error() { error() {
echo "error: $1" echo "error: $1"
@ -29,9 +30,15 @@ error() {
} }
getArgs() { 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 if [ -z $GOROOT ]; then
GOROOT=$(go env GOROOT) GOROOT=$(go env GOROOT)
echo "GOROOT not set explicitly, using $GOROOT instead" echo "GOROOT not set explicitly, using go env value instead"
fi fi
if [ -z $APPDIR ]; then if [ -z $APPDIR ]; then
if [ $# == 0 ]; then if [ $# == 0 ]; then
@ -45,9 +52,6 @@ getArgs() {
if [ ! -d $GOROOT ]; then if [ ! -d $GOROOT ]; then
error "$GOROOT is not a directory" error "$GOROOT is not a directory"
fi fi
if [ ! -x $GOROOT/bin/godoc ]; then
error "$GOROOT/bin/godoc does not exist or is not executable"
fi
if [ -e $APPDIR ]; then if [ -e $APPDIR ]; then
error "$APPDIR exists; check and remove it before trying again" error "$APPDIR exists; check and remove it before trying again"
fi fi
@ -57,18 +61,13 @@ getArgs() {
echo "APPDIR = $APPDIR" echo "APPDIR = $APPDIR"
} }
copyGodoc() { fetchGodoc() {
echo "*** copy $GOROOT/src/cmd/godoc to $APPDIR/godoc" echo "*** Fetching godoc (if not already in GOPATH)"
cp -r $GOROOT/src/cmd/godoc $APPDIR/godoc unset GOBIN
} go=$APPENGINE_SDK/go
$go get -d -tags appengine $GODOC
copyGoPackages() { mkdir -p $APPDIR/$GODOC
echo "*** copy $GOROOT/src/pkg/go to $APPDIR/newgo and rewrite imports" cp $(find $($go list -f '{{.Dir}}' $GODOC) -type f -depth 1) $APPDIR/$GODOC/
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
} }
makeAppYaml() { makeAppYaml() {
@ -87,16 +86,12 @@ EOF
makeZipfile() { makeZipfile() {
echo "*** make $APPDIR/$ZIPFILE" 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() { makeIndexfile() {
echo "*** make $APPDIR/$INDEXFILE" echo "*** make $APPDIR/$INDEXFILE"
OUT=/tmp/godoc.out GOPATH= godoc -write_index -index_files=$APPDIR/$INDEXFILE -zip=$APPDIR/$ZIPFILE
$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
} }
splitIndexfile() { splitIndexfile() {
@ -129,8 +124,7 @@ EOF
getArgs "$@" getArgs "$@"
set -e set -e
mkdir $APPDIR mkdir $APPDIR
copyGodoc fetchGodoc
copyGoPackages
makeAppYaml makeAppYaml
makeZipfile makeZipfile
makeIndexfile makeIndexfile