-
Notifications
You must be signed in to change notification settings - Fork 32
/
build_thirdparty.sh
executable file
·87 lines (78 loc) · 2.35 KB
/
build_thirdparty.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
#!/usr/bin/env bash
#
# Copyright (c) YugaByte, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations
# under the License.
#
set -euo pipefail
# shellcheck source=./yb-thirdparty-common.sh
. "${BASH_SOURCE[0]%/*}/yb-thirdparty-common.sh"
# This may re-execute the current script using the "arch" command based on YB_TARGET_ARCH.
ensure_correct_mac_architecture "$@"
build_thirdparty_args=( "$@" )
toolchain=""
# Do some lightweight parsing of the arguments to find what we need for the log file name.
# TODO: redirect log to file in Python itself, so we don't have to do this parsing here.
while [[ $# -gt 0 ]]; do
case "$1" in
--toolchain=*)
toolchain=${1#--toolchain=}
;;
--toolchain)
toolchain=$2
shift
;;
esac
shift
done
activate_virtualenv
log_dir=$HOME/logs
mkdir -p "${log_dir}"
log_file_name=build_thirdparty
latest_log_links=( "build_thirdparty_latest.log" )
if [[ -n ${toolchain} ]]; then
log_file_name+=_${toolchain}
latest_log_links=( "build_thirdparty_latest_${toolchain}.log" )
fi
log_file_name+=_$( date +%Y-%m-%dT%H_%M_%S ).log
log_path=${log_dir}/${log_file_name}
(
cd "${log_dir}"
for link_name in "${latest_log_links[@]}"; do
ln -sf "${log_file_name}" "${link_name}"
done
)
link_path_list_str=""
for link_name in "${latest_log_links[@]}"; do
if [[ -n ${link_path_list_str} ]]; then
link_path_list_str+=", "
fi
link_path_list_str+=${link_name}
done
echo
echo "Logging to ${log_path} (linked to ${link_path_list_str})"
echo
cmd=( python3 "${YB_THIRDPARTY_DIR}/python/yugabyte_db_thirdparty/yb_build_thirdparty_main.py" )
if [[ ${#build_thirdparty_args[@]} -gt 0 ]]; then
cmd+=( "${build_thirdparty_args[@]}" )
fi
# Cannot use |& redirection of both stdout and stderr due to the need to support Bash 3.
set +e
(
set -x
"${cmd[@]}"
) 2>&1 | tee "${log_path}"
exit_code=$?
set -e
echo
echo "Log saved to ${log_path}"
echo
exit ${exit_code}