-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sh
308 lines (257 loc) · 8.12 KB
/
build.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/env bash
#
# Copyright (c) 2018-2021 Stéphane Micheloud
#
# Licensed under the MIT License.
#
##############################################################################
## Subroutines
getHome() {
local source="${BASH_SOURCE[0]}"
while [ -h "$source" ] ; do
local linked="$(readlink "$source")"
local dir="$( cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pwd )"
source="$dir/$(basename "$linked")"
done
( cd -P "$(dirname "$source")" && pwd )
}
debug() {
local debug_label="[46m[DEBUG][0m"
$DEBUG && echo "$debug_label $1" 1>&2
}
error() {
local error_label="[91mError:[0m"
echo "$error_label $1" 1>&2
}
# use variables EXITCODE, TIMER_START
cleanup() {
[[ $1 =~ ^[0-1]$ ]] && EXITCODE=$1
if $TIMER; then
local timer_end=$(date +'%s')
local duration=$((timer_end - TIMER_START))
echo "Total elapsed time: $(date -d @$duration +'%H:%M:%S')" 1>&2
fi
debug "EXITCODE=$EXITCODE"
exit $EXITCODE
}
args() {
[[ $# -eq 0 ]] && HELP=true && return 1
for arg in "$@"; do
case "$arg" in
## options
-debug) DEBUG=true ;;
-help) HELP=true ;;
-timer) TIMER=true ;;
-*)
error "Unknown option $arg"
EXITCODE=1 && return 0
;;
## subcommands
arch|archives) CLONE=true & COMPILE=true & BOOTSTRAPPED=true & ARCHIVES=true ;;
boot|bootstrap) CLONE=true & COMPILE=true & BOOTSTRAPPED=true ;;
clean) CLEAN=true ;;
clone) CLONE=true ;;
community) COMMUNITY_BUILD=true ;;
compile) COMPILE=true ;;
doc|documentation) COMPILE=true & BOOTSTRAPPED=true & COMMUNITY_BUILD=true & DOCUMENTATION=true ;;
help) HELP=true ;;
java11) CLONE=true & JAVA11=true ;;
update) UPDATE=true ;;
*)
error "Unknown subcommand $arg"
EXITCODE=1 && return 0
;;
esac
done
debug "BOOTSTRAPPED=$BOOTSTRAPPED CLEAN=$CLEAN CLONE=$CLONE COMPILE=$COMPILE HELP=$HELP TIMER=$TIMER"
# See http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/
$TIMER && TIMER_START=$(date +"%s")
}
help() {
cat << EOS
Usage: $BASENAME { <option> | <subcommand> }
Options:
-debug show commands executed by this script
-timer display total elapsed time
Subcommands:
arch[ives] generate gz/zip archives (after bootstrap)
boot[strap] generate+test bootstrapped compiler (after compile)
clean delete generated files
clone update submodules
compile generate+test 1st stage compiler (after clone)
community test community-build
doc[umentation] generate documentation (after bootstrap)
help display this help message
java11 generate+test Dotty compiler with Java 11
sbt test sbt-dotty (after bootstrap)
update fetch/merge upstream repository
EOS
}
clone() {
debug "$GIT_CMD submodule sync"
$GIT_CMD submodule sync
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
debug "$GIT_CMD submodule update --init --recursive --jobs 7"
$GIT_CMD submodule update --init --recursive --jobs 7
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
}
update() {
debug "$GIT_CMD fetch upstream master"
$GIT_CMD fetch upstream master
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
debug "$GIT_CMD merge upstream master"
$GIT_CMD merge upstream/master
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
}
clean() {
echo "${COLOR_START}run sbt clean${COLOR_END}"
debug "$SCRIPTS_DIR/sbt clean"
$SCRIPTS_DIR/sbt clean
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
#debug "$GIT_CMD clean -xdf --exclude=*.bat --exclude=*.ps1 --exclude=*.sh"
#$GIT_CMD clean -xdf --exclude=*.bat --exclude=*.ps1 --exclude=build.sh
#[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
}
test_compiled() {
echo "${COLOR_START}sbt compile and sbt test${COLOR_END}"
debug "$SCRIPTS_DIR/sbt \";compile ;test\""
$SCRIPTS_DIR/sbt ";compile ;test"
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
debug "$SCRIPTS_DIR/cmdTests"
$SCRIPTS_DIR/cmdTests
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
}
test_bootstrapped() {
echo "${COLOR_START}sbt dotty-bootstrapped/compile and sbt dotty-bootstrapped/test${COLOR_END}"
debug "$SCRIPTS_DIR/sbt \";dotty-bootstrapped/compile ;dotty-bootstrapped/test\""
$SCRIPTS_DIR/sbt ";dotty-bootstrapped/compile ;dotty-bootstrapped/test ;dotty-staging/test ;sjsSandbox/run;sjsSandbox/test;sjsJUnitTests/test"
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
debug "$SCRIPTS_DIR/bootstrapCmdTests"
$SCRIPTS_DIR/bootstrapCmdTests
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
}
community_build() {
echo "${COLOR_START}sbt community-build/test${COLOR_END}"
debug "$GIT_CMD submodule sync"
$GIT_CMD submodule sync
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
debug "$GIT_CMD submodule update --init --recursive --jobs 7"
$GIT_CMD submodule update --init --recursive --jobs 7
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
debug "$SCRIPTS_DIR/sbt community-build/test"
$SCRIPTS_DIR/sbt community-build/test
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
return true
}
test_sbt() {
debug "$SCRIPTS_DIR/sbt sbt-dotty/scripted"
$SCRIPTS_DIR/sbt sbt-dotty/scripted
[[ $? -eq 0 ]] || ( EXITCODE=1 && return $EXITCODE )
}
test_java11() {
echo "${COLOR_START}sbt compile and sbt test (Java 11)${COLOR_END}"
[[ -z "$JDK11_HOME" ]] && EXITCODE=1 && return 0
local OLD_PATH=$PATH
export PATH="$JDK11_HOME/bin:$PATH"
debug "$SCRIPTS_DIR/sbt \";compile ;test\""
$SCRIPTS_DIR/sbt ";compile ;test"
[[ $? -eq 0 ]] || ( EXITCODE=1 && PATH=$OLD_PATH && return 0 )
PATH=$OLD_PATH
}
documentation() {
debug "$SCRIPTS_DIR/genDocs"
$SCRIPTS_DIR/genDocs
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
}
archives() {
debug "$SCRIPTS_DIR/sbt dist-bootstrapped/packArchive"
$SCRIPTS_DIR/sbt dist-bootstrapped/packArchive
[[ $? -eq 0 ]] || ( EXITCODE=1 && return 0 )
if $DEBUG; then
echo ""
echo "Output directory: dist-bootstrapped\target" 1>&2
find "$TOOL_HOME/dist-bootstrapped/target" -maxdepth 1 -type f
fi
}
##############################################################################
## Environment setup
BASENAME=$(basename "${BASH_SOURCE[0]}")
EXITCODE=0
TOOL_HOME="$(getHome)"
SCRIPTS_DIR=$TOOL_HOME/project/scripts
[[ -d "$SCRIPTS_DIR" ]] || cleanup 1
ARCHIVES=false
BOOTSTRAPPED=false
CLEAN=false
CLONE=false
COMMUNITY_BUILD=false
COMPILE=false
DEBUG=false
DOCUMENTATION=false
JAVA11=false
HELP=false
SBT=false
TIMER=false
UPDATE=false
COLOR_START="[32m"
COLOR_END="[0m"
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
"msys"*|"cygwin"*|"mingw"*)
GIT_CMD="$(which git).exe"
JAVA_CMD="$(which java).exe"
SBT_CMD="$(which sbt).bat"
;;
*)
GIT_CMD="$(which git)"
JAVA_CMD="$(which java)"
SBT_CMD="$(which sbt)"
;;
esac
## sbt build tool requires Java 8+ to be in PATH
if [[ ! -x "$JAVA_CMD" ]]; then
error "Java command not found"
cleanup 1
fi
## dotty is a sbt project
if [[ ! -f "$SBT_CMD" ]]; then
error "sbt build tool not found"
cleanup 1
fi
args "$@"
[[ $EXITCODE -eq 0 ]] || cleanup 1
##############################################################################
## Main
$HELP && help && cleanup
if $CLONE; then
clone || cleanup 1
fi
if $UPDATE; then
update || cleanup 1
fi
if $CLEAN; then
clean || cleanup 1
fi
if $COMPILE; then
test_compiled || cleanup 1
fi
if $BOOTSTRAPPED; then
test_bootstrapped || cleanup 1
fi
if $COMMUNITY_BUILD; then
community_build || cleanup 1
fi
if $SBT; then
test_sbt || cleanup 1
fi
if $JAVA11; then
test_java11 || cleanup 1
fi
if $DOCUMENTATION; then
documentation || cleanup 1
fi
if $ARCHIVES; then
archives || cleanup 1
fi
##############################################################################
## Cleanups
cleanup