A lightweight mechanism to provide an *instant kickstart* to a Go web server instance upon changing any Go source files under the project directory (and its subdirectories).

mkall.sh 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/usr/bin/env bash
  2. # Copyright 2009 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 runs or (given -n) prints suggested commands to generate files for
  6. # the Architecture/OS specified by the GOARCH and GOOS environment variables.
  7. # See README.md for more information about how the build system works.
  8. GOOSARCH="${GOOS}_${GOARCH}"
  9. # defaults
  10. mksyscall="./mksyscall.pl"
  11. mkerrors="./mkerrors.sh"
  12. zerrors="zerrors_$GOOSARCH.go"
  13. mksysctl=""
  14. zsysctl="zsysctl_$GOOSARCH.go"
  15. mksysnum=
  16. mktypes=
  17. run="sh"
  18. cmd=""
  19. case "$1" in
  20. -syscalls)
  21. for i in zsyscall*go
  22. do
  23. # Run the command line that appears in the first line
  24. # of the generated file to regenerate it.
  25. sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
  26. rm _$i
  27. done
  28. exit 0
  29. ;;
  30. -n)
  31. run="cat"
  32. cmd="echo"
  33. shift
  34. esac
  35. case "$#" in
  36. 0)
  37. ;;
  38. *)
  39. echo 'usage: mkall.sh [-n]' 1>&2
  40. exit 2
  41. esac
  42. if [[ "$GOOS" = "linux" ]] && [[ "$GOARCH" != "sparc64" ]]; then
  43. # Use then new build system
  44. # Files generated through docker (use $cmd so you can Ctl-C the build or run)
  45. $cmd docker build --tag generate:$GOOS $GOOS
  46. $cmd docker run --interactive --tty --volume $(dirname "$(readlink -f "$0")"):/build generate:$GOOS
  47. exit
  48. fi
  49. GOOSARCH_in=syscall_$GOOSARCH.go
  50. case "$GOOSARCH" in
  51. _* | *_ | _)
  52. echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
  53. exit 1
  54. ;;
  55. darwin_386)
  56. mkerrors="$mkerrors -m32"
  57. mksyscall="./mksyscall.pl -l32"
  58. mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
  59. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  60. ;;
  61. darwin_amd64)
  62. mkerrors="$mkerrors -m64"
  63. mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
  64. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  65. ;;
  66. darwin_arm)
  67. mkerrors="$mkerrors"
  68. mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
  69. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  70. ;;
  71. darwin_arm64)
  72. mkerrors="$mkerrors -m64"
  73. mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h"
  74. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  75. ;;
  76. dragonfly_386)
  77. mkerrors="$mkerrors -m32"
  78. mksyscall="./mksyscall.pl -l32 -dragonfly"
  79. mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
  80. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  81. ;;
  82. dragonfly_amd64)
  83. mkerrors="$mkerrors -m64"
  84. mksyscall="./mksyscall.pl -dragonfly"
  85. mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
  86. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  87. ;;
  88. freebsd_386)
  89. mkerrors="$mkerrors -m32"
  90. mksyscall="./mksyscall.pl -l32"
  91. mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
  92. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  93. ;;
  94. freebsd_amd64)
  95. mkerrors="$mkerrors -m64"
  96. mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
  97. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  98. ;;
  99. freebsd_arm)
  100. mkerrors="$mkerrors"
  101. mksyscall="./mksyscall.pl -l32 -arm"
  102. mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
  103. # Let the type of C char be signed for making the bare syscall
  104. # API consistent across over platforms.
  105. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  106. ;;
  107. linux_sparc64)
  108. GOOSARCH_in=syscall_linux_sparc64.go
  109. unistd_h=/usr/include/sparc64-linux-gnu/asm/unistd.h
  110. mkerrors="$mkerrors -m64"
  111. mksysnum="./mksysnum_linux.pl $unistd_h"
  112. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  113. ;;
  114. netbsd_386)
  115. mkerrors="$mkerrors -m32"
  116. mksyscall="./mksyscall.pl -l32 -netbsd"
  117. mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
  118. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  119. ;;
  120. netbsd_amd64)
  121. mkerrors="$mkerrors -m64"
  122. mksyscall="./mksyscall.pl -netbsd"
  123. mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
  124. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  125. ;;
  126. openbsd_386)
  127. mkerrors="$mkerrors -m32"
  128. mksyscall="./mksyscall.pl -l32 -openbsd"
  129. mksysctl="./mksysctl_openbsd.pl"
  130. zsysctl="zsysctl_openbsd.go"
  131. mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
  132. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  133. ;;
  134. openbsd_amd64)
  135. mkerrors="$mkerrors -m64"
  136. mksyscall="./mksyscall.pl -openbsd"
  137. mksysctl="./mksysctl_openbsd.pl"
  138. zsysctl="zsysctl_openbsd.go"
  139. mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
  140. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  141. ;;
  142. solaris_amd64)
  143. mksyscall="./mksyscall_solaris.pl"
  144. mkerrors="$mkerrors -m64"
  145. mksysnum=
  146. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  147. ;;
  148. *)
  149. echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
  150. exit 1
  151. ;;
  152. esac
  153. (
  154. if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
  155. case "$GOOS" in
  156. *)
  157. syscall_goos="syscall_$GOOS.go"
  158. case "$GOOS" in
  159. darwin | dragonfly | freebsd | netbsd | openbsd)
  160. syscall_goos="syscall_bsd.go $syscall_goos"
  161. ;;
  162. esac
  163. if [ -n "$mksyscall" ]; then echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; fi
  164. ;;
  165. esac
  166. if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
  167. if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
  168. if [ -n "$mktypes" ]; then
  169. echo "$mktypes types_$GOOS.go | go run mkpost.go > ztypes_$GOOSARCH.go";
  170. fi
  171. ) | $run