-
-
Notifications
You must be signed in to change notification settings - Fork 614
/
Copy pathlib.sh
89 lines (79 loc) · 3.13 KB
/
lib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Shared functions between individual scripts
CURL_USER_AGENT="DMD-CI $(curl --version | head -n 1)"
DMD_DIR="$PWD"
N=$(nproc)
clone() {
local url="$1"
local path="$2"
local branch="$3"
if [ ! -d $path ]; then
for i in {0..4}; do
if git clone --depth 1 --branch "$branch" "$url" "$path" "${@:4}" --quiet; then
break
elif [ $i -lt 4 ]; then
sleep $((1 << $i))
else
echo "Failed to clone: ${url}"
exit 1
fi
done
fi
}
download() {
local url="$1"
local path="$2"
curl -fsSL -A "$CURL_USER_AGENT" --retry 5 --retry-max-time 120 --connect-timeout 5 --speed-time 30 --speed-limit 1024 "$url" -o "$path"
}
################################################################################
# Download dmd
################################################################################
install_host_dmd() {
if [ ! -f dmd2/README.TXT ]; then
download "https://downloads.dlang.org/releases/2.x/${HOST_DMD_VERSION}/dmd.${HOST_DMD_VERSION}.windows.7z" dmd2.7z
7z x dmd2.7z > /dev/null
download "https://downloads.dlang.org/other/libcurl-7.65.3-2-WinSSL-zlib-x86-x64.zip" libcurl.zip
7z -y x libcurl.zip > /dev/null
fi
export PATH="$PWD/dmd2/windows/bin/:$PATH"
export HOST_DC="$PWD/dmd2/windows/bin/dmd.exe"
dmd --version
}
################################################################################
# Download Grep
################################################################################
install_grep() {
local tools_dir="${DMD_DIR}/tools"
mkdir -p "$tools_dir"
cd "$tools_dir"
if [ ! -f grep.exe ]; then
download "https://downloads.dlang.org/other/grep-3.1.zip" "grep-3.1.zip"
unzip "grep-3.1.zip" # contains grep.exe
fi
export PATH="${tools_dir}:$PATH"
}
################################################################################
# Checkout other repositories
################################################################################
clone_repos() {
if [ -z ${SYSTEM_PULLREQUEST_TARGETBRANCH+x} ]; then
# no PR
local REPO_BRANCH="$BUILD_SOURCEBRANCHNAME"
elif [ ${SYSTEM_PULLREQUEST_ISFORK} == False ]; then
# PR originating from the official dlang repo
local REPO_BRANCH="$SYSTEM_PULLREQUEST_SOURCEBRANCH"
else
# PR from a fork
local REPO_BRANCH="$SYSTEM_PULLREQUEST_TARGETBRANCH"
fi
for proj in phobos; do
if [ "$REPO_BRANCH" != master ] && [ "$REPO_BRANCH" != stable ] &&
! git ls-remote --exit-code --heads "https://github.com/dlang/$proj.git" "$REPO_BRANCH" > /dev/null; then
# use master as fallback for other repos to test feature branches
clone "https://github.com/dlang/$proj.git" "${DMD_DIR}/../$proj" master
echo "[GIT_CLONE] Switched $proj to branch master \$(REPO_BRANCH=$REPO_BRANCH)"
else
clone "https://github.com/dlang/$proj.git" "${DMD_DIR}/../$proj" "$REPO_BRANCH"
echo "[GIT_CLONE] Switched $proj to branch $REPO_BRANCH"
fi
done
}