1#!/bin/bash
2# Copyright (c) 2021 Google LLC.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# Linux Build Script.
17
18# Fail on any error.
19set -e
20
21SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
22ROOT_DIR="$( cd "${SCRIPT_DIR}/../../.." >/dev/null 2>&1 && pwd )"
23
24CONFIG=$1
25COMPILER=$2
26TOOL=$3
27BUILD_SHA=${KOKORO_GITHUB_COMMIT:-$KOKORO_GITHUB_PULL_REQUEST_COMMIT}
28
29docker run --rm -i \
30  --volume "${ROOT_DIR}:${ROOT_DIR}" \
31  --volume "${KOKORO_ARTIFACTS_DIR}:${KOKORO_ARTIFACTS_DIR}" \
32  --workdir "${ROOT_DIR}" \
33  --env SCRIPT_DIR=${SCRIPT_DIR} \
34  --env ROOT_DIR=${ROOT_DIR} \
35  --env CONFIG=${CONFIG} \
36  --env COMPILER=${COMPILER} \
37  --env TOOL=${TOOL} \
38  --env KOKORO_ARTIFACTS_DIR="${KOKORO_ARTIFACTS_DIR}" \
39  --env BUILD_SHA="${BUILD_SHA}" \
40  --entrypoint "${SCRIPT_DIR}/build-docker.sh" \
41  "gcr.io/shaderc-build/radial-build:latest"
42
43
44# chown the given directory to the current user, if it exists.
45# Docker creates files with the root user - this can upset the Kokoro artifact copier.
46function chown_dir() {
47  dir=$1
48  if [[ -d "$dir" ]]; then
49    sudo chown -R "$(id -u):$(id -g)" "$dir"
50  fi
51}
52
53chown_dir "${ROOT_DIR}/build"
54chown_dir "${ROOT_DIR}/external"
55