4 # Copyright (c) 2020 Project CHIP Authors
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 # This script connects Xcode's "Run Script" build phase to a build of CHIP for Apple's environments.
22 # Conventions used in this script:
23 # * Variables in upper case supplied by Xcode (or other executor), are exported to subprocesses, or
24 # are upper-case elsewhere in CHIP scripts (e.g. CHIP_ROOT is only used locally,
25 # but is all uppper). Variables defined herein and used locally are lower-case
28 here=$(cd "${0%/*}" && pwd)
31 CHIP_ROOT=$(cd "$here/../../.." && pwd)
34 echo "$me: *** ERROR: $*"
38 # lotsa debug output :-)
41 # helpful debugging, save off environment that Xcode gives us, can source it to
42 # retry/repro failures from a bash terminal
44 export >"$TEMP_DIR/env.sh"
47 # lots of environment variables passed by Xcode to this script
48 read -r -a defines <<<"$GCC_PREPROCESSOR_DEFINITIONS"
50 declare target_defines=
51 for define in "${defines[@]}"; do
53 # skip over those that GN does for us
58 CHIP_*_CONFIG_INCLUDE)
64 CONFIG_NETWORK_LAYER*)
71 target_defines+=,\"${define//\"/\\\"}\"
73 target_defines=[${target_defines:1}]
75 declare target_cflags='"-target","'"$PLATFORM_PREFERRED_ARCH"'-'"$LLVM_TARGET_TRIPLE_VENDOR"'-'"$LLVM_TARGET_TRIPLE_OS_VERSION"'"'
77 read -r -a archs <<<"$ARCHS"
79 for arch in "${archs[@]}"; do
80 target_cflags+=',"-arch","'"$arch"'"'
83 [[ $ENABLE_BITCODE == YES ]] && {
84 target_cflags+=',"-flto"'
88 'default_configs_cosmetic=[]' # suppress colorization
89 'chip_crypto="mbedtls"'
90 'chip_logging_style="darwin"'
91 'chip_build_tools=false'
92 'chip_build_tests=false'
93 'chip_ble_project_config_include=""'
94 'chip_device_project_config_include=""'
95 'chip_inet_project_config_include=""'
96 'chip_system_project_config_include=""'
97 'target_cpu="'"$PLATFORM_PREFERRED_ARCH"'"'
98 'target_defines='"$target_defines"
99 'target_cflags=['"$target_cflags"']'
102 [[ $CONFIGURATION != Debug* ]] && args+='is_debug=true'
104 [[ $PLATFORM_FAMILY_NAME != macOS ]] && {
107 'import("//config/ios/args.gni")'
111 [[ $PLATFORM_FAMILY_NAME == macOS ]] && {
114 'import("//config/standalone/args.gni")'
115 'chip_project_config_include_dirs=["'"$CHIP_ROOT"'/config/standalone"]'
119 # search current (or $2) and its parent directories until
120 # a name match is found, which is output on stdout
121 find_in_ancestors() {
122 declare to_find="${1}"
123 declare dir="${2:-$(pwd)}"
125 while [[ ! -e ${dir}/${to_find} && -n ${dir} ]]; do
129 if [[ ! -e ${dir}/${to_find} ]]; then
130 printf 'error: find_in_ancestors: %s not found\n' "$to_find" >&2
133 printf '%s\n' "$dir/$to_find"
138 cd "$CHIP_ROOT" # pushd and popd because we need the env vars from activate
140 if ENV=$(find_in_ancestors chip_xcode_build_connector_env.sh 2>/dev/null); then
144 # there are environments where these bits are unwanted, unnecessary, or impossible
145 [[ -n $CHIP_NO_SUBMODULES ]] || git submodule update --init
146 if [[ -z $CHIP_NO_ACTIVATE ]]; then
147 # first run bootstrap/activate in an external env to build everything
148 env -i PW_ENVSETUP_NO_BANNER=1 PW_ENVSETUP_QUIET=1 bash -c '. scripts/activate.sh'
150 # now source activate for env vars
151 PW_ENVSETUP_NO_BANNER=1 PW_ENVSETUP_QUIET=1 . scripts/activate.sh
155 # put build intermediates in TEMP_DIR
159 gn --root="$CHIP_ROOT" gen --check out --args="${args[*]}"