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