make.bash 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env bash
  2. set -e
  3. if [ ! -f make.bash ]; then
  4. echo "make.bash must be run from $GOPATH/src/github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/Android"
  5. exit 1
  6. fi
  7. # Don't use '-u' to force updates because the docker builds always pull
  8. # the latest versions. Outside of Docker, be aware that these dependencies
  9. # will not be overridden w/ new versions if they already exist in $GOPATH
  10. GOOS=arm go get -d -v github.com/Psiphon-Inc/openssl
  11. if [ $? != 0 ]; then
  12. echo "..'go get -d -v github.com/psiphon-inc/openssl' failed, exiting"
  13. exit $?
  14. fi
  15. GOOS=arm go get -d -v github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon
  16. if [ $? != 0 ]; then
  17. echo "..'go get -d -v github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon' failed, exiting"
  18. exit $?
  19. fi
  20. BUILDDATE=$(date --iso-8601=seconds)
  21. BUILDREPO=$(git config --get remote.origin.url)
  22. BUILDREV=$(git rev-parse --short HEAD)
  23. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  24. GOMOBILEVERSION=$(gomobile version | perl -ne '/gomobile version (.*?) / && print $1')
  25. # - starts the string with a `{`
  26. # - uses the `go list` command and passes it a template string (using the Go template syntax) saying I want all the dependencies of the package in the current directory, printing 1/line via printf
  27. # - pipes to `xargs` to run a command on each line output from the first command
  28. # - uses `go list` with a template string to print the "Import Path" (from just below `$GOPATH/src`) if the package is not part of the standard library
  29. # - pipes to `xargs` again, specifiying `pkg` as the placeholder name for each item being operated on (which is the list of non standard library import paths from the previous step)
  30. # - `xargs` runs a bash script (via `-c`) which changes to each import path in sequence, then echoes out `"<import path>":"<subshell output of getting the short git revision>",`
  31. # - this leaves a trailing `,` at the end, and no close to the JSON object, so simply `sed` replace the comma before the end of the line with `}` and you now have valid JSON
  32. DEPENDENCIES=$(echo -n "{" && go list -f '{{range $dep := .Deps}}{{printf "%s\n" $dep}}{{end}}' | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | xargs -I pkg bash -c 'cd $GOPATH/src/pkg && echo -n "\"pkg\":\"$(git rev-parse --short HEAD)\","' | sed 's/,$/}/')
  33. LDFLAGS="\
  34. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildDate=$BUILDDATE \
  35. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildRepo=$BUILDREPO \
  36. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildRev=$BUILDREV \
  37. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.goVersion=$GOVERSION \
  38. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.gomobileVersion=$GOMOBILEVERSION \
  39. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.dependencies=$DEPENDENCIES \
  40. "
  41. echo "Variables for ldflags:"
  42. echo " Build date: ${BUILDDATE}"
  43. echo " Build repo: ${BUILDREPO}"
  44. echo " Build revision: ${BUILDREV}"
  45. echo " Go version: ${GOVERSION}"
  46. echo " Gomobile version: ${GOMOBILEVERSION}"
  47. echo " Dependencies: ${DEPENDENCIES}"
  48. echo ""
  49. gomobile bind -v -target=android/arm -ldflags="$LDFLAGS" github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi
  50. if [ $? != 0 ]; then
  51. echo "..'gomobile bind' failed, exiting"
  52. exit $?
  53. fi
  54. mkdir -p build-tmp/psi
  55. unzip -o psi.aar -d build-tmp/psi
  56. yes | cp -rf PsiphonTunnel/AndroidManifest.xml build-tmp/psi/AndroidManifest.xml
  57. javac -d build-tmp -bootclasspath $ANDROID_HOME/platforms/android-23/android.jar -source 1.7 -target 1.7 -classpath build-tmp/psi/classes.jar:$ANDROID_HOME/platforms/android-23/optional/org.apache.http.legacy.jar PsiphonTunnel/PsiphonTunnel.java
  58. cd build-tmp
  59. jar uf psi/classes.jar ca/psiphon/*.class
  60. cd -
  61. cd build-tmp/psi
  62. zip -r ../../ca.psiphon.aar ./
  63. cd -
  64. rm -rf build-tmp
  65. echo "Done"