-
Notifications
You must be signed in to change notification settings - Fork 0
/
bazel.sh
executable file
·109 lines (94 loc) · 3.59 KB
/
bazel.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env bash
set -euo pipefail
##############################################################
# The canonical home of this script is:
# https://gitlab.tableausoftware.com/tableaubuild/bazel/bootstrapper/-/blob/main/src/bazel.sh
#
# Do not edit it anywhere else.
#
# If you want to consume it in a new location, talk to dpe-codex-buildsys about adding your usage to deploy.py
##############################################################
self=`basename "$0"`
currentArch=$(uname -m)
ensureHaveBazel()
{
bazelVersion=`cat $(dirname "$BASH_SOURCE")/.bazelversion | tr -d '\r'`
bazelCacheDirectory=`echo ~/.cache/tabbazel`
# Note that old JDKs in the cache will not get garbage collected, and will
# continue to be noticed by security scans. When you change the JDK version,
# consider taking some step to mitigate that, such as notifying users or
# adding a step to delete unpatched JDKs in the cache.
#
# These paths come from https://swarm.tsi.lan/files/depot/teams/near/tableau-support/java/java.properties
if [[ "$OSTYPE" == "darwin"* ]]
then
if [[ "$currentArch" == "x86_64" ]]
then
bazelJdkArtifactoryUrl="thirdparty/openjdk/azul/11.0.14/zulu11.54.26-sa-jdk+jre11.0.14-osx_x64.tar.gz"
else
bazelJdkArtifactoryUrl="thirdparty/openjdk/azul/11.0.19/zulu11.64.19-ca-jdk11.0.19-macosx_aarch64.tar.gz"
fi
else
bazelJdkArtifactoryUrl="thirdparty/openjdk/azul/11.0.14/zulu11.54.26-sa-jdk+jre11.0.14-linux_x64-sfdc.3-tableau.tar.gz"
fi
bazelJdkPackageName=$( basename $bazelJdkArtifactoryUrl .tar.gz )
export JAVA_HOME=$bazelCacheDirectory/jdk/$bazelJdkPackageName/
mkdir -p $bazelCacheDirectory/$bazelVersion-$currentArch
bazelBinaryPath=$bazelCacheDirectory/$bazelVersion-$currentArch/bazel
if [ ! -f $bazelBinaryPath ]
then
runHealthChecks
downloadBazel
fi
if [ ! -d $JAVA_HOME ]
then
downloadJdk
fi
}
runHealthChecks()
{
echo "${self}: running machine health checks" 1>&2
dir="$(dirname "$BASH_SOURCE")/bazel/bootstrapper_health_checks/"
if [ -d ${dir} ]
then
find ${dir} -name "*.sh" -type f -print0 | xargs -0 -n1 sh
fi
}
downloadBazel()
{
if [[ "$OSTYPE" == "darwin"* ]]
then
operatingSystem="darwin"
else
operatingSystem="linux"
fi
# Release candidates are published to a different location than prerelease and full release, and so are not cached in Artifactory
if [[ $bazelVersion == *rc* ]]
then
url="https://releases.bazel.build/${bazelVersion%%rc*}/rc${bazelVersion#*"rc"}/bazel_nojdk-$bazelVersion-$operatingSystem-${currentArch}"
else
url="https://artifactory.prod.tableautools.com/artifactory/bazel-releases-remote/download/$bazelVersion/bazel_nojdk-$bazelVersion-$operatingSystem-${currentArch}"
fi
echo "${self}: Downloading bazel binary from '$url' to '$bazelBinaryPath'" 1>&2
outputFile=`mktemp -u`
curl --fail --location --output $outputFile $url 1>&2
mv $outputFile $bazelBinaryPath
chmod +x $bazelBinaryPath
}
downloadJdk()
{
url="https://artifactory.prod.tableautools.com/artifactory/$bazelJdkArtifactoryUrl"
echo "${self}: Downloading JDK from '$url' to '$JAVA_HOME'" 1>&2
outputFile=`mktemp -u`.tar.gz
curl --fail --silent --location --output $outputFile $url
mkdir -p $bazelCacheDirectory/jdk
tar -xzf $outputFile -C $bazelCacheDirectory/jdk
if [ ! -d $JAVA_HOME ]
then
echo "JDK not found at $JAVA_HOME" 1>&2
exit 1
fi
}
ensureHaveBazel
cd "$(dirname "$BASH_SOURCE")"
$bazelBinaryPath $*