-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbootstrap.sh
More file actions
361 lines (316 loc) · 9.38 KB
/
Copy pathbootstrap.sh
File metadata and controls
361 lines (316 loc) · 9.38 KB
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#!/usr/bin/env bash
set -u
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)" || exit 1
root="$script_dir"
conan_dir="$root/conan"
cache_dir="$conan_dir/cache"
profile_override="$conan_dir/profile-override"
base_recipe_dir="$conan_dir/base-recipe"
deps_dir="$root/third-party"
conan_exe=""
cmake_exe=""
ninja_exe=""
do_export=""
install_profile=""
build_profile=""
toolchain_path=""
native_profile="native"
build_env_profile=""
build_type="Release"
deps_only=""
usage() {
cat <<EOF
Usage:
$(basename "$0") setup [--toolchain <toolchain_path>] [--cache <path>]
$(basename "$0") build <profile> [--toolchain <toolchain_path>] [--cache <path>] [--deps-only] [--debug]
Build mode defaults to Release. Pass --debug to use Debug.
Pass --cache to set CONAN_HOME explicitly; the default is conan/cache.
Setup and build use <toolchain_path>/tool/conan/bin/conan when --toolchain is set, otherwise PATH.
Without --toolchain, build requires profile native and uses host profile default + conan/profile-override and build profile default.
With --toolchain, build uses <toolchain_path>/conan/<profile> + conan/profile-override and an OS build profile; profile native is not allowed.
conan build uses <toolchain_path>/tool/cmake/bin/cmake when --toolchain is set, otherwise PATH cmake.
Build and generator directories are build/<profile>-<build-type>.
Pass --deps-only to stop after conan install.
EOF
}
usage_error() {
usage
exit 2
}
parse_toolchain_arg() {
if (($# < 2)); then
echo "error: --toolchain requires a toolchain path." >&2
usage_error
fi
toolchain_path="$2"
}
parse_cache_arg() {
if (($# < 2)); then
echo "error: --cache requires a cache path." >&2
usage_error
fi
cache_dir="$2"
}
parse_setup_args() {
while (($#)); do
case "$1" in
-h|--help)
usage
exit 0
;;
--toolchain)
parse_toolchain_arg "$@"
shift 2
;;
--cache)
parse_cache_arg "$@"
shift 2
;;
*)
echo "error: unknown setup argument: $1" >&2
usage_error
;;
esac
done
}
parse_build_args() {
while (($#)); do
case "$1" in
-h|--help)
usage
exit 0
;;
--toolchain)
parse_toolchain_arg "$@"
shift 2
;;
--cache)
parse_cache_arg "$@"
shift 2
;;
--deps-only)
deps_only=1
shift
;;
--debug)
build_type="Debug"
shift
;;
*)
echo "error: unknown build argument: $1" >&2
usage_error
;;
esac
done
}
while (($#)); do
case "$1" in
-h|--help)
usage
exit 0
;;
setup)
if [[ -n "$do_export" ]]; then
echo "error: setup was specified more than once." >&2
usage_error
fi
do_export=1
shift
parse_setup_args "$@"
break
;;
build)
if (($# < 2)); then
echo "error: build requires a profile name." >&2
usage_error
fi
if [[ -n "$build_profile" ]]; then
echo "error: build was specified more than once." >&2
usage_error
fi
install_profile="$2"
build_profile="$2"
shift 2
parse_build_args "$@"
break
;;
*)
echo "error: unknown command: $1" >&2
usage_error
;;
esac
done
if [[ -z "$do_export" && -z "$install_profile" && -z "$build_profile" ]]; then
usage_error
fi
if [[ -n "$toolchain_path" && ! -d "$toolchain_path" ]]; then
echo "error: toolchain path does not exist: $toolchain_path" >&2
exit 1
fi
validate_profile_mode() {
[[ -n "$install_profile" ]] || return 0
if [[ "$install_profile" == "$native_profile" ]]; then
if [[ -n "$toolchain_path" ]]; then
echo "error: profile $native_profile cannot be used with --toolchain." >&2
return 1
fi
return 0
fi
if [[ -z "$toolchain_path" ]]; then
echo "error: without --toolchain, build profile must be $native_profile." >&2
return 1
fi
}
validate_profile_mode || exit 1
check_executable() {
local exe="$1"
local label="$2"
if [[ "$exe" == */* || "$exe" == *\\* ]]; then
if [[ -x "$exe" ]]; then
return 0
fi
elif command -v -- "$exe" >/dev/null 2>&1; then
return 0
fi
echo "error: $label does not exist or is not on PATH: $exe" >&2
return 1
}
detect_build_env_profile() {
case "$(uname -s 2>/dev/null || echo unknown)" in
MINGW*|MSYS*|CYGWIN*)
build_env_profile="win-x64"
;;
Darwin*)
build_env_profile="macos-arm64"
;;
Linux*)
build_env_profile="linux-x64"
;;
*)
echo "error: unsupported build operating system: $(uname -s 2>/dev/null || echo unknown)" >&2
return 1
;;
esac
}
if [[ -n "$toolchain_path" && -n "$build_profile" ]]; then
detect_build_env_profile || exit 1
fi
mkdir -p -- "$cache_dir" || exit 1
cache_dir="$(cd -- "$cache_dir" && pwd -P)" || exit 1
export CONAN_HOME="$cache_dir"
if [[ -n "$toolchain_path" ]]; then
conan_exe="$toolchain_path/tool/conan/bin/conan"
else
conan_exe="conan"
fi
if ! check_executable "$conan_exe" "Conan executable"; then
echo " Pass --toolchain or make conan available on PATH." >&2
exit 1
fi
if [[ -n "$build_profile" && -z "$deps_only" ]]; then
if [[ -n "$toolchain_path" ]]; then
cmake_exe="$toolchain_path/tool/cmake/bin/cmake"
ninja_exe="$toolchain_path/tool/ninja/bin/ninja"
else
cmake_exe="cmake"
ninja_exe="ninja"
fi
if ! check_executable "$cmake_exe" "CMake executable"; then
echo " Pass --toolchain or make cmake available on PATH." >&2
exit 1
fi
if ! check_executable "$ninja_exe" "Ninja executable"; then
echo " Pass --toolchain or make ninja available on PATH." >&2
exit 1
fi
fi
run_conan() {
printf '+'
printf ' %q' "$conan_exe" "$@"
printf '\n'
"$conan_exe" "$@"
}
export_recipe() {
run_conan export "$1" --user=ysm --channel=stable
}
export_recipes() {
if [[ ! -f "$base_recipe_dir/conanfile.py" ]]; then
echo "error: base recipe does not exist: $base_recipe_dir" >&2
exit 1
fi
if [[ ! -d "$deps_dir" ]]; then
echo "error: dependency recipes directory does not exist: $deps_dir" >&2
exit 1
fi
export_recipe "$base_recipe_dir" || return 1
local found_recipe=""
local recipe_dir
for recipe_dir in "$deps_dir"/*; do
[[ -d "$recipe_dir" ]] || continue
[[ -f "$recipe_dir/conanfile.py" ]] || continue
found_recipe=1
export_recipe "$recipe_dir" || return 1
done
if [[ -z "$found_recipe" ]]; then
echo "error: no dependency recipes found in $deps_dir" >&2
return 1
fi
}
run_conan_with_profile() {
local conan_command="$1"
local profile="$2"
if [[ ! -f "$profile_override" ]]; then
echo "error: project profile override does not exist: $profile_override" >&2
return 1
fi
if [[ -n "$toolchain_path" ]]; then
if [[ ! -f "$toolchain_path/conan/$profile" ]]; then
echo "error: toolchain host profile does not exist: $toolchain_path/conan/$profile" >&2
return 1
fi
if [[ ! -f "$toolchain_path/conan/$build_env_profile" ]]; then
echo "error: toolchain build profile does not exist: $toolchain_path/conan/$build_env_profile" >&2
return 1
fi
run_conan "$conan_command" "$root" \
-pr:h "$toolchain_path/conan/$profile" \
-pr:h "$profile_override" \
-pr:b "$toolchain_path/conan/$build_env_profile" \
--no-remote \
--build=missing \
-s "build_type=$build_type" \
-c:h "user.target:profile=$profile" \
--core-conf core.graph:compatibility_mode=optimized
else
run_conan profile detect -e
run_conan "$conan_command" "$root" \
-pr:h default \
-pr:h "$profile_override" \
-pr:b default \
--no-remote \
--build=missing \
-s "build_type=$build_type" \
-c:h "user.target:profile=$native_profile" \
--core-conf core.graph:compatibility_mode=optimized
fi
}
install_with_profile() {
run_conan_with_profile install "$1"
run_conan cache clean --build
}
build_with_profile() {
run_conan_with_profile build "$1"
}
cd -- "$root" || exit 1
result=0
if [[ -n "$do_export" ]]; then
export_recipes || result=1
fi
if [[ "$result" == 0 && -n "$install_profile" ]]; then
if [[ -n "$deps_only" ]]; then
install_with_profile "$install_profile" || result=1
elif [[ -n "$build_profile" ]]; then
build_with_profile "$build_profile" || result=1
fi
fi
exit "$result"