1
- #! /usr/ bin/env bash
1
+ #! /bin/bash -e
2
2
3
3
#
4
4
# Copyright (c) 2020 Project CHIP Authors
27
27
28
28
CHIP_ROOT=$( cd " $( dirname " $0 " ) /../../.." && pwd)
29
29
30
- # lotsa debug output :-)
31
- set -ex
30
+ function format_gn_str() {
31
+ local val=" $1 "
32
+ val=" ${val// \\ / \\\\ } " # escape '\'
33
+ val=" ${val// \$ / \\\$ } " # escape '$'
34
+ echo -n " \" ${val// \" / \\\" } \" " # escape '"'
35
+ }
36
+
37
+ function format_gn_list() {
38
+ local val sep=
39
+ echo -n " ["
40
+ for val in " $@ " ; do
41
+ echo -n " $sep "
42
+ format_gn_str " $val "
43
+ sep=" , "
44
+ done
45
+ echo " ]"
46
+ }
32
47
33
48
# We only have work to do for the `installapi` and `build` phases
34
49
[[ " $ACTION " == installhdrs ]] && exit 0
35
50
36
- # helpful debugging, save off environment that Xcode gives us, can source it to
37
- # retry/repro failures from a bash terminal
38
51
mkdir -p " $TEMP_DIR "
39
- export > " $TEMP_DIR /env.sh"
40
52
41
- declare -a defines=()
42
- # lots of environment variables passed by Xcode to this script
43
- read -r -a defines <<< " $GCC_PREPROCESSOR_DEFINITIONS"
44
-
45
- declare target_defines=
46
- for define in " ${defines[@]} " ; do
53
+ # For debugging, save off environment that Xcode gives us, can source it to
54
+ # retry/repro failures from a bash terminal
55
+ # export >"$TEMP_DIR/env.sh"
56
+ # set -x
47
57
58
+ # Forward defines from Xcode (GCC_PREPROCESSOR_DEFINITIONS)
59
+ declare -a target_defines=()
60
+ read -r -a xcode_defines <<< " $GCC_PREPROCESSOR_DEFINITIONS"
61
+ for define in " ${xcode_defines[@]} " ; do
48
62
# skip over those that GN does for us
49
63
case " $define " in
50
- CHIP_HAVE_CONFIG_H)
51
- continue
52
- ;;
64
+ CHIP_HAVE_CONFIG_H) continue ;;
53
65
esac
54
- target_defines+=, \" ${ define// \" / \\\" } \"
66
+ target_defines+=( " $ define" )
55
67
done
56
- [[ $CHIP_ENABLE_ENCODING_SENTINEL_ENUM_VALUES == YES ]] && {
57
- target_defines+=,\" CHIP_CONFIG_IM_ENABLE_ENCODING_SENTINEL_ENUM_VALUES=1\"
58
- }
59
- target_defines=[${target_defines: 1} ]
60
68
69
+ # Forward C/C++ flags (OTHER_C*FLAGS)
70
+ declare -a target_cflags=()
71
+ read -r -a target_cflags_c <<< " $OTHER_CFLAGS"
72
+ read -r -a target_cflags_cc <<< " $OTHER_CPLUSPLUSFLAGS"
73
+
74
+ # Handle target OS and arch
61
75
declare target_arch=
62
76
declare target_cpu=
63
77
declare target_cflags=
@@ -72,18 +86,12 @@ for arch in "${archs[@]}"; do
72
86
* ) target_cpu=" $arch " ;;
73
87
esac
74
88
fi
75
- if [ -n " $target_cflags " ]; then
76
- target_cflags+=' ,'
77
- fi
78
- target_cflags+=' "-arch","' " $arch " ' "'
89
+ target_cflags+=(-arch " $arch " )
79
90
done
80
91
81
- [[ $ENABLE_BITCODE == YES ]] && {
82
- if [ -n " $target_cflags " ]; then
83
- target_cflags+=' ,'
84
- fi
85
- target_cflags+=' "-flto"'
86
- }
92
+ # Translate other options
93
+ [[ $CHIP_ENABLE_ENCODING_SENTINEL_ENUM_VALUES == YES ]] && target_defines+=(" CHIP_CONFIG_IM_ENABLE_ENCODING_SENTINEL_ENUM_VALUES=1" )
94
+ [[ $ENABLE_BITCODE == YES ]] && target_cflags+=(" -flto" )
87
95
88
96
declare -a args=(
89
97
' default_configs_cosmetic=[]' # suppress colorization
@@ -98,10 +106,12 @@ declare -a args=(
98
106
' chip_disable_platform_kvs=true'
99
107
' enable_fuzz_test_targets=false'
100
108
" target_cpu=\" $target_cpu \" "
101
- " target_defines=$target_defines "
102
- " target_cflags=[$target_cflags ]"
103
109
" mac_target_arch=\" $target_arch \" "
104
110
" mac_deployment_target=\" $LLVM_TARGET_TRIPLE_OS_VERSION$LLVM_TARGET_TRIPLE_SUFFIX \" "
111
+ " target_defines=$( format_gn_list " ${target_defines[@]} " ) "
112
+ " target_cflags=$( format_gn_list " ${target_cflags[@]} " ) "
113
+ " target_cflags_c=$( format_gn_list " ${target_cflags_c[@]} " ) "
114
+ " target_cflags_cc=$( format_gn_list " ${target_cflags_cc[@]} " ) "
105
115
)
106
116
107
117
case " $CONFIGURATION " in
@@ -197,16 +207,18 @@ find_in_ancestors() {
197
207
if [[ -z $CHIP_NO_ACTIVATE ]]; then
198
208
# first run bootstrap/activate in an external env to build everything
199
209
env -i PW_ENVSETUP_NO_BANNER=1 PW_ENVSETUP_QUIET=1 bash -c ' . scripts/activate.sh'
200
- set +ex
201
210
# now source activate for env vars
211
+ opts=" $( set +o) "
212
+ set +ex
202
213
PW_ENVSETUP_NO_BANNER=1 PW_ENVSETUP_QUIET=1 . scripts/activate.sh
203
- set -ex
214
+ eval " $opts "
204
215
fi
205
216
206
217
# put build intermediates in TEMP_DIR
207
218
cd " $TEMP_DIR "
208
219
209
220
# generate and build
221
+ set -x
210
222
gn --root=" $CHIP_ROOT " gen --check out --args=" ${args[*]} "
211
223
exec ninja -v -C out
212
224
}
0 commit comments