build-zip.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/bash
  2. if [ $# -ne 2 ]; then
  3. cat <<EOF
  4. Usage: $0 <TARGET> <VERSION_NUMBER>
  5. TARGET: protoc | protoc-gen-javalite
  6. Example:
  7. $ $0 protoc 3.0.0
  8. $ $0 protoc-gen-javalite 3.0.0
  9. This script will download pre-built protoc or protoc plugin binaries from maven
  10. repository and create .zip packages suitable to be included in the github
  11. release page. If the target is protoc, well-known type .proto files will also be
  12. included. Each invocation will create 9 zip packages:
  13. dist/<TARGET>-<VERSION_NUMBER>-win32.zip
  14. dist/<TARGET>-<VERSION_NUMBER>-win64.zip
  15. dist/<TARGET>-<VERSION_NUMBER>-osx-x86_32.zip
  16. dist/<TARGET>-<VERSION_NUMBER>-osx-x86_64.zip
  17. dist/<TARGET>-<VERSION_NUMBER>-linux-x86_32.zip
  18. dist/<TARGET>-<VERSION_NUMBER>-linux-x86_64.zip
  19. dist/<TARGET>-<VERSION_NUMBER>-linux-aarch_64.zip
  20. dist/<TARGET>-<VERSION_NUMBER>-linux-ppcle_64.zip
  21. dist/<TARGET>-<VERSION_NUMBER>-linux-s390x_64.zip
  22. EOF
  23. exit 1
  24. fi
  25. TARGET=$1
  26. VERSION_NUMBER=$2
  27. # <zip file name> <binary file name> pairs.
  28. declare -a FILE_NAMES=( \
  29. win32.zip windows-x86_32.exe \
  30. win64.zip windows-x86_64.exe \
  31. osx-x86_32.zip osx-x86_32.exe \
  32. osx-x86_64.zip osx-x86_64.exe \
  33. linux-x86_32.zip linux-x86_32.exe \
  34. linux-x86_64.zip linux-x86_64.exe \
  35. linux-aarch_64.zip linux-aarch_64.exe \
  36. linux-ppcle_64.zip linux-ppcle_64.exe \
  37. linux-s390x_64.zip linux-s390x_64.exe \
  38. )
  39. # List of all well-known types to be included.
  40. declare -a WELL_KNOWN_TYPES=( \
  41. google/protobuf/descriptor.proto \
  42. google/protobuf/any.proto \
  43. google/protobuf/api.proto \
  44. google/protobuf/duration.proto \
  45. google/protobuf/empty.proto \
  46. google/protobuf/field_mask.proto \
  47. google/protobuf/source_context.proto \
  48. google/protobuf/struct.proto \
  49. google/protobuf/timestamp.proto \
  50. google/protobuf/type.proto \
  51. google/protobuf/wrappers.proto \
  52. google/protobuf/compiler/plugin.proto \
  53. )
  54. set -e
  55. # A temporary working directory to put all files.
  56. DIR=$(mktemp -d)
  57. # Copy over well-known types.
  58. mkdir -p ${DIR}/include/google/protobuf/compiler
  59. for PROTO in ${WELL_KNOWN_TYPES[@]}; do
  60. cp -f ../src/${PROTO} ${DIR}/include/${PROTO}
  61. done
  62. # Create a readme file.
  63. cat <<EOF > ${DIR}/readme.txt
  64. Protocol Buffers - Google's data interchange format
  65. Copyright 2008 Google Inc.
  66. https://developers.google.com/protocol-buffers/
  67. This package contains a precompiled binary version of the protocol buffer
  68. compiler (protoc). This binary is intended for users who want to use Protocol
  69. Buffers in languages other than C++ but do not want to compile protoc
  70. themselves. To install, simply place this binary somewhere in your PATH.
  71. If you intend to use the included well known types then don't forget to
  72. copy the contents of the 'include' directory somewhere as well, for example
  73. into '/usr/local/include/'.
  74. Please refer to our official github site for more installation instructions:
  75. https://github.com/protocolbuffers/protobuf
  76. EOF
  77. mkdir -p dist
  78. mkdir -p ${DIR}/bin
  79. # Create a zip file for each binary.
  80. for((i=0;i<${#FILE_NAMES[@]};i+=2));do
  81. ZIP_NAME=${FILE_NAMES[$i]}
  82. if [ ${ZIP_NAME:0:3} = "win" ]; then
  83. BINARY="$TARGET.exe"
  84. else
  85. BINARY="$TARGET"
  86. fi
  87. BINARY_NAME=${FILE_NAMES[$(($i+1))]}
  88. BINARY_URL=http://repo1.maven.org/maven2/com/google/protobuf/$TARGET/${VERSION_NUMBER}/$TARGET-${VERSION_NUMBER}-${BINARY_NAME}
  89. if ! wget ${BINARY_URL} -O ${DIR}/bin/$BINARY &> /dev/null; then
  90. echo "[ERROR] Failed to download ${BINARY_URL}" >&2
  91. echo "[ERROR] Skipped $TARGET-${VERSION_NAME}-${ZIP_NAME}" >&2
  92. continue
  93. fi
  94. TARGET_ZIP_FILE=`pwd`/dist/$TARGET-${VERSION_NUMBER}-${ZIP_NAME}
  95. pushd $DIR &> /dev/null
  96. chmod +x bin/$BINARY
  97. if [ "$TARGET" = "protoc" ]; then
  98. zip -r ${TARGET_ZIP_FILE} include bin readme.txt &> /dev/null
  99. else
  100. zip -r ${TARGET_ZIP_FILE} bin &> /dev/null
  101. fi
  102. rm bin/$BINARY
  103. popd &> /dev/null
  104. echo "[INFO] Successfully created ${TARGET_ZIP_FILE}"
  105. done