build-zip.sh 3.8 KB

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