2021-03-17 18:52:03 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Copyright 2021 The Tint Authors.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
# https://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.
|
|
|
|
|
2022-02-18 14:15:50 +00:00
|
|
|
# This is the bash script invoked inside a docker container.
|
|
|
|
# The script expects that the CWD points to a clean checkout of Tint.
|
|
|
|
# As `gclient sync` will litter the tint checkout with fetched tools and
|
|
|
|
# projects, this script will first clone the pristine tint checkout to
|
|
|
|
# ${SRC_DIR}. This allows developers to locally run this script without having
|
|
|
|
# to worry about their local tint copy being touched.
|
|
|
|
#
|
|
|
|
# This script expects the following environment variables to be set on entry:
|
|
|
|
#
|
|
|
|
# SRC_DIR - Path to where the local Tint copy will be made. See above.
|
|
|
|
# BUILD_DIR - Path to where Tint will be built.
|
|
|
|
# BUILD_TYPE - Either: 'Debug' or 'Release'
|
|
|
|
# BUILD_SYSTEM - Must be 'cmake'
|
|
|
|
# BUILD_SANITIZER - Either: '', 'asan', or 'ubstan'
|
|
|
|
# BUILD_TOOLCHAIN - Either: 'clang' or 'gcc'
|
|
|
|
|
2021-03-17 18:52:03 +00:00
|
|
|
set -e # Fail on any error.
|
|
|
|
|
|
|
|
function show_cmds { set -x; }
|
|
|
|
function hide_cmds { { set +x; } 2>/dev/null; }
|
2021-03-19 20:48:50 +00:00
|
|
|
function task_begin {
|
|
|
|
TASK_NAME="$@"
|
|
|
|
SECONDS=0
|
|
|
|
}
|
|
|
|
function print_last_task_duration {
|
|
|
|
if [ ! -z "${TASK_NAME}" ]; then
|
|
|
|
echo "${TASK_NAME} completed in $(($SECONDS / 3600))h$((($SECONDS / 60) % 60))m$(($SECONDS % 60))s"
|
|
|
|
fi
|
|
|
|
}
|
2021-03-17 18:52:03 +00:00
|
|
|
function status {
|
2021-03-19 20:48:50 +00:00
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
print_last_task_duration
|
2021-03-17 18:52:03 +00:00
|
|
|
echo ""
|
|
|
|
echo "*****************************************************************"
|
|
|
|
echo "* $@"
|
|
|
|
echo "*****************************************************************"
|
|
|
|
echo ""
|
2021-03-19 20:48:50 +00:00
|
|
|
task_begin $@
|
2021-03-17 18:52:03 +00:00
|
|
|
}
|
2021-04-28 08:59:03 +00:00
|
|
|
function with_retry {
|
|
|
|
local MAX_ATTEMPTS=5
|
|
|
|
local RETRY_DELAY_SECS=5
|
|
|
|
local ATTEMPT=1
|
|
|
|
while true; do
|
|
|
|
"$@" && break
|
|
|
|
if [[ $ATTEMPT -ge $MAX_ATTEMPTS ]]; then
|
|
|
|
echo "The command has failed after $ATTEMPT attempts."
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
((ATTEMPT++))
|
|
|
|
echo "'$@' failed. Attempt ($ATTEMPT/$MAX_ATTEMPTS). Retrying..."
|
|
|
|
sleep $RETRY_DELAY_SECS;
|
|
|
|
done
|
|
|
|
}
|
2021-03-17 18:52:03 +00:00
|
|
|
|
2021-09-20 19:30:35 +00:00
|
|
|
CLONE_SRC_DIR="$(pwd)"
|
2021-03-19 22:08:20 +00:00
|
|
|
|
2021-03-17 18:52:03 +00:00
|
|
|
. /bin/using.sh # Declare the bash `using` function for configuring toolchains.
|
|
|
|
|
2021-03-19 22:08:20 +00:00
|
|
|
using depot_tools
|
2021-05-12 08:15:41 +00:00
|
|
|
using go-1.14.4 # Speeds up ./tools/lint
|
|
|
|
using doxygen-1.8.18
|
2021-03-17 18:52:03 +00:00
|
|
|
|
2022-02-18 14:15:50 +00:00
|
|
|
status "Creating source directory '${SRC_DIR}' and build directory '${BUILD_DIR}'"
|
2021-03-17 18:52:03 +00:00
|
|
|
mkdir -p ${SRC_DIR}
|
2022-02-18 14:15:50 +00:00
|
|
|
mkdir -p ${BUILD_DIR}
|
|
|
|
|
|
|
|
status "Cloning to source directory '${SRC_DIR}'"
|
2021-03-17 18:52:03 +00:00
|
|
|
cd ${SRC_DIR}
|
2021-09-20 19:30:35 +00:00
|
|
|
git clone ${CLONE_SRC_DIR} .
|
2021-03-17 18:52:03 +00:00
|
|
|
|
|
|
|
status "Fetching dependencies"
|
|
|
|
cp standalone.gclient .gclient
|
2021-04-28 08:59:03 +00:00
|
|
|
with_retry gclient sync
|
2021-03-17 18:52:03 +00:00
|
|
|
|
2021-05-12 08:15:41 +00:00
|
|
|
status "Linting"
|
|
|
|
./tools/lint
|
|
|
|
|
2021-03-17 18:52:03 +00:00
|
|
|
status "Configuring build system"
|
|
|
|
if [ "$BUILD_SYSTEM" == "cmake" ]; then
|
|
|
|
using cmake-3.17.2
|
|
|
|
|
|
|
|
COMMON_CMAKE_FLAGS=""
|
|
|
|
COMMON_CMAKE_FLAGS+=" -DCMAKE_BUILD_TYPE=${BUILD_TYPE}"
|
2022-01-18 18:58:16 +00:00
|
|
|
COMMON_CMAKE_FLAGS+=" -DTINT_DOCS_WARN_AS_ERROR=1"
|
|
|
|
COMMON_CMAKE_FLAGS+=" -DTINT_BUILD_BENCHMARKS=1"
|
2021-03-17 18:52:03 +00:00
|
|
|
|
|
|
|
if [ "$BUILD_TOOLCHAIN" == "clang" ]; then
|
|
|
|
using clang-10.0.0
|
2021-06-07 08:07:11 +00:00
|
|
|
COMMON_CMAKE_FLAGS+=" -DTINT_BUILD_FUZZERS=1"
|
2021-08-11 14:10:05 +00:00
|
|
|
COMMON_CMAKE_FLAGS+=" -DTINT_BUILD_SPIRV_TOOLS_FUZZER=1"
|
|
|
|
COMMON_CMAKE_FLAGS+=" -DTINT_BUILD_AST_FUZZER=1"
|
|
|
|
COMMON_CMAKE_FLAGS+=" -DTINT_BUILD_REGEX_FUZZER=1"
|
2021-03-17 18:52:03 +00:00
|
|
|
elif [ "$BUILD_TOOLCHAIN" == "gcc" ]; then
|
|
|
|
using gcc-9
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$BUILD_SANITIZER" == "asan" ]; then
|
|
|
|
COMMON_CMAKE_FLAGS+=" -DTINT_ENABLE_ASAN=1"
|
2021-04-30 15:01:08 +00:00
|
|
|
elif [ "$BUILD_SANITIZER" == "ubsan" ]; then
|
|
|
|
COMMON_CMAKE_FLAGS+=" -DTINT_ENABLE_UBSAN=1"
|
|
|
|
export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
|
2021-03-17 18:52:03 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd ${BUILD_DIR}
|
|
|
|
|
2021-06-25 14:00:36 +00:00
|
|
|
status "Running Doxygen"
|
|
|
|
echo "NOTE: This will fail on first warning. Run with -DTINT_DOCS_WARN_AS_ERROR=OFF to see all warnings".
|
|
|
|
echo ""
|
|
|
|
show_cmds
|
|
|
|
# NOTE: If we upgrade Doxygen to a more recent version, we can set DOXYGEN_WARN_AS_ERROR to
|
|
|
|
# "FAIL_ON_WARNINGS" instead of "YES" in our CMakeLists.txt so see all warnings, and then
|
|
|
|
# fail. See https://www.doxygen.nl/manual/config.html#cfg_warn_as_error
|
|
|
|
cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS}
|
|
|
|
cmake --build . --target tint-docs
|
|
|
|
hide_cmds
|
|
|
|
|
2022-02-18 14:15:50 +00:00
|
|
|
status "Building tint in '${BUILD_DIR}'"
|
2021-03-17 18:52:03 +00:00
|
|
|
show_cmds
|
|
|
|
cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS}
|
2021-06-25 14:00:36 +00:00
|
|
|
cmake --build . -- --jobs=$(nproc)
|
2021-03-17 18:52:03 +00:00
|
|
|
hide_cmds
|
|
|
|
|
|
|
|
status "Running tint_unittests"
|
|
|
|
show_cmds
|
|
|
|
./tint_unittests
|
|
|
|
hide_cmds
|
|
|
|
|
2021-08-11 14:10:05 +00:00
|
|
|
if [ -f ./tint_ast_fuzzer_unittests ]; then
|
|
|
|
status "Running tint_ast_fuzzer_unittests"
|
|
|
|
show_cmds
|
|
|
|
./tint_ast_fuzzer_unittests
|
|
|
|
hide_cmds
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f ./tint_regex_fuzzer_unittests ]; then
|
|
|
|
status "Running tint_regex_fuzzer_unittests"
|
|
|
|
show_cmds
|
|
|
|
./tint_regex_fuzzer_unittests
|
|
|
|
hide_cmds
|
|
|
|
fi
|
|
|
|
|
2022-02-21 15:19:07 +00:00
|
|
|
status "Testing test/tint/test-all.sh"
|
2021-03-17 18:52:03 +00:00
|
|
|
show_cmds
|
2022-02-21 15:19:07 +00:00
|
|
|
${SRC_DIR}/test/tint/test-all.sh "${BUILD_DIR}/tint" --verbose
|
2021-03-17 18:52:03 +00:00
|
|
|
hide_cmds
|
|
|
|
|
2021-04-16 14:43:34 +00:00
|
|
|
status "Checking _other.cc files also build"
|
|
|
|
show_cmds
|
2021-09-03 14:16:56 +00:00
|
|
|
cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS} -DTINT_BUILD_AS_OTHER_OS=ON
|
2021-06-25 14:00:36 +00:00
|
|
|
cmake --build . -- --jobs=$(nproc)
|
2021-09-03 14:16:56 +00:00
|
|
|
cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS} -DTINT_BUILD_AS_OTHER_OS=OFF
|
|
|
|
hide_cmds
|
|
|
|
|
|
|
|
status "Checking disabling all readers and writers also builds"
|
|
|
|
show_cmds
|
2022-01-18 18:58:16 +00:00
|
|
|
cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS} -DTINT_BUILD_SPV_READER=OFF -DTINT_BUILD_SPV_WRITER=OFF -DTINT_BUILD_WGSL_READER=OFF -DTINT_BUILD_WGSL_WRITER=OFF -DTINT_BUILD_MSL_WRITER=OFF -DTINT_BUILD_HLSL_WRITER=OFF -DTINT_BUILD_BENCHMARKS=OFF
|
2021-09-03 14:16:56 +00:00
|
|
|
cmake --build . -- --jobs=$(nproc)
|
2022-01-18 18:58:16 +00:00
|
|
|
cmake ${SRC_DIR} ${CMAKE_FLAGS} ${COMMON_CMAKE_FLAGS} -DTINT_BUILD_SPV_READER=ON -DTINT_BUILD_SPV_WRITER=ON -DTINT_BUILD_WGSL_READER=ON -DTINT_BUILD_WGSL_WRITER=ON -DTINT_BUILD_MSL_WRITER=ON -DTINT_BUILD_HLSL_WRITER=ON -DTINT_BUILD_BENCHMARKS=ON
|
2021-04-16 14:43:34 +00:00
|
|
|
hide_cmds
|
2021-03-17 18:52:03 +00:00
|
|
|
else
|
|
|
|
status "Unsupported build system: $BUILD_SYSTEM"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
status "Done"
|