-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon
240 lines (196 loc) · 4.94 KB
/
common
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
#!/bin/bash
# Code shared between autobuild and buildstats.
# Color code escape character.
esc="$(printf '\033')"
disable_color() {
red='' ; green='' ; yellow='' ; blue='' ; pink='' ; cyan='' ; white=''
dim_red='' ; dim_green='' ; dim_yellow='' ; dim_blue='' ; dim_pink=''
dim_cyan='' ; dim_white='' ; reset=''
}
disable_color
if [ -t 1 ] && [ "$(tput colors 2> /dev/null)" != -1 ] ; then
red="$(printf '\033[1;31m')"
green="$(printf '\033[1;32m')"
yellow="$(printf '\033[1;33m')"
blue="$(printf '\033[1;34m')"
pink="$(printf '\033[1;35m')"
cyan="$(printf '\033[1;36m')"
white="$(printf '\033[1;37m')"
dim_red="$(printf '\033[0;31m')"
dim_green="$(printf '\033[0;32m')"
dim_yellow="$(printf '\033[0;33m')"
dim_blue="$(printf '\033[0;34m')"
dim_pink="$(printf '\033[0;35m')"
dim_cyan="$(printf '\033[0;36m')"
dim_white="$(printf '\033[0;37m')"
reset="$(printf '\033[0m')"
fi
die() {
echo "$1"
exit 1
}
true=0
false=1
flags=( )
force=0
fetch=1
project=''
args=( )
jobs=0
selected_branch=''
for arg in "$@" ; do
case "$arg" in
-f|--force) force=1 ; flags+=( --force ) ;;
-n|--nofetch) fetch=0 ; flags+=( --nofetch ) ;;
-p|--project) project=0 ; flags+=( --project );;
-j*) jobs="${arg#-j}" ; flags+=( --jobs="$jobs" );;
--jobs=*) jobs="${arg#--jobs=}" ; flags+=( --jobs="$jobs" ) ;;
--branch=*) selected_branch="${arg#--branch=}" ; flags+=( --branch="$selected_branch" );;
*) [ -z "$project" ] && project="$arg" && continue
args+=( "$arg" )
esac
done
set -- "${args[@]}"
if [ -z "$project" ] || [ "$project" = '*' ] ; then
for project in $(find projects -type f ! -name '*.*' -printf '%f\n' | sort) ; do
printf ':: %s\n' "$project"
"$0" "${flags[@]}" "$project" "${args[@]}"
done
exit
fi
_merge_config() {
local var="$1"
local separator="$2"
eval "if [ ! -z \"\${${var}[\$source]}\" ] ; then
[ ! -z \"\${${var}[\$target]}\" ] && ${var}[\$target]+=\"$separator\"
${var}[\$target]+=\"\${${var}[\$source]}\"
fi"
}
_copy_config() {
local var="$1"
eval "if [ ! -z \"\${${var}[\$source]}\" ] ; then
[ ! -z \"\${${var}[\$target]}\" ] \\
&& die \"Cannot merge config \$source into \$target: ${var} already set!\"
${var}[\$target]=\"\${${var}[\$source]}\"
fi"
}
merge_config() {
local target="$1"
local source="$2"
_merge_config cmake_options ' '
_merge_config compiler_options ' '
_merge_config linker_options ' '
_copy_config config_command
_copy_config make_command
_merge_config prefix_paths ';'
}
. "$here/config"
[ -f "$here/config.local" ] && . "$here/config.local"
[ -f "$here/projects/$project" ] || die "Unknown project: $project"
. "$here/projects/$project"
[ -f "$here/projects/$project.local" ] && . "$here/projects/$project.local"
[ $jobs = 0 ] && jobs="$default_jobs"
html_header() {
local title="$1"
local toroot="$2"
local extra="$3"
printf '<!DOCTYPE html>\n'
printf '<html><head><meta charset="utf-8">\n<title>%s</title>\n' "$title"
for favicon in "${!favicons[@]}" ; do
case "$favicon" in /*) url="$favicon" ;; *) url="$toroot/$favicon" ;; esac
case "$favicon" in
*.ico)
printf '<link rel="shortcut icon" href="%s">\n' "$url" ;;
*)
sizes="${favicons[$favicon]}"
printf '<link rel="icon" href="%s" sizes="%s">\n' "$url" "$sizes" ;;
esac
done
printf '<link rel="stylesheet" href="%s/console.css" type="text/css">' "$toroot"
printf '%s\n' "$extra"
printf '</head><body>\n'
}
html_footer() {
printf '</body></html>\n'
}
parse_build_type() {
local build_type="$1"
local out_name="$2"
IFS='_' read -ra components <<< "$build_type"
eval "$2=( ${components[@]} )"
}
in_array() {
local needle="$1"
for entry in "${@:2}" ; do
if [ "$entry" == "$needle" ] ; then
true
return
fi
done
false
}
in_wildcard_array() {
local needle="$1"
for entry in "${@:2}" ; do
if [[ "$needle" == $entry ]] ; then
true
return
fi
done
false
}
build_suffixes=(
'.force'
'.ref'
'.old'
'.html'
'.txt'
'-config.txt'
'-options.txt'
'-raw.txt'
'-time.txt'
'-errors.txt'
'-warnings.txt'
'-cache.html'
'-change.txt'
'-results'
)
rmbuild() {
name="$1"
for suffix in "${build_suffixes[@]}" ; do
file="$name$suffix"
[ -f "$file" ] && rm "$file"
[ -d "$file" ] && rm -r "$file"
done
}
rmbuilddir() {
name="$1"
for suffix in "${build_suffixes[@]}" ; do
file="$name$suffix"
[ -d "$file" ] && rm -r "$file"
done
}
is_valid_branch() {
for remote in "${branches[@]}"; do
[[ "$branch" == "${remote##*/}" ]] && return $true
done
return $false
}
relative_path() {
local dir="${1%/}"
local target="$2"
local up=''
# Find the common part of $target and $dir
while [ ! -z "$dir" ] && [ "${target#$dir}" = "${target}" ] ; do
[ "${dir%/*}" = "$dir" ] && dir=''
dir="${dir%/*}"
up="../$up"
done
target="${target#$dir}"
target="${target#/}"
printf '%s' "$up$target"
}
# Escape for use in a sed replacement string
escape_sed() {
sed 's/\([\\\*\.\^\$\/]\|\[\|\]\)/\\\1/g' | perl -pe 's/\n/\\\n/'
}