-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathbuild_darwin_framework.py
More file actions
executable file
·184 lines (156 loc) · 6.08 KB
/
build_darwin_framework.py
File metadata and controls
executable file
·184 lines (156 loc) · 6.08 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
#!/usr/bin/env -S python3 -B
# Copyright (c) 2022 Project Matter Authors
#
# 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.
import argparse
import glob
import os
import platform
from subprocess import PIPE, Popen
import contextlib
def get_file_from_pigweed(name):
CHIP_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
PIGWEED = os.path.join(CHIP_ROOT, ".environment/cipd/packages/pigweed")
pattern = os.path.join(PIGWEED, '**', name)
for filename in glob.glob(pattern, recursive=True):
if os.path.isfile(filename):
return filename
return None
def run_command(command):
returncode = -1
command_log = b''
print("Running {}".format(command))
with Popen(command, cwd=os.getcwd(), stdout=PIPE, stderr=PIPE) as process:
for line in process.stdout:
command_log += line
for line in process.stderr:
command_log += line
process.wait()
returncode = process.returncode
with open(args.log_path, "wb") as f:
f.write(command_log)
if returncode != 0:
# command_log is binary, so decoding as utf-8 might technically fail. We don't want
# to throw on that.
with contextlib.suppress(Exception):
print("Failure log: {}".format(command_log.decode()))
return returncode
def build_darwin_framework(args):
abs_path = os.path.abspath(args.out_path)
if not os.path.exists(abs_path):
os.mkdir(abs_path)
command = [
'xcodebuild',
'-scheme',
args.target,
'-sdk',
args.target_sdk,
'-project',
args.project_path,
'-derivedDataPath',
abs_path,
"ARCHS={}".format(args.target_arch),
]
if args.target_sdk != "macosx":
command += [
# Build Matter.framework as a static library
"SUPPORTS_TEXT_BASED_API=NO",
"MACH_O_TYPE=staticlib",
# Change visibility flags such that both darwin-framework-tool and Matter.framework
# are built with the same flags.
"GCC_INLINES_ARE_PRIVATE_EXTERN=NO",
"GCC_SYMBOLS_PRIVATE_EXTERN=NO",
]
options = {
'CHIP_INET_CONFIG_ENABLE_IPV4': args.ipv4,
'CHIP_IS_ASAN': args.asan,
'CHIP_IS_BLE': args.ble,
'CHIP_IS_CLANG': args.clang,
'CHIP_ENABLE_ENCODING_SENTINEL_ENUM_VALUES': args.enable_encoding_sentinel_enum_values,
'CHIP_USE_NETWORK_FRAMEWORK': args.use_network_framework
}
for option in options:
command += ["{}={}".format(option, "YES" if options[option] else "NO")]
defines = 'GCC_PREPROCESSOR_DEFINITIONS=${inherited} MTR_NO_AVAILABILITY=1'
command += [defines]
cflags = ["${inherited}"]
ldflags = ["${inherited}"]
if args.clang:
command += [
"CC={}".format(get_file_from_pigweed("clang")),
"CXX={}".format(get_file_from_pigweed("clang++")),
"COMPILER_INDEX_STORE_ENABLE=NO",
"CLANG_ENABLE_MODULES=NO",
]
ldflags += [
"-nostdlib++",
get_file_from_pigweed("libc++.a"),
]
if args.asan:
flags = ["-fsanitize=address", "-fno-omit-frame-pointer"]
cflags += flags
ldflags += flags
if args.clang:
ldflags += [
get_file_from_pigweed("libclang_rt.asan_osx_dynamic.dylib")
]
if args.enable_encoding_sentinel_enum_values:
cflags += ["-DCHIP_CONFIG_IM_ENABLE_ENCODING_SENTINEL_ENUM_VALUES=1"]
if args.compdb:
cflags += ["-gen-cdb-fragment-path ", abs_path + '/compdb']
command += ["OTHER_CFLAGS=" + ' '.join(cflags), "OTHER_LDFLAGS=" + ' '.join(ldflags)]
command_result = run_command(command)
print("Build Framework Result: {}".format(command_result))
exit(command_result)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Build the Matter Darwin framework")
parser.add_argument(
"--project_path",
default="src/darwin/Framework/Matter.xcodeproj",
help="Set the project path",
required=True,
)
parser.add_argument(
"--out_path",
default="/tmp/macos_framework_output",
help="Output lpath for framework",
required=True,
)
parser.add_argument("--target",
default="Matter",
help="Name of target to build",
required=True)
parser.add_argument("--target_sdk",
default="macosx",
help="Set the target sdk",
required=False,
)
parser.add_argument("--target_arch",
default=platform.machine(),
help="Set the target architecture",
required=False,
)
parser.add_argument("--log_path",
help="Output log file destination",
required=True)
parser.add_argument('--ipv4', action=argparse.BooleanOptionalAction)
parser.add_argument('--asan', action=argparse.BooleanOptionalAction)
parser.add_argument('--ble', action=argparse.BooleanOptionalAction)
parser.add_argument('--clang', action=argparse.BooleanOptionalAction)
parser.add_argument('--enable-encoding-sentinel-enum-values', action=argparse.BooleanOptionalAction)
parser.add_argument('--compdb', action=argparse.BooleanOptionalAction)
parser.add_argument('--use-network-framework',
action=argparse.BooleanOptionalAction)
args = parser.parse_args()
build_darwin_framework(args)