-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.py
executable file
·316 lines (238 loc) · 10.2 KB
/
build.py
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/usr/bin/env python3
import getopt
import os
import sys
def get_program_path(program):
"""
Return absolute path of program
"""
import subprocess
try:
path = subprocess.check_output(["which", program])
return str(path, encoding="utf-8").strip("\n ")
except subprocess.CalledProcessError:
return None
def run_build(parse_args):
"""
Run a source build
"""
import modules.build as build
import modules.config as config
import modules.distros as distros
import modules.sync as sync
import modules.upload as upload
# verify args
if not parse_args.build_dir:
print("No build dir specified")
os._exit(1)
elif not parse_args.target:
print("No build target specified")
os._exit(1)
elif not parse_args.distribution:
print("No distribution specified")
os._exit(1)
elif not parse_args.version:
print("No distribution version specified")
os._exit(1)
elif not parse_args.device:
print("No device specified")
os._exit(1)
elif not parse_args.build_variant:
print("No build variant specified")
os._exit(1)
# append tool dir to path
os.environ['PATH'] = os.environ['PATH'] + ":" + os.environ['PWD'] + "/tools"
build_dir = os.path.realpath(parse_args.build_dir[0])
target = parse_args.target[0]
distribution = parse_args.distribution[0]
version = parse_args.version[0]
device = parse_args.device[0]
build_variant = parse_args.build_variant[0]
valid_versions = distros.get_distro_versions(distribution)
if version not in valid_versions:
print("Invalid version specified. Options are: " + valid_versions)
os._exit(1)
# set ccache stuff
ccache_bin = get_program_path("ccache")
if ccache_bin:
config.envvars["CCACHE_EXEC"] = ccache_bin
config.envvars["CCACHE_DIR"] = build_dir + "/ccache"
config.envvars["USE_CCACHE"] = "1"
config.envvars["CCACHE_MAXSIZE"] = "100G"
config.envvars["CCACHE_COMPRESS"] = "1"
# update envvars
os.environ.update(config.envvars)
# sync repos
sync.sync_dist_repo(build_dir, distribution, version, \
local_only = parse_args.local_only)
# apply repopicks
repopicks = []
topics = []
repopicks_lineage = []
topics_lineage = []
force_pick = parse_args.force_pick
if parse_args.pick:
repopicks = parse_args.pick
if parse_args.pick_lineage:
repopicks_lineage = parse_args.pick_lineage
if parse_args.pick_topic:
topics = parse_args.pick_topic
if parse_args.pick_lineage_topic:
topics_lineage = parse_args.pick_lineage_topic
sync.apply_repopicks(build_dir, distribution, version, \
sync.lineage_gerrit, picks=repopicks_lineage, topics=topics_lineage, force=force_pick)
sync.apply_repopicks(build_dir, distribution, version, \
sync.msm8916_gerrit, picks=repopicks, topics=topics, force=force_pick)
# build
build.build_target(build_dir, distribution, version, device, target, build_variant)
# get artifacts
bootimage_path = build.get_bootimage_path(build_dir, distribution, version, device)
recovery_path = build.get_recoveryimage_path(build_dir, distribution, version, device)
otapackage_path = build.get_otapackage_path(build_dir, distribution, version, device)
tag = build.get_build_release_tag(distribution, version, device, target)
description = build.get_build_release_description(distribution, version, device)
upload.create_github_release(tag, description)
if bootimage_path:
bootimage_name = build.get_bootimage_release_name(distribution, version, device)
upload.upload_github_artifact(tag, bootimage_name, bootimage_path)
upload.upload_ssh(tag, bootimage_name, bootimage_path)
if recovery_path:
recovery_name = build.get_recoveryimage_release_name(distribution, version, device)
upload.upload_github_artifact(tag, recovery_name, recovery_path)
upload.upload_ssh(tag, recovery_name, recovery_path)
if otapackage_path and target == "otapackage":
otapackage_name = build.get_otapackage_release_name(distribution, version, device)
upload.upload_github_artifact(tag, otapackage_name, otapackage_path)
upload.upload_ssh(tag, otapackage_name, otapackage_path)
# clean
if parse_args.clean_device:
print("Cleaning build directory...")
build.clean_source_dir(build_dir, distribution, version, device)
elif parse_args.clean:
print("Cleaning build directory...")
build.clean_source_dir(build_dir, distribution, version)
def generate_pipelines(parse_args):
"""
Generate build pipelines
"""
import modules.build
import modules.jobs
import subprocess
buildkite_yaml = "steps:\n"
base_args = []
base_args.append(sys.argv[0])
if parse_args.build_dir:
base_args.append("--build-dir")
if type(parse_args.build_dir) == str:
base_args.append(parse_args.build_dir)
else:
base_args.append(parse_args.build_dir[0])
if parse_args.config_url:
base_args.append("--config-url")
base_args.append(parse_args.config_url[0])
if parse_args.local_only:
base_args.append("--local-only")
if parse_args.clean:
base_args.append("--clean")
if parse_args.clean_device:
base_args.append("--clean-device")
distributions = []
if parse_args.distribution:
distributions.extend(parse_args.distribution)
else:
distributions.extend(modules.jobs.get_distros())
for distribution in distributions:
versions = []
if parse_args.version:
versions.extend(parse_args.version)
else:
versions.extend(modules.jobs.get_distro_versions(distribution))
for version in versions:
build_variants = []
devices = []
repopicks = []
topics = []
repopicks_lineage = []
topics_lineage = []
force_pick = parse_args.force_pick
targets = []
if parse_args.build_variant:
build_variants.extend(parse_args.build_variant)
else:
build_variants.extend(modules.jobs.get_build_variants(distribution, version))
if parse_args.device:
devices.extend(parse_args.device)
else:
devices.extend(modules.jobs.get_devices(distribution, version))
if parse_args.target:
targets.extend(parse_args.target)
else:
targets.extend(modules.jobs.get_targets(distribution, version))
if parse_args.pick:
repopicks = parse_args.pick
if parse_args.pick_lineage:
repopicks_lineage = parse_args.pick_lineage
if parse_args.pick_topic:
topics = parse_args.pick_topic
if parse_args.pick_lineage_topic:
topics_lineage = parse_args.pick_lineage_topic
# Append from conf
repopicks += modules.jobs.get_repopicks(distribution, version)[0]
repopicks_lineage += modules.jobs.get_lineage_repopicks(distribution, version)[0]
topics += modules.jobs.get_repopicks(distribution, version)[1]
topics_lineage += modules.jobs.get_lineage_repopicks(distribution, version)[1]
for device in devices:
for build_variant in build_variants:
for target in targets:
script_args = []
script_args.append("--distribution")
script_args.append(distribution)
script_args.append("--version")
script_args.append(version)
script_args.append("--device")
script_args.append(device)
script_args.append("--build-variant")
script_args.append(build_variant)
script_args.append("--target")
script_args.append(target)
for repopick in repopicks:
script_args.append("--pick")
script_args.append(str(repopick))
for repopick in repopicks_lineage:
script_args.append("--pick-lineage")
script_args.append(str(repopick))
for topic in topics:
script_args.append("--pick-topic")
script_args.append(str(topic))
for topic in topics_lineage:
script_args.append("--pick-lineage-topic")
script_args.append(str(topic))
if force_pick:
script_args.append("--force-pick")
desc = modules.build.get_build_release_description(\
distribution, version, device)
buildkite_yaml += " - label: " + desc + "\n"
buildkite_yaml += " command: "
for arg in base_args:
buildkite_yaml += arg
buildkite_yaml += " "
for arg in script_args:
buildkite_yaml += arg
buildkite_yaml += " "
buildkite_yaml += "\n"
buildkite_yaml += " retry:\n"
buildkite_yaml += " automatic: false\n"
buildkite_yaml += "\n"
buildkite_args =["buildkite-agent", "pipeline", "upload"]
res = subprocess.run(buildkite_args, input=buildkite_yaml, encoding="utf-8")
if res.returncode != 0:
print("Failed to upload pipeline")
os._exit(res.returncode)
if __name__ == "__main__":
import modules.args
argv = modules.args.parse_config_url()
parse_args = modules.args.parse_args(argv)
if parse_args.generate_pipelines:
generate_pipelines(parse_args)
else:
run_build(parse_args)