build-zip.sh 3.4 KB

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