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 x86 32 arch: 9# ARCH=x86_32 ./buildscripts/kokoro/unix.sh 10# For aarch64 arch: 11# ARCH=aarch_64 ./buildscripts/kokoro/unix.sh 12# For ppc64le arch: 13# ARCH=ppcle_64 ./buildscripts/kokoro/unix.sh 14# For s390x arch: 15# ARCH=s390_64 ./buildscripts/kokoro/unix.sh 16 17# This script assumes `set -e`. Removing it may lead to undefined behavior. 18set -exu -o pipefail 19 20# It would be nicer to use 'readlink -f' here but osx does not support it. 21readonly GRPC_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)" 22 23# cd to the root dir of grpc-java 24cd $(dirname $0)/../.. 25 26# TODO(zpencer): always make sure we are using Oracle jdk8 27if [[ -f /usr/libexec/java_home ]]; then 28 JAVA_HOME=$(/usr/libexec/java_home -v"1.8.0") 29fi 30 31# ARCH is x86_64 unless otherwise specified. 32ARCH="${ARCH:-x86_64}" 33 34cat <<EOF >> gradle.properties 35# defaults to -Xmx512m -XX:MaxMetaspaceSize=256m 36# https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory 37# Increased due to java.lang.OutOfMemoryError: Metaspace failures, "JVM heap 38# space is exhausted", and to increase build speed 39org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=1024m 40EOF 41 42ARCH="$ARCH" buildscripts/make_dependencies.sh 43 44# Set properties via flags, do not pollute gradle.properties 45GRADLE_FLAGS="${GRADLE_FLAGS:-}" 46GRADLE_FLAGS+=" -PtargetArch=$ARCH" 47GRADLE_FLAGS+=" -Pcheckstyle.ignoreFailures=false" 48GRADLE_FLAGS+=" -PfailOnWarnings=true" 49GRADLE_FLAGS+=" -PerrorProne=true" 50GRADLE_FLAGS+=" -PskipAndroid=true" 51GRADLE_FLAGS+=" -Dorg.gradle.parallel=true" 52export GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'" 53 54# Make protobuf discoverable by :grpc-compiler 55export LD_LIBRARY_PATH=/tmp/protobuf/lib 56export LDFLAGS=-L/tmp/protobuf/lib 57export CXXFLAGS="-I/tmp/protobuf/include" 58 59./gradlew grpc-compiler:clean $GRADLE_FLAGS 60 61if [[ -z "${SKIP_TESTS:-}" ]]; then 62 # Ensure all *.proto changes include *.java generated code 63 ./gradlew assemble generateTestProto publishToMavenLocal $GRADLE_FLAGS 64 65 if [[ -z "${SKIP_CLEAN_CHECK:-}" && ! -z $(git status --porcelain) ]]; then 66 git status 67 echo "Error Working directory is not clean. Forget to commit generated files?" 68 exit 1 69 fi 70 # Run tests 71 ./gradlew build :grpc-all:jacocoTestReport $GRADLE_FLAGS 72 pushd examples 73 ./gradlew build $GRADLE_FLAGS 74 # --batch-mode reduces log spam 75 mvn verify --batch-mode 76 popd 77 for f in examples/example-* 78 do 79 pushd "$f" 80 ../gradlew build $GRADLE_FLAGS 81 if [ -f "pom.xml" ]; then 82 # --batch-mode reduces log spam 83 mvn verify --batch-mode 84 fi 85 popd 86 done 87 # TODO(zpencer): also build the GAE examples 88fi 89 90LOCAL_MVN_TEMP=$(mktemp -d) 91# Note that this disables parallel=true from GRADLE_FLAGS 92if [[ -z "${ALL_ARTIFACTS:-}" ]]; then 93 if [[ "$ARCH" = "aarch_64" || "$ARCH" = "ppcle_64" || "$ARCH" = "s390_64" ]]; then 94 GRADLE_FLAGS+=" -x grpc-compiler:generateTestProto -x grpc-compiler:generateTestLiteProto" 95 GRADLE_FLAGS+=" -x grpc-compiler:testGolden -x grpc-compiler:testLiteGolden" 96 GRADLE_FLAGS+=" -x grpc-compiler:testDeprecatedGolden -x grpc-compiler:testDeprecatedLiteGolden" 97 fi 98 ./gradlew grpc-compiler:build grpc-compiler:publish $GRADLE_FLAGS \ 99 -Dorg.gradle.parallel=false -PrepositoryDir=$LOCAL_MVN_TEMP 100else 101 ./gradlew publish :grpc-core:versionFile $GRADLE_FLAGS \ 102 -Dorg.gradle.parallel=false -PrepositoryDir=$LOCAL_MVN_TEMP 103 pushd examples/example-hostname 104 ../gradlew jibBuildTar $GRADLE_FLAGS 105 popd 106 107 readonly OTHER_ARTIFACT_DIR="${OTHER_ARTIFACT_DIR:-$GRPC_JAVA_DIR/artifacts}" 108 mkdir -p "$OTHER_ARTIFACT_DIR" 109 cp core/build/version "$OTHER_ARTIFACT_DIR"/ 110 cp examples/example-hostname/build/example-hostname.* "$OTHER_ARTIFACT_DIR"/ 111fi 112 113readonly MVN_ARTIFACT_DIR="${MVN_ARTIFACT_DIR:-$GRPC_JAVA_DIR/mvn-artifacts}" 114 115mkdir -p "$MVN_ARTIFACT_DIR" 116cp -r "$LOCAL_MVN_TEMP"/* "$MVN_ARTIFACT_DIR"/ 117