#!/bin/bash1# Copyright (c) 2021 Google LLC.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14#15# Linux Build Script.1617# Fail on any error.18set -e1920SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"21ROOT_DIR="$( cd "${SCRIPT_DIR}/../.." >/dev/null 2>&1 && pwd )"2223BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}2425# chown the given directory to the current user, if it exists.26# Docker creates files with the root user - this can upset the Kokoro artifact copier.27function chown_dir() {28dir=$129if [[ -d "$dir" ]]; then30sudo chown -R "$(id -u):$(id -g)" "$dir"31fi32}3334set +e35# Allow build failures3637# "--privileged" is required to run ptrace in the asan builds.38docker run --rm -i \39--privileged \40--volume "${ROOT_DIR}:${ROOT_DIR}" \41--volume "${KOKORO_ARTIFACTS_DIR}:${KOKORO_ARTIFACTS_DIR}" \42--workdir "${ROOT_DIR}" \43--env SCRIPT_DIR=${SCRIPT_DIR} \44--env ROOT_DIR=${ROOT_DIR} \45--env KOKORO_ARTIFACTS_DIR="${KOKORO_ARTIFACTS_DIR}" \46--env BUILD_SHA="${BUILD_SHA}" \47--entrypoint "${SCRIPT_DIR}/build-docker.sh" \48"gcr.io/shaderc-build/radial-build:latest"49RESULT=$?5051# This is important. If the permissions are not fixed, kokoro will fail52# to pull build artifacts, and put the build in tool-failure state, which53# blocks the logs.54chown_dir "${ROOT_DIR}/build"55exit $RESULT565758