build-zip.sh 3.89 KB
Newer Older
1 2
#!/bin/bash

3
if [ $# -ne 2 ]; then
4
  cat <<EOF
5 6 7
Usage: $0 <TARGET> <VERSION_NUMBER>

TARGET: protoc | protoc-gen-javalite
8 9

Example:
10 11
  $ $0 protoc 3.0.0
  $ $0 protoc-gen-javalite 3.0.0
12

13 14 15
This script will download pre-built protoc or protoc plugin binaries from maven
repository and create .zip packages suitable to be included in the github
release page. If the target is protoc, well-known type .proto files will also be
16
included. Each invocation will create 9 zip packages:
17
  dist/<TARGET>-<VERSION_NUMBER>-win32.zip
18
  dist/<TARGET>-<VERSION_NUMBER>-win64.zip
19 20 21 22
  dist/<TARGET>-<VERSION_NUMBER>-osx-x86_32.zip
  dist/<TARGET>-<VERSION_NUMBER>-osx-x86_64.zip
  dist/<TARGET>-<VERSION_NUMBER>-linux-x86_32.zip
  dist/<TARGET>-<VERSION_NUMBER>-linux-x86_64.zip
Jisi Liu's avatar
Jisi Liu committed
23
  dist/<TARGET>-<VERSION_NUMBER>-linux-aarch_64.zip
24
  dist/<TARGET>-<VERSION_NUMBER>-linux-ppcle_64.zip
25
  dist/<TARGET>-<VERSION_NUMBER>-linux-s390x_64.zip
26 27 28 29
EOF
  exit 1
fi

30 31
TARGET=$1
VERSION_NUMBER=$2
32 33 34 35

# <zip file name> <binary file name> pairs.
declare -a FILE_NAMES=( \
  win32.zip windows-x86_32.exe \
36
  win64.zip windows-x86_64.exe \
37 38 39 40
  osx-x86_32.zip osx-x86_32.exe \
  osx-x86_64.zip osx-x86_64.exe \
  linux-x86_32.zip linux-x86_32.exe \
  linux-x86_64.zip linux-x86_64.exe \
Jisi Liu's avatar
Jisi Liu committed
41
  linux-aarch_64.zip linux-aarch_64.exe \
42
  linux-ppcle_64.zip linux-ppcle_64.exe \
43
  linux-s390x_64.zip linux-s390x_64.exe \
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
)

# List of all well-known types to be included.
declare -a WELL_KNOWN_TYPES=(           \
  google/protobuf/descriptor.proto      \
  google/protobuf/any.proto             \
  google/protobuf/api.proto             \
  google/protobuf/duration.proto        \
  google/protobuf/empty.proto           \
  google/protobuf/field_mask.proto      \
  google/protobuf/source_context.proto  \
  google/protobuf/struct.proto          \
  google/protobuf/timestamp.proto       \
  google/protobuf/type.proto            \
  google/protobuf/wrappers.proto        \
  google/protobuf/compiler/plugin.proto \
)

set -e

# A temporary working directory to put all files.
DIR=$(mktemp -d)

# Copy over well-known types.
mkdir -p ${DIR}/include/google/protobuf/compiler
for PROTO in ${WELL_KNOWN_TYPES[@]}; do
  cp -f ../src/${PROTO} ${DIR}/include/${PROTO}
done

# Create a readme file.
cat <<EOF > ${DIR}/readme.txt
Protocol Buffers - Google's data interchange format
Copyright 2008 Google Inc.
https://developers.google.com/protocol-buffers/

This package contains a precompiled binary version of the protocol buffer
compiler (protoc). This binary is intended for users who want to use Protocol
Buffers in languages other than C++ but do not want to compile protoc
themselves. To install, simply place this binary somewhere in your PATH.

84 85 86 87
If you intend to use the included well known types then don't forget to
copy the contents of the 'include' directory somewhere as well, for example
into '/usr/local/include/'.

88
Please refer to our official github site for more installation instructions:
Feng Xiao's avatar
Feng Xiao committed
89
  https://github.com/protocolbuffers/protobuf
90 91 92 93 94 95 96
EOF

mkdir -p dist
mkdir -p ${DIR}/bin
# Create a zip file for each binary.
for((i=0;i<${#FILE_NAMES[@]};i+=2));do
  ZIP_NAME=${FILE_NAMES[$i]}
97 98 99 100 101
  if [ ${ZIP_NAME:0:3} = "win" ]; then
    BINARY="$TARGET.exe"
  else
    BINARY="$TARGET"
  fi
102
  BINARY_NAME=${FILE_NAMES[$(($i+1))]}
103
  BINARY_URL=http://repo1.maven.org/maven2/com/google/protobuf/$TARGET/${VERSION_NUMBER}/$TARGET-${VERSION_NUMBER}-${BINARY_NAME}
104
  if ! wget ${BINARY_URL} -O ${DIR}/bin/$BINARY &> /dev/null; then
105
    echo "[ERROR] Failed to download ${BINARY_URL}" >&2
106
    echo "[ERROR] Skipped $TARGET-${VERSION_NAME}-${ZIP_NAME}" >&2
107 108
    continue
  fi
109
  TARGET_ZIP_FILE=`pwd`/dist/$TARGET-${VERSION_NUMBER}-${ZIP_NAME}
110
  pushd $DIR &> /dev/null
111
  chmod +x bin/$BINARY
112 113 114 115 116
  if [ "$TARGET" = "protoc" ]; then
    zip -r ${TARGET_ZIP_FILE} include bin readme.txt &> /dev/null
  else
    zip -r ${TARGET_ZIP_FILE} bin &> /dev/null
  fi
117
  rm  bin/$BINARY
118 119 120
  popd &> /dev/null
  echo "[INFO] Successfully created ${TARGET_ZIP_FILE}"
done