You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.1 KiB

  1. #!/usr/bin/env bash
  2. # Copyright 2011 The Go Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style
  4. # license that can be found in the LICENSE file.
  5. # This script creates a complete godoc app in $APPDIR.
  6. # It copies the cmd/godoc and src/go/... sources from GOROOT,
  7. # synthesizes an app.yaml file, and creates the .zip, index, and
  8. # configuration files.
  9. #
  10. # If an argument is provided it is assumed to be the app-engine godoc directory.
  11. # Without an argument, $APPDIR is used instead. If GOROOT is not set, "go env"
  12. # is consulted to find the $GOROOT.
  13. #
  14. # The script creates a .zip file representing the $GOROOT file system
  15. # and computes the correspondig search index files. These files are then
  16. # copied to $APPDIR. A corresponding godoc configuration file is created
  17. # in $APPDIR/appconfig.go.
  18. ZIPFILE=godoc.zip
  19. INDEXFILE=godoc.index
  20. SPLITFILES=index.split.
  21. GODOC=golang.org/x/tools/cmd/godoc
  22. CONFIGFILE=$GODOC/appconfig.go
  23. error() {
  24. echo "error: $1"
  25. exit 2
  26. }
  27. getArgs() {
  28. if [ -z $APPENGINE_SDK ]; then
  29. error "APPENGINE_SDK environment variable not set"
  30. fi
  31. if [ ! -x $APPENGINE_SDK/goapp ]; then
  32. error "couldn't find goapp command in $APPENGINE_SDK"
  33. fi
  34. if [ -z $GOROOT ]; then
  35. GOROOT=$(go env GOROOT)
  36. echo "GOROOT not set explicitly, using go env value instead"
  37. fi
  38. if [ -z $APPDIR ]; then
  39. if [ $# == 0 ]; then
  40. error "APPDIR not set, and no argument provided"
  41. fi
  42. APPDIR=$1
  43. echo "APPDIR not set, using argument instead"
  44. fi
  45. # safety checks
  46. if [ ! -d $GOROOT ]; then
  47. error "$GOROOT is not a directory"
  48. fi
  49. if [ -e $APPDIR ]; then
  50. error "$APPDIR exists; check and remove it before trying again"
  51. fi
  52. # reporting
  53. echo "GOROOT = $GOROOT"
  54. echo "APPDIR = $APPDIR"
  55. }
  56. fetchGodoc() {
  57. echo "*** Fetching godoc (if not already in GOPATH)"
  58. unset GOBIN
  59. go=$APPENGINE_SDK/goapp
  60. $go get -d -tags appengine $GODOC
  61. mkdir -p $APPDIR/$GODOC
  62. cp $(find $($go list -f '{{.Dir}}' $GODOC) -mindepth 1 -maxdepth 1 -type f) $APPDIR/$GODOC/
  63. }
  64. makeAppYaml() {
  65. echo "*** make $APPDIR/app.yaml"
  66. cat > $APPDIR/app.yaml <<EOF
  67. application: godoc
  68. version: 1
  69. runtime: go
  70. api_version: go1.4beta
  71. handlers:
  72. - url: /.*
  73. script: _go_app
  74. EOF
  75. }
  76. makeZipfile() {
  77. echo "*** make $APPDIR/$ZIPFILE"
  78. zip -q -r $APPDIR/$ZIPFILE $GOROOT/*
  79. }
  80. makeIndexfile() {
  81. echo "*** make $APPDIR/$INDEXFILE"
  82. GOPATH= godoc -write_index -index_files=$APPDIR/$INDEXFILE -zip=$APPDIR/$ZIPFILE
  83. }
  84. splitIndexfile() {
  85. echo "*** split $APPDIR/$INDEXFILE"
  86. split -b8m $APPDIR/$INDEXFILE $APPDIR/$SPLITFILES
  87. }
  88. makeConfigfile() {
  89. echo "*** make $APPDIR/$CONFIGFILE"
  90. cat > $APPDIR/$CONFIGFILE <<EOF
  91. package main
  92. // GENERATED FILE - DO NOT MODIFY BY HAND.
  93. // (generated by golang.org/x/tools/cmd/godoc/setup-godoc-app.bash)
  94. const (
  95. // .zip filename
  96. zipFilename = "$ZIPFILE"
  97. // goroot directory in .zip file
  98. zipGoroot = "$GOROOT"
  99. // glob pattern describing search index files
  100. // (if empty, the index is built at run-time)
  101. indexFilenames = "$SPLITFILES*"
  102. )
  103. EOF
  104. }
  105. getArgs "$@"
  106. set -e
  107. mkdir $APPDIR
  108. fetchGodoc
  109. makeAppYaml
  110. makeZipfile
  111. makeIndexfile
  112. splitIndexfile
  113. makeConfigfile
  114. echo "*** setup complete"