blob: f7c1549a342488a090b7551fad6f265fec9ae70a [file] [log] [blame]
David Burger7fd1dbe2020-03-26 09:26:55 -06001#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# Copyright 2020 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6"""Transforms config from /config/proto/api proto format to platform JSON."""
7
8import argparse
9import json
10import pprint
C Shapiro90fda252020-04-17 14:34:57 -050011import os
David Burger7fd1dbe2020-03-26 09:26:55 -060012import sys
C Shapiro90fda252020-04-17 14:34:57 -050013import re
C Shapiro5bf23a72020-04-24 11:40:17 -050014import xml.etree.ElementTree as etree
C Shapiro9a3ac8c2020-04-25 07:49:21 -050015import xml.dom.minidom as minidom
David Burger7fd1dbe2020-03-26 09:26:55 -060016
17from collections import namedtuple
18
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070019from chromiumos.config.api import device_brand_pb2
David Burger92609a32020-04-23 10:38:50 -060020from chromiumos.config.api import topology_pb2
C Shapiro5bf23a72020-04-24 11:40:17 -050021from chromiumos.config.payload import config_bundle_pb2
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070022from chromiumos.config.api.software import brand_config_pb2
David Burger7fd1dbe2020-03-26 09:26:55 -060023
24Config = namedtuple('Config',
25 ['program',
26 'hw_design',
27 'odm',
28 'hw_design_config',
29 'device_brand',
C Shapiro2f0bb5d2020-04-14 10:07:47 -050030 'device_signer_config',
David Burger7fd1dbe2020-03-26 09:26:55 -060031 'oem',
32 'sw_config',
33 'brand_config',
34 'build_target'])
35
C Shapiro5bf23a72020-04-24 11:40:17 -050036ConfigFiles = namedtuple('ConfigFiles',
37 ['bluetooth',
38 'arc_hw_features'])
39
David Burger7fd1dbe2020-03-26 09:26:55 -060040
41def ParseArgs(argv):
42 """Parse the available arguments.
43
44 Invalid arguments or -h cause this function to print a message and exit.
45
46 Args:
47 argv: List of string arguments (excluding program name / argv[0])
48
49 Returns:
50 argparse.Namespace object containing the attributes.
51 """
52 parser = argparse.ArgumentParser(
53 description='Converts source proto config into platform JSON config.')
54 parser.add_argument(
55 '-c',
56 '--project_configs',
57 nargs='+',
58 type=str,
59 help='Space delimited list of source protobinary project config files.')
60 parser.add_argument(
61 '-p',
62 '--program_config',
63 type=str,
64 help='Path to the source program-level protobinary file')
65 parser.add_argument(
66 '-o',
67 '--output',
68 type=str,
69 help='Output file that will be generated')
70 return parser.parse_args(argv)
71
72
73def _Set(field, target, target_name):
74 if field:
75 target[target_name] = field
76
77
C Shapiro5bf23a72020-04-24 11:40:17 -050078def _BuildArc(config, config_files):
David Burger7fd1dbe2020-03-26 09:26:55 -060079 if config.build_target.arc:
80 build_properties = {
81 'device': config.build_target.arc.device,
82 'first-api-level': config.build_target.arc.first_api_level,
83 'marketing-name': config.device_brand.brand_name,
84 'metrics-tag': config.hw_design.name.lower(),
Andrew Lambb47b7dc2020-04-07 10:20:32 -060085 'product': config.build_target.id.value,
David Burger7fd1dbe2020-03-26 09:26:55 -060086 }
87 if config.oem:
88 build_properties['oem'] = config.oem.name
C Shapiro5bf23a72020-04-24 11:40:17 -050089 result = {
90 'build-properties': build_properties
91 }
92 feature_id = _ArcHardwareFeatureId(config.hw_design_config)
93 if feature_id in config_files.arc_hw_features:
94 result['hardware-features'] = config_files.arc_hw_features[feature_id]
95 return result
David Burger7fd1dbe2020-03-26 09:26:55 -060096
C Shapiro90fda252020-04-17 14:34:57 -050097def _BuildBluetooth(config, bluetooth_files):
98 bt_flags = config.sw_config.bluetooth_config.flags
99 # Convert to native map (from proto wrapper)
100 bt_flags_map = dict(bt_flags)
101 result = {}
102 if bt_flags_map:
103 result['flags'] = bt_flags_map
104 bt_comp = config.hw_design_config.hardware_features.bluetooth.component
105 if bt_comp.vendor_id:
106 bt_id = _BluetoothId(config.hw_design.name.lower(), bt_comp)
107 if bt_id in bluetooth_files:
108 result['config'] = bluetooth_files[bt_id]
109 return result
110
David Burger7fd1dbe2020-03-26 09:26:55 -0600111
112def _BuildFingerprint(hw_topology):
Andrew Lambc2c55462020-04-06 08:43:34 -0600113 if hw_topology.HasField('fingerprint'):
David Burger7fd1dbe2020-03-26 09:26:55 -0600114 fp = hw_topology.fingerprint.hardware_feature.fingerprint
David Burger92609a32020-04-23 10:38:50 -0600115 result = {}
116 if fp.location != topology_pb2.HardwareFeatures.Fingerprint.NOT_PRESENT:
117 location = fp.Location.DESCRIPTOR.values_by_number[fp.location].name
118 result['sensor-location'] = location.lower().replace('_', '-')
119 if fp.board:
120 result['board'] = fp.board
David Burger7fd1dbe2020-03-26 09:26:55 -0600121 return result
122
123
124def _FwBcsPath(payload):
125 if payload and payload.firmware_image_name:
126 return 'bcs://%s.%d.%d.0.tbz2' % (
127 payload.firmware_image_name,
128 payload.version.major,
129 payload.version.minor)
130
131
132def _FwBuildTarget(payload):
133 if payload:
134 return payload.build_target_name
135
136
137def _BuildFirmware(config):
Andrew Lamb3da156d2020-04-16 16:00:56 -0600138 fw_payload_config = config.sw_config.firmware
139 fw_build_config = config.sw_config.firmware_build_config
140 main_ro = fw_payload_config.main_ro_payload
141 main_rw = fw_payload_config.main_rw_payload
142 ec_ro = fw_payload_config.ec_ro_payload
143 pd_ro = fw_payload_config.pd_ro_payload
David Burger7fd1dbe2020-03-26 09:26:55 -0600144
145 build_targets = {}
Andrew Lamb3da156d2020-04-16 16:00:56 -0600146
Andrew Lambf8954ee2020-04-21 10:24:40 -0600147 _Set(fw_build_config.build_targets.depthcharge, build_targets, 'depthcharge')
148 _Set(fw_build_config.build_targets.coreboot, build_targets, 'coreboot')
149 _Set(fw_build_config.build_targets.ec, build_targets, 'ec')
150 _Set(
151 list(fw_build_config.build_targets.ec_extras), build_targets, 'ec_extras')
152 _Set(fw_build_config.build_targets.libpayload, build_targets, 'libpayload')
David Burger7fd1dbe2020-03-26 09:26:55 -0600153
154 result = {
155 'bcs-overlay': config.build_target.overlay_name,
156 'build-targets': build_targets,
David Burger7fd1dbe2020-03-26 09:26:55 -0600157 }
Andrew Lamb883fa042020-04-06 11:37:22 -0600158
159 _Set(main_ro.firmware_image_name.lower(), result, 'image-name')
160
161 if not any((
162 main_ro.firmware_image_name,
163 main_rw.firmware_image_name,
164 ec_ro.firmware_image_name,
165 pd_ro.firmware_image_name,
166 )):
Andrew Lambb9e660f2020-04-06 11:37:22 -0600167 result['no-firmware'] = True
Andrew Lamb883fa042020-04-06 11:37:22 -0600168
169 _Set(_FwBcsPath(main_ro), result, 'main-ro-image')
170 _Set(_FwBcsPath(main_rw), result, 'main-rw-image')
171 _Set(_FwBcsPath(ec_ro), result, 'ec-ro-image')
172 _Set(_FwBcsPath(pd_ro), result, 'pd-ro-image')
David Burger7fd1dbe2020-03-26 09:26:55 -0600173
Andrew Lambf39fbe82020-04-13 16:14:33 -0600174 _Set(
175 config.hw_design_config.hardware_features.fw_config.value,
176 result,
177 'firmware-config',
178 )
179
David Burger7fd1dbe2020-03-26 09:26:55 -0600180 return result
181
182
183def _BuildFwSigning(config):
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500184 if config.sw_config.firmware and config.device_signer_config:
185 return {
186 'key-id': config.device_signer_config.key_id,
187 'signature-id': config.hw_design.name.lower(),
188 }
189 return {}
David Burger7fd1dbe2020-03-26 09:26:55 -0600190
191
192def _File(source, destination):
193 return {
194 'destination': destination,
195 'source': source
196 }
197
198
199def _BuildAudio(config):
200 alsa_path = '/usr/share/alsa/ucm'
201 cras_path = '/etc/cras'
202 project_name = config.hw_design.name.lower()
Andrew Lamb7d536782020-04-07 10:23:55 -0600203 if not config.sw_config.HasField('audio_config'):
David Burger7fd1dbe2020-03-26 09:26:55 -0600204 return {}
205 audio = config.sw_config.audio_config
206 card = audio.card_name
David Burger599ff7b2020-04-06 16:29:31 -0600207 card_with_suffix = audio.card_name
208 if audio.ucm_suffix:
209 card_with_suffix += '.' + audio.ucm_suffix
David Burger7fd1dbe2020-03-26 09:26:55 -0600210 files = []
211 if audio.ucm_file:
David Burger599ff7b2020-04-06 16:29:31 -0600212 files.append(_File(
213 audio.ucm_file,
214 '%s/%s/HiFi.conf' % (alsa_path, card_with_suffix)))
David Burger7fd1dbe2020-03-26 09:26:55 -0600215 if audio.ucm_master_file:
216 files.append(_File(
David Burger599ff7b2020-04-06 16:29:31 -0600217 audio.ucm_master_file,
218 '%s/%s/%s.conf' % (alsa_path, card_with_suffix, card_with_suffix)))
David Burger7fd1dbe2020-03-26 09:26:55 -0600219 if audio.card_config_file:
220 files.append(_File(
221 audio.card_config_file, '%s/%s/%s' % (cras_path, project_name, card)))
222 if audio.dsp_file:
223 files.append(
David Burger2e254902020-04-02 16:56:01 -0600224 _File(audio.dsp_file, '%s/%s/dsp.ini' % (cras_path, project_name)))
David Burger599ff7b2020-04-06 16:29:31 -0600225
226 result = {
David Burger7fd1dbe2020-03-26 09:26:55 -0600227 'main': {
228 'cras-config-dir': project_name,
229 'files': files,
230 }
231 }
David Burger599ff7b2020-04-06 16:29:31 -0600232 if audio.ucm_suffix:
David Burger03cdcbd2020-04-13 13:54:48 -0600233 result['main']['ucm-suffix'] = audio.ucm_suffix
David Burger599ff7b2020-04-06 16:29:31 -0600234
235 return result
David Burger7fd1dbe2020-03-26 09:26:55 -0600236
237
David Burger8aa8fa32020-04-14 08:30:34 -0600238def _BuildCamera(hw_topology):
239 if hw_topology.HasField('camera'):
240 camera = hw_topology.camera.hardware_feature.camera
241 result = {}
242 if camera.count.value:
243 result['count'] = camera.count.value
244 return result
245
246
Andrew Lamb7806ce92020-04-07 10:22:17 -0600247def _BuildIdentity(hw_scan_config, program, brand_scan_config=None):
David Burger7fd1dbe2020-03-26 09:26:55 -0600248 identity = {}
249 _Set(hw_scan_config.firmware_sku, identity, 'sku-id')
250 _Set(hw_scan_config.smbios_name_match, identity, 'smbios-name-match')
Andrew Lamb7806ce92020-04-07 10:22:17 -0600251 # 'platform-name' is needed to support 'mosys platform name'. Clients should
252 # longer require platform name, but set it here for backwards compatibility.
253 _Set(program.name, identity, 'platform-name')
David Burger7fd1dbe2020-03-26 09:26:55 -0600254 # ARM architecture
255 _Set(hw_scan_config.device_tree_compatible_match, identity,
256 'device-tree-compatible-match')
257
258 if brand_scan_config:
259 _Set(brand_scan_config.whitelabel_tag, identity, 'whitelabel-tag')
260
261 return identity
262
263
264def _Lookup(id_value, id_map):
265 if id_value.value:
266 key = id_value.value
267 if key in id_map:
268 return id_map[id_value.value]
269 error = 'Failed to lookup %s with value: %s' % (
270 id_value.__class__.__name__.replace('Id', ''), key)
271 print(error)
272 print('Check the config contents provided:')
273 pp = pprint.PrettyPrinter(indent=4)
274 pp.pprint(id_map)
275 raise Exception(error)
276
277
C Shapiro5bf23a72020-04-24 11:40:17 -0500278def _TransformBuildConfigs(config, config_files=ConfigFiles({}, {})):
David Burger7fd1dbe2020-03-26 09:26:55 -0600279 partners = dict([(x.id.value, x) for x in config.partners.value])
280 programs = dict([(x.id.value, x) for x in config.programs.value])
David Burger7fd1dbe2020-03-26 09:26:55 -0600281 sw_configs = list(config.software_configs)
282 brand_configs = dict([(x.brand_id.value, x) for x in config.brand_configs])
283
C Shapiroa0b766c2020-03-31 08:35:28 -0500284 if len(config.build_targets) != 1:
285 # Artifact of sharing the config_bundle for analysis and transforms.
286 # Integrated analysis of multiple programs/projects it the only time
287 # having multiple build targets would be valid.
288 raise Exception('Single build_target required for transform')
289
David Burger7fd1dbe2020-03-26 09:26:55 -0600290 results = {}
291 for hw_design in config.designs.value:
292 if config.device_brands.value:
293 device_brands = [x for x in config.device_brands.value
294 if x.design_id.value == hw_design.id.value]
295 else:
296 device_brands = [device_brand_pb2.DeviceBrand()]
297
298 for device_brand in device_brands:
299 # Brand config can be empty since platform JSON config allows it
300 brand_config = brand_config_pb2.BrandConfig()
301 if device_brand.id.value in brand_configs:
302 brand_config = brand_configs[device_brand.id.value]
303
304 for hw_design_config in hw_design.configs:
305 design_id = hw_design_config.id.value
306 sw_config_matches = [x for x in sw_configs
307 if x.design_config_id.value == design_id]
308 if len(sw_config_matches) == 1:
309 sw_config = sw_config_matches[0]
310 elif len(sw_config_matches) > 1:
311 raise Exception('Multiple software configs found for: %s' % design_id)
312 else:
313 raise Exception('Software config is required for: %s' % design_id)
314
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500315 program = _Lookup(hw_design.program_id, programs)
316 signer_configs = dict(
317 [(x.brand_id.value, x) for x in program.device_signer_configs])
318 device_signer_config = None
319 if signer_configs:
320 device_signer_config = _Lookup(device_brand.id, signer_configs)
321
C Shapiro90fda252020-04-17 14:34:57 -0500322 transformed_config = _TransformBuildConfig(
323 Config(
324 program=program,
325 hw_design=hw_design,
326 odm=_Lookup(hw_design.odm_id, partners),
327 hw_design_config=hw_design_config,
328 device_brand=device_brand,
329 device_signer_config=device_signer_config,
330 oem=_Lookup(device_brand.oem_id, partners),
331 sw_config=sw_config,
332 brand_config=brand_config,
333 build_target=config.build_targets[0]),
C Shapiro5bf23a72020-04-24 11:40:17 -0500334 config_files)
David Burger7fd1dbe2020-03-26 09:26:55 -0600335
336 config_json = json.dumps(transformed_config,
337 sort_keys=True,
338 indent=2,
339 separators=(',', ': '))
340
341 if config_json not in results:
342 results[config_json] = transformed_config
343
344 return list(results.values())
345
346
C Shapiro5bf23a72020-04-24 11:40:17 -0500347def _TransformBuildConfig(config, config_files):
David Burger7fd1dbe2020-03-26 09:26:55 -0600348 """Transforms Config instance into target platform JSON schema.
349
350 Args:
351 config: Config namedtuple
C Shapiro5bf23a72020-04-24 11:40:17 -0500352 config_files: Map to look up the generated config files.
David Burger7fd1dbe2020-03-26 09:26:55 -0600353
354 Returns:
355 Unique config payload based on the platform JSON schema.
356 """
357 result = {
358 'identity': _BuildIdentity(
359 config.sw_config.id_scan_config,
Andrew Lamb7806ce92020-04-07 10:22:17 -0600360 config.program,
David Burger7fd1dbe2020-03-26 09:26:55 -0600361 config.brand_config.scan_config),
362 'name': config.hw_design.name.lower(),
363 }
364
C Shapiro5bf23a72020-04-24 11:40:17 -0500365 _Set(_BuildArc(config, config_files), result, 'arc')
David Burger7fd1dbe2020-03-26 09:26:55 -0600366 _Set(_BuildAudio(config), result, 'audio')
C Shapiro5bf23a72020-04-24 11:40:17 -0500367 _Set(_BuildBluetooth(config, config_files.bluetooth), result, 'bluetooth')
David Burger7fd1dbe2020-03-26 09:26:55 -0600368 _Set(config.device_brand.brand_code, result, 'brand-code')
David Burger8aa8fa32020-04-14 08:30:34 -0600369 _Set(_BuildCamera(
370 config.hw_design_config.hardware_topology), result, 'camera')
David Burger7fd1dbe2020-03-26 09:26:55 -0600371 _Set(_BuildFirmware(config), result, 'firmware')
372 _Set(_BuildFwSigning(config), result, 'firmware-signing')
373 _Set(_BuildFingerprint(
374 config.hw_design_config.hardware_topology), result, 'fingerprint')
375 power_prefs = config.sw_config.power_config.preferences
376 power_prefs_map = dict(
377 (x.replace('_', '-'),
378 power_prefs[x]) for x in power_prefs)
379 _Set(power_prefs_map, result, 'power')
380
381 return result
382
383
384def WriteOutput(configs, output=None):
385 """Writes a list of configs to platform JSON format.
386
387 Args:
388 configs: List of config dicts defined in cros_config_schema.yaml
389 output: Target file output (if None, prints to stdout)
390 """
391 json_output = json.dumps(
392 {'chromeos': {
393 'configs': configs,
394 }},
395 sort_keys=True,
396 indent=2,
397 separators=(',', ': '))
398 if output:
399 with open(output, 'w') as output_stream:
400 # Using print function adds proper trailing newline.
401 print(json_output, file=output_stream)
402 else:
403 print(json_output)
404
405
C Shapiro90fda252020-04-17 14:34:57 -0500406def _BluetoothId(project_name, bt_comp):
407 return '_'.join([project_name,
408 bt_comp.vendor_id,
409 bt_comp.product_id,
410 bt_comp.bcd_device])
411
412
C Shapiro5bf23a72020-04-24 11:40:17 -0500413def _Feature(name, present):
414 attrib = {'name': name}
415 if present:
416 return etree.Element('feature', attrib=attrib)
417 else:
418 return etree.Element('unavailable-feature', attrib=attrib)
419
420
421def _AnyPresent(features):
422 return topology_pb2.HardwareFeatures.PRESENT in features;
423
424
425def _ArcHardwareFeatureId(design_config):
426 return design_config.id.value.lower().replace(':', '_')
427
428
429def WriteArcHardwareFeatureFiles(config, output_dir):
430 """Writes ARC hardware_feature.xml files for each config
431
432 Args:
433 config: Source ConfigBundle to process.
434 output_dir: Path to the generated output.
435 Returns:
436 dict that maps the design_config_id onto the correct file.
437 """
438 project_gen_path = re.match(r'.*(generated.*)', output_dir).groups(1)[0]
439 result = {}
440 for hw_design in config.designs.value:
441 for design_config in hw_design.configs:
442 hw_features = design_config.hardware_features
443 multi_camera = hw_features.camera.count == 2
444 touchscreen = _AnyPresent([hw_features.screen.touch_support])
445 acc = hw_features.accelerometer
446 gyro = hw_features.gyroscope
447 compass = hw_features.magnetometer
448 ls = hw_features.light_sensor
449 root = etree.Element('permissions')
450 root.extend([
451 _Feature('android.hardware.camera', multi_camera),
452 _Feature('android.hardware.camera.autofocus', multi_camera),
453 _Feature('android.hardware.sensor.accelerometer',
454 _AnyPresent(
455 [acc.lid_accelerometer, acc.base_accelerometer])),
456 _Feature('android.hardware.sensor.gyroscope',
457 _AnyPresent(
458 [gyro.lid_gyroscope, gyro.base_gyroscope])),
459 _Feature('android.hardware.sensor.compass',
460 _AnyPresent(
461 [compass.lid_magnetometer, compass.base_magnetometer])),
462 _Feature('android.hardware.sensor.light',
463 _AnyPresent(
464 [ls.lid_lightsensor, ls.base_lightsensor])),
465 _Feature('android.hardware.touchscreen', touchscreen),
466 _Feature('android.hardware.touchscreen.multitouch', touchscreen),
467 _Feature(
468 'android.hardware.touchscreen.multitouch.distinct', touchscreen),
469 _Feature(
470 'android.hardware.touchscreen.multitouch.jazzhand', touchscreen),
471 ])
472
473 feature_id = _ArcHardwareFeatureId( design_config)
474
475 file_name = 'hardware_features_%s.xml' % feature_id
476 output = '%s/arc/%s' % (output_dir, file_name)
C Shapiro9a3ac8c2020-04-25 07:49:21 -0500477 file_content = minidom.parseString(
478 etree.tostring(root)).toprettyxml(indent=' ', encoding='utf-8')
479
480 with open(output, 'wb') as f:
481 f.write(file_content)
482
C Shapiro5bf23a72020-04-24 11:40:17 -0500483 result[feature_id] = {
484 'build-path': '%s/arc/%s' % (project_gen_path, file_name),
485 'system-path': '/etc/%s' % file_name,
486 }
487 return result
488
489
C Shapiro90fda252020-04-17 14:34:57 -0500490def WriteBluetoothConfigFiles(config, output_dir):
491 """Writes bluetooth conf files for every unique bluetooth chip.
492
493 Args:
494 config: Source ConfigBundle to process.
495 output_dir: Path to the generated output.
496 Returns:
497 dict that maps the bluetooth component id onto the file config.
498 """
499 project_gen_path = re.match(r'.*(generated.*)', output_dir).groups(1)[0]
500 result = {}
501 for hw_design in config.designs.value:
502 project_name = hw_design.name.lower()
503 for design_config in hw_design.configs:
504 bt_comp = design_config.hardware_features.bluetooth.component
505 if bt_comp.vendor_id:
506 bt_id = _BluetoothId(project_name, bt_comp)
507 result[bt_id] = {
C Shapiro8556b2d2020-04-22 11:04:14 -0500508 'build-path': '%s/bluetooth/%s.conf' % (project_gen_path, bt_id),
C Shapiro90fda252020-04-17 14:34:57 -0500509 'system-path': '/etc/bluetooth/%s/main.conf' % bt_id,
510 }
511 bt_content = '''[General]
512DeviceID = bluetooth:%s:%s:%s''' % (bt_comp.vendor_id,
513 bt_comp.product_id,
514 bt_comp.bcd_device)
515
516 output = '%s/bluetooth/%s.conf' % (output_dir, bt_id)
517 with open(output, 'w') as output_stream:
518 # Using print function adds proper trailing newline.
519 print(bt_content, file=output_stream)
520 return result
521
522
David Burger7fd1dbe2020-03-26 09:26:55 -0600523def _ReadConfig(path):
524 """Reads a binary proto from a file.
525
526 Args:
527 path: Path to the binary proto.
528 """
529 config = config_bundle_pb2.ConfigBundle()
530 with open(path, 'rb') as f:
531 config.ParseFromString(f.read())
532 return config
533
534
535def _MergeConfigs(configs):
536 result = config_bundle_pb2.ConfigBundle()
537 for config in configs:
538 result.MergeFrom(config)
539
540 return result
541
542
543def Main(project_configs,
544 program_config,
545 output):
546 """Transforms source proto config into platform JSON.
547
548 Args:
549 project_configs: List of source project configs to transform.
550 program_config: Program config for the given set of projects.
551 output: Output file that will be generated by the transform.
552 """
C Shapiro90fda252020-04-17 14:34:57 -0500553 configs =_MergeConfigs(
554 [_ReadConfig(program_config)] +
555 [_ReadConfig(config) for config in project_configs])
C Shapiro5bf23a72020-04-24 11:40:17 -0500556 bluetooth_files = {}
557 arc_hw_feature_files = {}
558 output_dir = os.path.dirname(output)
559 if os.path.exists(os.path.join(output_dir, 'bluetooth')):
560 bluetooth_files = WriteBluetoothConfigFiles(configs, output_dir)
561 if os.path.exists(os.path.join(output_dir, 'arc')):
562 arc_hw_feature_files = WriteArcHardwareFeatureFiles(
563 configs, output_dir)
564 config_files = ConfigFiles(
565 bluetooth=bluetooth_files,
566 arc_hw_features=arc_hw_feature_files,
567 )
568 WriteOutput(_TransformBuildConfigs(configs, config_files), output)
David Burger7fd1dbe2020-03-26 09:26:55 -0600569
570
571def main(argv=None):
572 """Main program which parses args and runs
573
574 Args:
575 argv: List of command line arguments, if None uses sys.argv.
576 """
577 if argv is None:
578 argv = sys.argv[1:]
579 opts = ParseArgs(argv)
580 Main(opts.project_configs, opts.program_config, opts.output)
581
582
583if __name__ == '__main__':
584 sys.exit(main(sys.argv[1:]))