forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchip_xcode_build_connector.sh
executable file
·225 lines (193 loc) · 6.38 KB
/
chip_xcode_build_connector.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
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
#!/bin/bash -e
#
# Copyright (c) 2020 Project CHIP Authors
# All rights reserved.
#
# 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.
#
# This script connects Xcode's "Run Script" build phase to a build of CHIP for Apple's environments.
#
# Conventions used in this script:
# * Variables in upper case supplied by Xcode (or other executor), are exported to subprocesses, or
# are upper-case elsewhere in CHIP scripts (e.g. CHIP_ROOT is only used locally,
# but is all uppper). Variables defined herein and used locally are lower-case
#
CHIP_ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
function format_gn_str() {
local val="$1"
val="${val//\\/\\\\}" # escape '\'
val="${val//\$/\\\$}" # escape '$'
echo -n "\"${val//\"/\\\"}\"" # escape '"'
}
function format_gn_list() {
local val sep=
echo -n "["
for val in "$@"; do
echo -n "$sep"
format_gn_str "$val"
sep=", "
done
echo "]"
}
# We only have work to do for the `installapi` and `build` phases
[[ "$ACTION" == installhdrs ]] && exit 0
mkdir -p "$TEMP_DIR"
# For debugging, save off environment that Xcode gives us, can source it to
# retry/repro failures from a bash terminal
#export >"$TEMP_DIR/env.sh"
#set -x
# Forward defines from Xcode (GCC_PREPROCESSOR_DEFINITIONS)
declare -a target_defines=()
read -r -a xcode_defines <<<"$GCC_PREPROCESSOR_DEFINITIONS"
for define in "${xcode_defines[@]}"; do
# skip over those that GN does for us
case "$define" in
CHIP_HAVE_CONFIG_H) continue ;;
esac
target_defines+=("$define")
done
# Forward C/C++ flags (OTHER_C*FLAGS)
declare -a target_cflags=()
read -r -a target_cflags_c <<<"$OTHER_CFLAGS"
read -r -a target_cflags_cc <<<"$OTHER_CPLUSPLUSFLAGS"
# Handle target OS and arch
declare target_arch=
declare target_cpu=
declare target_cflags=
declare current_arch="$(uname -m)"
read -r -a archs <<<"$ARCHS"
for arch in "${archs[@]}"; do
if [ -z "$target_arch" ] || [ "$arch" = "$current_arch" ]; then
target_arch="$arch"
case "$arch" in
x86_64) target_cpu="x64" ;;
*) target_cpu="$arch" ;;
esac
fi
target_cflags+=(-arch "$arch")
done
# Translate other options
[[ $CHIP_ENABLE_ENCODING_SENTINEL_ENUM_VALUES == YES ]] && target_defines+=("CHIP_CONFIG_IM_ENABLE_ENCODING_SENTINEL_ENUM_VALUES=1")
[[ $ENABLE_BITCODE == YES ]] && target_cflags+=("-flto")
declare -a args=(
'default_configs_cosmetic=[]' # suppress colorization
'chip_crypto="boringssl"'
'chip_build_controller_dynamic_server=false'
'chip_build_tools=false'
'chip_build_tests=false'
'chip_enable_wifi=false'
'chip_enable_python_modules=false'
'chip_device_config_enable_dynamic_mrp_config=true'
'chip_log_message_max_size=4096' # might as well allow nice long log messages
'chip_disable_platform_kvs=true'
'enable_fuzz_test_targets=false'
"target_cpu=\"$target_cpu\""
"mac_target_arch=\"$target_arch\""
"mac_deployment_target=\"$LLVM_TARGET_TRIPLE_OS_VERSION$LLVM_TARGET_TRIPLE_SUFFIX\""
"target_defines=$(format_gn_list "${target_defines[@]}")"
"target_cflags=$(format_gn_list "${target_cflags[@]}")"
"target_cflags_c=$(format_gn_list "${target_cflags_c[@]}")"
"target_cflags_cc=$(format_gn_list "${target_cflags_cc[@]}")"
)
case "$CONFIGURATION" in
Debug) args+=('is_debug=true') ;;
Release) args+=('is_debug=false') ;;
esac
[[ $PLATFORM_FAMILY_NAME != macOS ]] && {
args+=(
'target_os="ios"'
'import("//config/ios/args.gni")'
)
}
[[ $PLATFORM_FAMILY_NAME == macOS ]] && {
args+=(
'target_os="mac"'
)
}
[[ $CHIP_INET_CONFIG_ENABLE_IPV4 == NO ]] && {
args+=(
'chip_inet_config_enable_ipv4=false'
)
}
[[ $CHIP_IS_ASAN == YES || $ENABLE_ADDRESS_SANITIZER == YES ]] && {
args+=(
'is_asan=true'
)
}
[[ $CHIP_IS_UBSAN == YES || $ENABLE_UNDEFINED_BEHAVIOR_SANITIZER == YES ]] && {
args+=(
'is_ubsan=true'
)
}
[[ $CHIP_IS_TSAN == YES || $ENABLE_THREAD_SANITIZER == YES ]] && {
args+=(
'is_tsan=true'
# The system stats stuff races on the stats in various ways,
# so just disable it when using TSan.
'chip_system_config_provide_statistics=false'
)
}
[[ $CHIP_IS_CLANG == YES ]] && {
args+=(
'is_clang=true'
)
}
[[ $CHIP_IS_BLE == NO ]] && {
args+=(
'chip_config_network_layer_ble=false'
)
}
[[ $CHIP_ENABLE_ENCODING_SENTINEL_ENUM_VALUES == YES ]] && {
args+=(
'enable_encoding_sentinel_enum_values=true'
)
}
# search current (or $2) and its parent directories until
# a name match is found, which is output on stdout
find_in_ancestors() {
declare to_find="${1}"
declare dir="${2:-$(pwd)}"
while [[ ! -e ${dir}/${to_find} && -n ${dir} ]]; do
dir=${dir%/*}
done
if [[ ! -e ${dir}/${to_find} ]]; then
printf 'error: find_in_ancestors: %s not found\n' "$to_find" >&2
return 1
fi
printf '%s\n' "$dir/$to_find"
}
# actual build stuff
{
cd "$CHIP_ROOT"
if ENV=$(find_in_ancestors chip_xcode_build_connector_env.sh 2>/dev/null); then
. "$ENV"
fi
# there are environments where these bits are unwanted, unnecessary, or impossible
[[ -n $CHIP_NO_SUBMODULES ]] || scripts/checkout_submodules.py --shallow --platform darwin
if [[ -z $CHIP_NO_ACTIVATE ]]; then
# first run bootstrap/activate in an external env to build everything
env -i PW_ENVSETUP_NO_BANNER=1 PW_ENVSETUP_QUIET=1 bash -c '. scripts/activate.sh'
# now source activate for env vars
opts="$(set +o)"
set +ex
PW_ENVSETUP_NO_BANNER=1 PW_ENVSETUP_QUIET=1 . scripts/activate.sh
eval "$opts"
fi
# put build intermediates in TEMP_DIR
cd "$TEMP_DIR"
# generate and build
set -x
gn --root="$CHIP_ROOT" gen --check out --args="${args[*]}"
ninja -C out -v
ninja -C out -t missingdeps
}