build-zip.sh 3.0 KB

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