ldflags.sh 523 B

123456789101112131415161718
  1. #!/bin/sh
  2. set -e
  3. if [ ! -f "build/env.sh" ]; then
  4. echo "$0 must be run from the root of the repository."
  5. exit 2
  6. fi
  7. # Since Go 1.5, the separator char for link time assignments
  8. # is '=' and using ' ' prints a warning. However, Go < 1.5 does
  9. # not support using '='.
  10. sep=$(go version | awk '{ if ($3 >= "go1.5" || index($3, "devel")) print "="; else print " "; }' -)
  11. # set gitCommit when running from a Git checkout.
  12. if [ -f ".git/HEAD" ]; then
  13. echo "-ldflags '-X main.gitCommit$sep$(git rev-parse HEAD)'"
  14. fi