blob: 4ca6ae24852c7fc81c26c359b82c30a51a47687f [file] [log] [blame]
#!/bin/bash
# Copyright 2016 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Shell script containing the main build phase for all bazel_github_job-s
set -e
set +x
BAZEL=~/.bazel/${BAZEL_VERSION}/bin/bazel
ROOT="${PWD}"
TEST_TAG_FILTERS="{{ variables.TEST_TAG_FILTERS }}"
BUILD_TAG_FILTERS=""
cat >${ROOT}/bazel.bazelrc <<EOF
import %workspace%/.bazelrc
build {{ variables.BUILD_OPTS }}
test {{ variables.TEST_OPTS }}
test --test_tag_filters ${TEST_TAG_FILTERS}
EOF
if [[ ! -z "${BUILD_TAG_FILTERS}" ]];
then
echo "build --build_tag_filters ${BUILD_TAG_FILTERS}" >> ${ROOT}/bazel.bazelrc
fi
if [[ "${PLATFORM_NAME}" =~ .*darwin.* ]] && \
xcodebuild -showsdks 2> /dev/null | grep -q '\-sdk iphonesimulator'; then
cat >>${ROOT}/bazel.bazelrc <<EOF
build --define IPHONE_SDK=1
EOF
fi
rm -f .unstable
mkdir -p .bin
cat <<EOF >.bin/bazel
#!/bin/bash
retCode=0
${BAZEL} --bazelrc=${ROOT}/bazel.bazelrc "\$@" || retCode=\$?
# Bazel returns 3 if there was test failures but no breakge
if [[ "\$retCode" -eq "3" ]]; then
# Write 1 in the .unstable file so the following step in Jenkins
# know that it is a test failure.
echo 1 >"${ROOT}/.unstable"
elif [[ "\$retCode" -ne "0" ]]; then
# Else simply fails the job by exiting with a non null return code
exit \$retCode
fi
EOF
chmod +x .bin/bazel
export PATH="${PWD}/.bin:${PATH}"
cd {{ variables.WORKSPACE }}
touch .bazelrc
echo "==== bazel version ===="
bazel version
echo
echo
set -x
{{ variables.CONFIGURE }}
TESTS='{{ variables.TESTS }}'
[ -z "${TESTS}" ] || TESTS="$(bazel query "tests(${TESTS})")"
[ -z "{{ variables.BUILDS }}" ] || bazel build {{ variables.BUILDS }}
[ -z "${TESTS}" ] || bazel test ${TESTS}