mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
133 lines
4.3 KiB
Bash
Executable file
133 lines
4.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -uexo pipefail
|
|
|
|
HOST_DMD_VER=2.072.2 # same as in dmd/src/posix.mak
|
|
CURL_USER_AGENT="CirleCI $(curl --version | head -n 1)"
|
|
N=2
|
|
CIRCLE_NODE_INDEX=${CIRCLE_NODE_INDEX:-0}
|
|
CIRCLE_PROJECT_REPONAME=${CIRCLE_PROJECT_REPONAME:-dmd}
|
|
|
|
case $CIRCLE_NODE_INDEX in
|
|
0) MODEL=64 ;;
|
|
1) MODEL=32 ;;
|
|
esac
|
|
|
|
# clone druntime and phobos
|
|
clone() {
|
|
local url="$1"
|
|
local path="$2"
|
|
local branch="$3"
|
|
for i in {0..4}; do
|
|
if git clone --branch "$branch" "$url" "$path" "${@:4}"; then
|
|
break
|
|
elif [ $i -lt 4 ]; then
|
|
sleep $((1 << $i))
|
|
else
|
|
echo "Failed to clone: ${url}"
|
|
exit 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
download() {
|
|
local url="$1"
|
|
local fallbackurl="$2"
|
|
local outputfile="$3"
|
|
for i in {0..4}; do
|
|
if curl -fsS -A "$CURL_USER_AGENT" --max-time 5 "$url" -o "$outputfile" ||
|
|
curl -fsS -A "$CURL_USER_AGENT" --max-time 5 "$fallbackurl" -o "$outputfile" ; then
|
|
break
|
|
elif [ $i -ge 4 ]; then
|
|
sleep $((1 << $i))
|
|
else
|
|
echo "Failed to download script ${outputfile}" 1>&2
|
|
exit 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
install_deps() {
|
|
if [ $MODEL -eq 32 ]; then
|
|
sudo apt-get update --quiet=2
|
|
sudo aptitude install g++-multilib --assume-yes --quiet=2
|
|
fi
|
|
|
|
download "https://dlang.org/install.sh" "https://nightlies.dlang.org/install.sh" "install.sh"
|
|
|
|
source "$(CURL_USER_AGENT=\"$CURL_USER_AGENT\" bash install.sh dmd-$HOST_DMD_VER --activate)"
|
|
$DC --version
|
|
env
|
|
}
|
|
|
|
setup_repos() {
|
|
# set a default in case we run into rate limit restrictions
|
|
local base_branch=""
|
|
if [ -n "${CIRCLE_PR_NUMBER:-}" ]; then
|
|
base_branch=$((curl -fsSL https://api.github.com/repos/dlang/$CIRCLE_PROJECT_REPONAME/pulls/$CIRCLE_PR_NUMBER || echo) | jq -r '.base.ref')
|
|
else
|
|
base_branch=$CIRCLE_BRANCH
|
|
fi
|
|
base_branch=${base_branch:-"master"}
|
|
|
|
# merge testee PR with base branch (master) before testing
|
|
if [ -n "${CIRCLE_PR_NUMBER:-}" ]; then
|
|
local head=$(git rev-parse HEAD)
|
|
git fetch https://github.com/dlang/$CIRCLE_PROJECT_REPONAME.git $base_branch
|
|
git checkout -f FETCH_HEAD
|
|
local base=$(git rev-parse HEAD)
|
|
git config user.name 'CI'
|
|
git config user.email '<>'
|
|
git merge -m "Merge $head into $base" $head
|
|
fi
|
|
|
|
for proj in druntime phobos; do
|
|
if [ $base_branch != master ] && [ $base_branch != stable ] &&
|
|
! git ls-remote --exit-code --heads https://github.com/dlang/$proj.git $base_branch > /dev/null; then
|
|
# use master as fallback for other repos to test feature branches
|
|
clone https://github.com/dlang/$proj.git ../$proj master --depth 1
|
|
else
|
|
clone https://github.com/dlang/$proj.git ../$proj $base_branch --depth 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
coverage()
|
|
{
|
|
# load environment for bootstrap compiler
|
|
source "$(CURL_USER_AGENT=\"$CURL_USER_AGENT\" bash ~/dlang/install.sh dmd-$HOST_DMD_VER --activate)"
|
|
|
|
# build dmd, druntime, and phobos
|
|
make -j$N -C src -f posix.mak MODEL=$MODEL HOST_DMD=$DMD all
|
|
make -j$N -C ../druntime -f posix.mak MODEL=$MODEL
|
|
make -j$N -C ../phobos -f posix.mak MODEL=$MODEL
|
|
|
|
# rebuild dmd with coverage enabled
|
|
# use the just build dmd as host compiler this time
|
|
local build_path=generated/linux/release/$MODEL
|
|
# `generated` gets cleaned in the next step, so we create another _generated
|
|
# The nested folder hierarchy is needed to conform to those specified in
|
|
# the generate dmd.conf
|
|
mkdir -p _${build_path}
|
|
cp $build_path/dmd _${build_path}/host_dmd
|
|
cp $build_path/dmd.conf _${build_path}
|
|
make -j$N -C src -f posix.mak MODEL=$MODEL HOST_DMD=../_${build_path}/host_dmd clean
|
|
make -j$N -C src -f posix.mak MODEL=$MODEL HOST_DMD=../_${build_path}/host_dmd ENABLE_COVERAGE=1
|
|
|
|
make -j1 -C test MODEL=$MODEL ARGS="-O -inline -release" DMD_TEST_COVERAGE=1
|
|
}
|
|
|
|
codecov()
|
|
{
|
|
# CodeCov gets confused by lst files which it can't matched
|
|
rm -rf test/runnable/extra-files
|
|
download "https://codecov.io/bash" "https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov" "codecov.sh"
|
|
bash codecov.sh
|
|
}
|
|
|
|
case $1 in
|
|
install-deps) install_deps ;;
|
|
setup-repos) setup_repos ;;
|
|
coverage) coverage ;;
|
|
codecov) codecov ;;
|
|
esac
|