-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmake.sh
executable file
·89 lines (72 loc) · 1.75 KB
/
make.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
#!/usr/bin/env bash
BAITJS_DIR="$HOME/.bait/baitjs"
# Parse arguments
IS_LOCAL=0
NO_SELF=0
for i in "$@"; do
case $i in
--local)
IS_LOCAL=1
;;
--no-self)
NO_SELF=1
;;
esac
done
download_baitjs() {
# Pull or clone baitjs
if [ -f $BAITJS_DIR/bait.js ]; then
if [ $IS_LOCAL == 0 ]; then
git -C $BAITJS_DIR pull --quiet
fi
elif [ $IS_LOCAL == 0 ]; then
git clone --depth 1 https://github.com/bait-lang/baitjs $BAITJS_DIR
else
echo "baitjs not found locally. Run without \"--local\""
exit 1
fi
}
bootstrap() {
# Backup bait.js
[ -f bait.js ] && mv -f bait.js old_bait.js
# Just compile once (required for implementing breaking changes)
if [ $NO_SELF == 1 ]; then
cp $BAITJS_DIR/bait.js . # Required to set correct value for $BAITDIR, etc.
node bait.js cli/bait.bt -o bait.js
return
fi
# Compile new bait.js and ensure self compilation is working
node $BAITJS_DIR/bait.js cli/bait.bt -o bait1.js
node bait1.js cli/bait.bt -o bait2.js
node bait2.js self -o bait.js
}
check_success() {
allow_retry=$1
if [ -f bait.js ]; then
return
fi
if [ "$allow_retry" = true ] && [ $IS_LOCAL == 0 ]; then
# Pull latest version of Bait
echo "make: compilation failed. Retrying..."
git pull https://github.com/bait-lang/bait main --quiet
# Retry bootstrapping
bootstrap
check_success false
return
fi
echo "make: compilation failed"
exit 1
}
cleanup() {
# Sanity check the file size
if [ $(wc -l bait.js | awk '{print $1}') -le 5000 ]; then
echo "bait.js is too small. Something went wrong."
exit 1
fi
rm -f bait1.js bait2.js
}
download_baitjs
bootstrap
check_success true
cleanup
echo "Run 'sudo ./bait symlink' to add Bait to your path."