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