Home | History | Annotate | Download | only in kokoro
      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.
     12 set -exu -o pipefail
     13 
     14 # It would be nicer to use 'readlink -f' here but osx does not support it.
     15 readonly GRPC_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)"
     16 
     17 if [[ -f /VERSION ]]; then
     18   cat /VERSION
     19 fi
     20 
     21 # cd to the root dir of grpc-java
     22 cd $(dirname $0)/../..
     23 
     24 # TODO(zpencer): always make sure we are using Oracle jdk8
     25 
     26 # ARCH is 64 bit unless otherwise specified.
     27 ARCH="${ARCH:-64}"
     28 
     29 ARCH="$ARCH" buildscripts/make_dependencies.sh
     30 
     31 # Set properties via flags, do not pollute gradle.properties
     32 GRADLE_FLAGS="${GRADLE_FLAGS:-}"
     33 GRADLE_FLAGS+=" -PtargetArch=x86_$ARCH $GRADLE_FLAGS"
     34 GRADLE_FLAGS+=" -Pcheckstyle.ignoreFailures=false"
     35 GRADLE_FLAGS+=" -PfailOnWarnings=true"
     36 GRADLE_FLAGS+=" -PerrorProne=true"
     37 GRADLE_FLAGS+=" -Dorg.gradle.parallel=true"
     38 export GRADLE_OPTS="-Xmx512m"
     39 
     40 # Make protobuf discoverable by :grpc-compiler
     41 export LD_LIBRARY_PATH=/tmp/protobuf/lib
     42 export LDFLAGS=-L/tmp/protobuf/lib
     43 export CXXFLAGS="-I/tmp/protobuf/include"
     44 
     45 ./gradlew clean $GRADLE_FLAGS
     46 
     47 if [[ -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
     65 fi
     66 
     67 LOCAL_MVN_TEMP=$(mktemp -d)
     68 # Note that this disables parallel=true from GRADLE_FLAGS
     69 if [[ -z "${ALL_ARTIFACTS:-}" ]]; then
     70   ./gradlew grpc-compiler:build grpc-compiler:uploadArchives $GRADLE_FLAGS \
     71     -Dorg.gradle.parallel=false -PrepositoryDir=$LOCAL_MVN_TEMP
     72 else
     73   ./gradlew uploadArchives $GRADLE_FLAGS \
     74     -Dorg.gradle.parallel=false -PrepositoryDir=$LOCAL_MVN_TEMP
     75 fi
     76 
     77 readonly MVN_ARTIFACT_DIR="${MVN_ARTIFACT_DIR:-$GRPC_JAVA_DIR/mvn-artifacts}"
     78 
     79 mkdir -p "$MVN_ARTIFACT_DIR"
     80 cp -r "$LOCAL_MVN_TEMP"/* "$MVN_ARTIFACT_DIR"/
     81