1#!/bin/bash 2 3# This file is used for both Linux and MacOS builds. 4# For Linux, this script is called inside a docker container with 5# the correct environment for releases. 6# To run locally: 7# ./buildscripts/kokoro/unix.sh 8# For 32 bit: 9# ARCH=32 ./buildscripts/kokoro/unix.sh 10 11# This script assumes `set -e`. Removing it may lead to undefined behavior. 12set -exu -o pipefail 13 14# It would be nicer to use 'readlink -f' here but osx does not support it. 15readonly GRPC_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)" 16 17if [[ -f /VERSION ]]; then 18 cat /VERSION 19fi 20 21# cd to the root dir of grpc-java 22cd $(dirname $0)/../.. 23 24# TODO(zpencer): always make sure we are using Oracle jdk8 25 26# ARCH is 64 bit unless otherwise specified. 27ARCH="${ARCH:-64}" 28 29ARCH="$ARCH" buildscripts/make_dependencies.sh 30 31# Set properties via flags, do not pollute gradle.properties 32GRADLE_FLAGS="${GRADLE_FLAGS:-}" 33GRADLE_FLAGS+=" -PtargetArch=x86_$ARCH $GRADLE_FLAGS" 34GRADLE_FLAGS+=" -Pcheckstyle.ignoreFailures=false" 35GRADLE_FLAGS+=" -PfailOnWarnings=true" 36GRADLE_FLAGS+=" -PerrorProne=true" 37GRADLE_FLAGS+=" -Dorg.gradle.parallel=true" 38export GRADLE_OPTS="-Xmx512m" 39 40# Make protobuf discoverable by :grpc-compiler 41export LD_LIBRARY_PATH=/tmp/protobuf/lib 42export LDFLAGS=-L/tmp/protobuf/lib 43export CXXFLAGS="-I/tmp/protobuf/include" 44 45./gradlew clean $GRADLE_FLAGS 46 47if [[ -z "${SKIP_TESTS:-}" ]]; then 48 # Ensure all *.proto changes include *.java generated code 49 ./gradlew assemble generateTestProto install $GRADLE_FLAGS 50 51 if [[ -z "${SKIP_CLEAN_CHECK:-}" && ! -z $(git status --porcelain) ]]; then 52 git status 53 echo "Error Working directory is not clean. Forget to commit generated files?" 54 exit 1 55 fi 56 # Run tests 57 ./gradlew build $GRADLE_FLAGS 58 pushd examples 59 ./gradlew clean $GRADLE_FLAGS 60 ./gradlew build $GRADLE_FLAGS 61 # --batch-mode reduces log spam 62 mvn clean verify --batch-mode 63 popd 64 # TODO(zpencer): also build the GAE examples 65fi 66 67LOCAL_MVN_TEMP=$(mktemp -d) 68# Note that this disables parallel=true from GRADLE_FLAGS 69if [[ -z "${ALL_ARTIFACTS:-}" ]]; then 70 ./gradlew grpc-compiler:build grpc-compiler:uploadArchives $GRADLE_FLAGS \ 71 -Dorg.gradle.parallel=false -PrepositoryDir=$LOCAL_MVN_TEMP 72else 73 ./gradlew uploadArchives $GRADLE_FLAGS \ 74 -Dorg.gradle.parallel=false -PrepositoryDir=$LOCAL_MVN_TEMP 75fi 76 77readonly MVN_ARTIFACT_DIR="${MVN_ARTIFACT_DIR:-$GRPC_JAVA_DIR/mvn-artifacts}" 78 79mkdir -p "$MVN_ARTIFACT_DIR" 80cp -r "$LOCAL_MVN_TEMP"/* "$MVN_ARTIFACT_DIR"/ 81