-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.sh
84 lines (72 loc) · 1.8 KB
/
utils.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
#
# Intended to be sourced from other scripts.
#
# Contains common utilities for bootstrap.sh and build.sh
#
function green() {
echo -e "\033[1;32;40m"$@"\033[0m"
}
function red() {
echo -e "\033[1;31;40m"$@"\033[0m"
}
function start_clock() {
CLOCK_START=$(date +%s)
echo -n "$1..."
}
function ok() {
local STOP=$(date +%s)
if [ -t 1 ]; then
echo -e -n "\b\b\b [$(green ok)]"
else
echo -n " ok!"
fi
echo " ($((STOP-CLOCK_START))s)"
}
function fail() {
local STOP=$(date +%s)
if [ -t 1 ]; then
echo -e -n "\b\b\b [$(red FAILED)]"
else
echo -n " FAILED!"
fi
echo " ($((STOP-CLOCK_START))s)"
echo "--log start--"
cat $1
echo "--log end--"
exit 1
}
EXIT_HOOKS=""
function run_exit_hooks() {
for hook in $EXIT_HOOKS; do
eval "$hook" || true
done
}
function on_exit() {
EXIT_HOOKS="$EXIT_HOOKS $@"
trap run_exit_hooks EXIT
}
function on_exit_if_tty() {
if [ -t 1 ]; then
on_exit "$@"
fi
}
function write_build_info() {
# Overwrite default "unknown-version" with git describe
local v=foo/lang/build_info.foo
echo '---' > $v
echo 'Generated by write_built_info in utils.sh, DO NOT COMMIT! Replaced by the' >> $v
echo 'default "unknown-version" once the build has finished.' >> $v
echo '---' >> $v
echo 'define Version' >> $v
echo ' "'$(git describe --tags --dirty 2> /dev/null || echo "version-info-missing")'"!' >> $v
}
function restore_build_info() {
git checkout --quiet HEAD foo/lang/build_info.foo
}
function exename() {
if [ -z "${WINDIR:-}" ]; then
echo "$1"
else
echo "$1.exe"
fi
}