make.bash 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env bash
  2. set -e -x
  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. # The "OPENSSL" tag enables support of OpenSSL for use by IndistinguishableTLS.
  8. BUILD_TAGS="OPENSSL"
  9. # Don't use '-u' to force updates because the docker builds always pull
  10. # the latest versions. Outside of Docker, be aware that these dependencies
  11. # will not be overridden w/ new versions if they already exist in $GOPATH
  12. GOOS=arm go get -d -v -tags "${BUILD_TAGS}" github.com/Psiphon-Inc/openssl
  13. if [ $? != 0 ]; then
  14. echo "..'go get -d -v github.com/psiphon-inc/openssl' failed, exiting"
  15. exit $?
  16. fi
  17. GOOS=arm go get -d -v -tags "${BUILD_TAGS}" github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon
  18. if [ $? != 0 ]; then
  19. echo "..'go get -d -v github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon' failed, exiting"
  20. exit $?
  21. fi
  22. BUILDDATE=$(date --iso-8601=seconds)
  23. BUILDREPO=$(git config --get remote.origin.url)
  24. BUILDREV=$(git rev-parse --short HEAD)
  25. GOVERSION=$(go version | perl -ne '/go version (.*?) / && print $1')
  26. GOMOBILEVERSION=$(gomobile version | perl -ne '/gomobile version (.*?) / && print $1')
  27. # - starts the string with a `{`
  28. # - 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
  29. # - pipes to `xargs` to run a command on each line output from the first command
  30. # - 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
  31. # - 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)
  32. # - `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>",`
  33. # - 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
  34. DEPENDENCIES=$(cd ../psi && 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/,$/}/')
  35. LDFLAGS="\
  36. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildDate=$BUILDDATE \
  37. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildRepo=$BUILDREPO \
  38. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.buildRev=$BUILDREV \
  39. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.goVersion=$GOVERSION \
  40. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.gomobileVersion=$GOMOBILEVERSION \
  41. -X github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common.dependencies=$DEPENDENCIES \
  42. "
  43. echo "Variables for ldflags:"
  44. echo " Build date: ${BUILDDATE}"
  45. echo " Build repo: ${BUILDREPO}"
  46. echo " Build revision: ${BUILDREV}"
  47. echo " Go version: ${GOVERSION}"
  48. echo " Gomobile version: ${GOMOBILEVERSION}"
  49. echo " Dependencies: ${DEPENDENCIES}"
  50. echo ""
  51. gomobile bind -v -target=android/arm -tags "${BUILD_TAGS}" -ldflags="$LDFLAGS" github.com/Psiphon-Labs/psiphon-tunnel-core/MobileLibrary/psi
  52. if [ $? != 0 ]; then
  53. echo "..'gomobile bind' failed, exiting"
  54. exit $?
  55. fi
  56. mkdir -p build-tmp/psi
  57. unzip -o psi.aar -d build-tmp/psi
  58. yes | cp -f PsiphonTunnel/AndroidManifest.xml build-tmp/psi/AndroidManifest.xml
  59. yes | cp -f PsiphonTunnel/libs/libtun2socks.so build-tmp/psi/jni/armeabi-v7a/libtun2socks.so
  60. 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
  61. if [ $? != 0 ]; then
  62. echo "..'javac' compiling PsiphonTunnel failed, exiting"
  63. exit $?
  64. fi
  65. cd build-tmp
  66. jar uf psi/classes.jar ca/psiphon/*.class
  67. if [ $? != 0 ]; then
  68. echo "..'jar' failed to add classes, exiting"
  69. exit $?
  70. fi
  71. cd -
  72. cd build-tmp/psi
  73. zip -r ../../ca.psiphon.aar ./
  74. cd -
  75. rm -rf build-tmp
  76. echo "Done"