forked from dotnet/jitutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·203 lines (164 loc) · 5.5 KB
/
bootstrap.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env bash
# Bootstrap the jitutils tools:
# 1. If this script is run not from within the jitutils directory (e.g., you've downloaded
# a copy of this file directly), then "git clone" the jitutils project first. Otherwise,
# if we can tell we're being run from within an existing "git clone", don't do that.
# 2. Build the jitutils tools.
# 3. Download (if necessary) clang-format and clang-tidy (used by the jit-format tool).
function get_host_os {
# Use uname to determine what the OS is.
OSName=$(uname -s)
case $OSName in
Linux)
__HostOS=Linux
;;
Darwin)
__HostOS=OSX
;;
FreeBSD)
__HostOS=FreeBSD
;;
OpenBSD)
__HostOS=OpenBSD
;;
NetBSD)
__HostOS=NetBSD
;;
SunOS)
__HostOS=SunOS
;;
*)
echo "Unsupported OS $OSName detected, configuring as if for Linux"
__HostOS=Linux
;;
esac
}
function validate_url {
if wget -S --spider $1 2>&1 | grep -e "HTTP/1.1 200 OK";
then
return 0;
else
return 1;
fi
}
function download_tools {
# Do we have wget?
if ! hash wget 2>/dev/null; then
echo "Error: wget not found; not downloading clang-format and clang-tidy."
if [ "$__HostOS" == "OSX" ]; then
echo "On OSX, install wget using Homebrew (https://brew.sh/) using 'brew install wget'."
fi
return 1
fi
# Figure out which version to download. The "RID:" value from "dotnet --info" looks
# like this:
# RID: osx.10.12-x64
info=$(dotnet --info |grep RID:)
info=${info##*RID:* }
clangFormatUrl=https://clrjit.blob.core.windows.net/clang-tools/${info}/clang-format
if validate_url ${clangFormatUrl} > /dev/null; then
echo "Downloading clang-format to bin directory"
# download appropriate version of clang-format
wget --progress=dot:giga ${clangFormatUrl} -O bin/clang-format
chmod 751 bin/clang-format
else
echo "clang-format not found here: ${clangFormatUrl}"
fi
clangTidyUrl=https://clrjit.blob.core.windows.net/clang-tools/${info}/clang-tidy
if validate_url ${clangTidyUrl} > /dev/null; then
echo "Downloading clang-tidy to bin directory"
# download appropriate version of clang-tidy
wget --progress=dot:giga ${clangTidyUrl} -O bin/clang-tidy
chmod 751 bin/clang-tidy
else
echo "clang-tidy not found here: ${clangTidyUrl}"
fi
if [ ! -f bin/clang-format -o ! -f bin/clang-tidy ]; then
echo "Either clang-tidy or clang-format was not installed. Please install and put them on the PATH to use jit-format."
echo "Tools can be found at http://llvm.org/releases/download.html#3.8.0"
return 1
fi
return 0
}
# Start the non-functions.
__ErrMsgPrefix="ERROR: "
get_host_os
# Check if our required tools exist.
if ! hash dotnet 2>/dev/null; then
echo "${__ErrMsgPrefix}Can't find dotnet! Please install from http://dot.net and add to PATH."
exit 1
fi
if ! hash git 2>/dev/null; then
echo "${__ErrMsgPrefix}Can't find git! Please add to PATH."
exit 1
fi
# Are we already in the dotnet/jitutils repo? Or do we need to clone it? We look for build.cmd
# in the directory this script was invoked from.
# Obtain the location of the bash script.
__root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Check if the bootstrap script is in the root of the jitutils repo.
# By default, we're going to clone the repo.
__clone_repo=1
if [ -e ${__root}/build.cmd ]; then
# We found build.cmd. But make sure it's the root of the repo.
__root="$( cd ${__root} && git rev-parse --show-toplevel )"
pushd ${__root} >/dev/null
git remote -v | grep "/jitutils" >/dev/null
if [ $? == 0 ]; then
# We've proven that we're at the root of the jitutils repo.
__clone_repo=0
fi
popd >/dev/null
fi
if [ ${__clone_repo} == 1 ]; then
git clone https://github.com/dotnet/jitutils.git
exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}git clone failed."
exit $exit_code
fi
if [ ! -d ${__root}/jitutils ]; then
echo "${__ErrMsgPrefix}can't find ${__root}/jitutils."
exit 1
fi
pushd ${__root}/jitutils >/dev/null
else
pushd . >/dev/null
fi
# Pull in needed packages. This works globally (due to jitutils.sln).
dotnet restore
exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to restore packages."
exit $exit_code
fi
# Build and publish all the utilties and frameworks
./build.sh -p -f
exit_code=$?
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Build failed."
exit $exit_code
fi
exit_code=0
if ! hash clang-format 2>/dev/null || ! hash clang-tidy 2>/dev/null; then
download_tools
exit_code=$?
else
if ! clang-format --version | grep -q 3.8 || ! clang-tidy --version | grep -q 3.8; then
echo "jit-format requires clang-format and clang-tidy version 3.8.*. Currently installed: "
clang-format --version
clang-tidy --version
echo "Installing version 3.8 of clang tools"
download_tools
exit_code=$?
fi
fi
if [ $exit_code != 0 ]; then
echo "${__ErrMsgPrefix}Failed to download clang-format and clang-tidy."
exit $exit_code
fi
popd >/dev/null
echo "Adding ${__root}/jitutils/bin to PATH"
export PATH=$PATH:${__root}/jitutils/bin
echo "Done setting up!"
exit 0