David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 1 | #!/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 | |
| 8 | import argparse |
| 9 | import json |
| 10 | import pprint |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 11 | import os |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 12 | import sys |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 13 | import re |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 14 | import xml.etree.ElementTree as etree |
C Shapiro | 9a3ac8c | 2020-04-25 07:49:21 -0500 | [diff] [blame] | 15 | import xml.dom.minidom as minidom |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 16 | |
| 17 | from collections import namedtuple |
| 18 | |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 19 | from chromiumos.config.api import device_brand_pb2 |
David Burger | 92609a3 | 2020-04-23 10:38:50 -0600 | [diff] [blame] | 20 | from chromiumos.config.api import topology_pb2 |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 21 | from chromiumos.config.payload import config_bundle_pb2 |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 22 | from chromiumos.config.api.software import brand_config_pb2 |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 23 | |
David Burger | e6f7622 | 2020-04-27 11:08:01 -0600 | [diff] [blame] | 24 | from google.protobuf import json_format |
| 25 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 26 | Config = namedtuple('Config', |
| 27 | ['program', |
| 28 | 'hw_design', |
| 29 | 'odm', |
| 30 | 'hw_design_config', |
| 31 | 'device_brand', |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 32 | 'device_signer_config', |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 33 | 'oem', |
| 34 | 'sw_config', |
| 35 | 'brand_config', |
| 36 | 'build_target']) |
| 37 | |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 38 | ConfigFiles = namedtuple('ConfigFiles', |
| 39 | ['bluetooth', |
C Shapiro | 6830e6c | 2020-04-29 13:29:56 -0500 | [diff] [blame] | 40 | 'arc_hw_features', |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 41 | 'touch_fw', |
C Shapiro | 6830e6c | 2020-04-29 13:29:56 -0500 | [diff] [blame] | 42 | 'dptf_file']) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 43 | |
C Shapiro | 6830e6c | 2020-04-29 13:29:56 -0500 | [diff] [blame] | 44 | DPTF_PATH = 'sw_build_config/platform/chromeos-config/thermal/dptf.dv' |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 45 | TOUCH_PATH = 'sw_build_config/platform/chromeos-config/touch' |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 46 | |
| 47 | def ParseArgs(argv): |
| 48 | """Parse the available arguments. |
| 49 | |
| 50 | Invalid arguments or -h cause this function to print a message and exit. |
| 51 | |
| 52 | Args: |
| 53 | argv: List of string arguments (excluding program name / argv[0]) |
| 54 | |
| 55 | Returns: |
| 56 | argparse.Namespace object containing the attributes. |
| 57 | """ |
| 58 | parser = argparse.ArgumentParser( |
| 59 | description='Converts source proto config into platform JSON config.') |
| 60 | parser.add_argument( |
| 61 | '-c', |
| 62 | '--project_configs', |
| 63 | nargs='+', |
| 64 | type=str, |
| 65 | help='Space delimited list of source protobinary project config files.') |
| 66 | parser.add_argument( |
| 67 | '-p', |
| 68 | '--program_config', |
| 69 | type=str, |
| 70 | help='Path to the source program-level protobinary file') |
| 71 | parser.add_argument( |
| 72 | '-o', |
| 73 | '--output', |
| 74 | type=str, |
| 75 | help='Output file that will be generated') |
| 76 | return parser.parse_args(argv) |
| 77 | |
| 78 | |
| 79 | def _Set(field, target, target_name): |
| 80 | if field: |
| 81 | target[target_name] = field |
| 82 | |
| 83 | |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 84 | def _BuildArc(config, config_files): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 85 | if config.build_target.arc: |
| 86 | build_properties = { |
| 87 | 'device': config.build_target.arc.device, |
| 88 | 'first-api-level': config.build_target.arc.first_api_level, |
| 89 | 'marketing-name': config.device_brand.brand_name, |
| 90 | 'metrics-tag': config.hw_design.name.lower(), |
Andrew Lamb | b47b7dc | 2020-04-07 10:20:32 -0600 | [diff] [blame] | 91 | 'product': config.build_target.id.value, |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 92 | } |
| 93 | if config.oem: |
| 94 | build_properties['oem'] = config.oem.name |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 95 | result = { |
| 96 | 'build-properties': build_properties |
| 97 | } |
| 98 | feature_id = _ArcHardwareFeatureId(config.hw_design_config) |
| 99 | if feature_id in config_files.arc_hw_features: |
| 100 | result['hardware-features'] = config_files.arc_hw_features[feature_id] |
C Shapiro | a3f202d | 2020-05-19 08:18:45 -0500 | [diff] [blame] | 101 | topology = config.hw_design_config.hardware_topology |
| 102 | ppi = topology.screen.hardware_feature.screen.panel_properties.pixels_per_in |
| 103 | # Only set for high resolution displays |
| 104 | if ppi and ppi > 250: |
| 105 | result['scale'] = ppi |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 106 | return result |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 107 | |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 108 | def _BuildBluetooth(config, bluetooth_files): |
| 109 | bt_flags = config.sw_config.bluetooth_config.flags |
| 110 | # Convert to native map (from proto wrapper) |
| 111 | bt_flags_map = dict(bt_flags) |
| 112 | result = {} |
| 113 | if bt_flags_map: |
| 114 | result['flags'] = bt_flags_map |
C Shapiro | 74da76e | 2020-05-04 13:02:20 -0500 | [diff] [blame] | 115 | bt_comp = config.hw_design_config.hardware_features.bluetooth.component.usb |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 116 | if bt_comp.vendor_id: |
| 117 | bt_id = _BluetoothId(config.hw_design.name.lower(), bt_comp) |
| 118 | if bt_id in bluetooth_files: |
| 119 | result['config'] = bluetooth_files[bt_id] |
| 120 | return result |
| 121 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 122 | |
| 123 | def _BuildFingerprint(hw_topology): |
Andrew Lamb | c2c5546 | 2020-04-06 08:43:34 -0600 | [diff] [blame] | 124 | if hw_topology.HasField('fingerprint'): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 125 | fp = hw_topology.fingerprint.hardware_feature.fingerprint |
David Burger | 92609a3 | 2020-04-23 10:38:50 -0600 | [diff] [blame] | 126 | result = {} |
| 127 | if fp.location != topology_pb2.HardwareFeatures.Fingerprint.NOT_PRESENT: |
| 128 | location = fp.Location.DESCRIPTOR.values_by_number[fp.location].name |
| 129 | result['sensor-location'] = location.lower().replace('_', '-') |
| 130 | if fp.board: |
| 131 | result['board'] = fp.board |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 132 | return result |
| 133 | |
| 134 | |
| 135 | def _FwBcsPath(payload): |
| 136 | if payload and payload.firmware_image_name: |
| 137 | return 'bcs://%s.%d.%d.0.tbz2' % ( |
| 138 | payload.firmware_image_name, |
| 139 | payload.version.major, |
| 140 | payload.version.minor) |
| 141 | |
| 142 | |
| 143 | def _FwBuildTarget(payload): |
| 144 | if payload: |
| 145 | return payload.build_target_name |
| 146 | |
| 147 | |
| 148 | def _BuildFirmware(config): |
Andrew Lamb | 3da156d | 2020-04-16 16:00:56 -0600 | [diff] [blame] | 149 | fw_payload_config = config.sw_config.firmware |
| 150 | fw_build_config = config.sw_config.firmware_build_config |
| 151 | main_ro = fw_payload_config.main_ro_payload |
| 152 | main_rw = fw_payload_config.main_rw_payload |
| 153 | ec_ro = fw_payload_config.ec_ro_payload |
| 154 | pd_ro = fw_payload_config.pd_ro_payload |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 155 | |
| 156 | build_targets = {} |
Andrew Lamb | 3da156d | 2020-04-16 16:00:56 -0600 | [diff] [blame] | 157 | |
Andrew Lamb | f8954ee | 2020-04-21 10:24:40 -0600 | [diff] [blame] | 158 | _Set(fw_build_config.build_targets.depthcharge, build_targets, 'depthcharge') |
| 159 | _Set(fw_build_config.build_targets.coreboot, build_targets, 'coreboot') |
| 160 | _Set(fw_build_config.build_targets.ec, build_targets, 'ec') |
| 161 | _Set( |
| 162 | list(fw_build_config.build_targets.ec_extras), build_targets, 'ec_extras') |
| 163 | _Set(fw_build_config.build_targets.libpayload, build_targets, 'libpayload') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 164 | |
| 165 | result = { |
| 166 | 'bcs-overlay': config.build_target.overlay_name, |
| 167 | 'build-targets': build_targets, |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 168 | } |
Andrew Lamb | 883fa04 | 2020-04-06 11:37:22 -0600 | [diff] [blame] | 169 | |
| 170 | _Set(main_ro.firmware_image_name.lower(), result, 'image-name') |
| 171 | |
Andrew Lamb | 883fa04 | 2020-04-06 11:37:22 -0600 | [diff] [blame] | 172 | _Set(_FwBcsPath(main_ro), result, 'main-ro-image') |
| 173 | _Set(_FwBcsPath(main_rw), result, 'main-rw-image') |
| 174 | _Set(_FwBcsPath(ec_ro), result, 'ec-ro-image') |
| 175 | _Set(_FwBcsPath(pd_ro), result, 'pd-ro-image') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 176 | |
Andrew Lamb | f39fbe8 | 2020-04-13 16:14:33 -0600 | [diff] [blame] | 177 | _Set( |
| 178 | config.hw_design_config.hardware_features.fw_config.value, |
| 179 | result, |
| 180 | 'firmware-config', |
| 181 | ) |
| 182 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 183 | return result |
| 184 | |
| 185 | |
| 186 | def _BuildFwSigning(config): |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 187 | if config.sw_config.firmware and config.device_signer_config: |
David Burger | 68e0d14 | 2020-05-15 17:29:33 -0600 | [diff] [blame] | 188 | program = config.program.id.value |
| 189 | hw_design = config.hw_design.name.lower() |
David Burger | 4a34465 | 2020-05-15 19:45:26 -0600 | [diff] [blame] | 190 | brand_code = config.device_brand.brand_code |
| 191 | if program == 'Zork' and brand_code == 'ZZCR': |
| 192 | # TODO(https://crbug.com/1070814): Hack!!!, Zork projects that do not have |
| 193 | # their own brand-code do not share signing keys. Thus this hack for now. |
David Burger | f762dee | 2020-05-17 05:58:58 -0600 | [diff] [blame] | 194 | # TODO(https://crbug.com/1083770): Also, Berknip signing keys not present |
| 195 | # in signing server, special case. |
| 196 | key_id = 'TREMBYLE' if hw_design == 'berknip' else hw_design.upper() |
David Burger | 68e0d14 | 2020-05-15 17:29:33 -0600 | [diff] [blame] | 197 | return { |
David Burger | f762dee | 2020-05-17 05:58:58 -0600 | [diff] [blame] | 198 | 'key-id': key_id, |
David Burger | 68e0d14 | 2020-05-15 17:29:33 -0600 | [diff] [blame] | 199 | 'signature-id': hw_design, |
| 200 | } |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 201 | return { |
| 202 | 'key-id': config.device_signer_config.key_id, |
David Burger | 68e0d14 | 2020-05-15 17:29:33 -0600 | [diff] [blame] | 203 | 'signature-id': hw_design, |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 204 | } |
| 205 | return {} |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 206 | |
| 207 | |
| 208 | def _File(source, destination): |
| 209 | return { |
| 210 | 'destination': destination, |
| 211 | 'source': source |
| 212 | } |
| 213 | |
| 214 | |
| 215 | def _BuildAudio(config): |
| 216 | alsa_path = '/usr/share/alsa/ucm' |
| 217 | cras_path = '/etc/cras' |
| 218 | project_name = config.hw_design.name.lower() |
David Burger | 4325066 | 2020-05-07 11:21:50 -0600 | [diff] [blame] | 219 | program_name = config.program.name.lower() |
Andrew Lamb | 7d53678 | 2020-04-07 10:23:55 -0600 | [diff] [blame] | 220 | if not config.sw_config.HasField('audio_config'): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 221 | return {} |
| 222 | audio = config.sw_config.audio_config |
| 223 | card = audio.card_name |
David Burger | 599ff7b | 2020-04-06 16:29:31 -0600 | [diff] [blame] | 224 | card_with_suffix = audio.card_name |
| 225 | if audio.ucm_suffix: |
| 226 | card_with_suffix += '.' + audio.ucm_suffix |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 227 | files = [] |
| 228 | if audio.ucm_file: |
David Burger | 599ff7b | 2020-04-06 16:29:31 -0600 | [diff] [blame] | 229 | files.append(_File( |
| 230 | audio.ucm_file, |
| 231 | '%s/%s/HiFi.conf' % (alsa_path, card_with_suffix))) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 232 | if audio.ucm_master_file: |
| 233 | files.append(_File( |
David Burger | 599ff7b | 2020-04-06 16:29:31 -0600 | [diff] [blame] | 234 | audio.ucm_master_file, |
| 235 | '%s/%s/%s.conf' % (alsa_path, card_with_suffix, card_with_suffix))) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 236 | if audio.card_config_file: |
| 237 | files.append(_File( |
| 238 | audio.card_config_file, '%s/%s/%s' % (cras_path, project_name, card))) |
| 239 | if audio.dsp_file: |
| 240 | files.append( |
David Burger | 2e25490 | 2020-04-02 16:56:01 -0600 | [diff] [blame] | 241 | _File(audio.dsp_file, '%s/%s/dsp.ini' % (cras_path, project_name))) |
David Burger | e1a3749 | 2020-05-06 09:29:24 -0600 | [diff] [blame] | 242 | if audio.module_file: |
| 243 | files.append( |
David Burger | 4325066 | 2020-05-07 11:21:50 -0600 | [diff] [blame] | 244 | _File(audio.module_file, '/etc/modprobe.d/alsa-%s.conf' % program_name)) |
David Burger | e1a3749 | 2020-05-06 09:29:24 -0600 | [diff] [blame] | 245 | if audio.board_file: |
| 246 | files.append( |
| 247 | _File(audio.board_file, '%s/%s/board.ini' % (cras_path, project_name))) |
David Burger | 599ff7b | 2020-04-06 16:29:31 -0600 | [diff] [blame] | 248 | |
| 249 | result = { |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 250 | 'main': { |
| 251 | 'cras-config-dir': project_name, |
| 252 | 'files': files, |
| 253 | } |
| 254 | } |
David Burger | 599ff7b | 2020-04-06 16:29:31 -0600 | [diff] [blame] | 255 | if audio.ucm_suffix: |
David Burger | 03cdcbd | 2020-04-13 13:54:48 -0600 | [diff] [blame] | 256 | result['main']['ucm-suffix'] = audio.ucm_suffix |
David Burger | 599ff7b | 2020-04-06 16:29:31 -0600 | [diff] [blame] | 257 | |
| 258 | return result |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 259 | |
| 260 | |
David Burger | 8aa8fa3 | 2020-04-14 08:30:34 -0600 | [diff] [blame] | 261 | def _BuildCamera(hw_topology): |
| 262 | if hw_topology.HasField('camera'): |
| 263 | camera = hw_topology.camera.hardware_feature.camera |
| 264 | result = {} |
| 265 | if camera.count.value: |
| 266 | result['count'] = camera.count.value |
| 267 | return result |
| 268 | |
| 269 | |
Andrew Lamb | 7806ce9 | 2020-04-07 10:22:17 -0600 | [diff] [blame] | 270 | def _BuildIdentity(hw_scan_config, program, brand_scan_config=None): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 271 | identity = {} |
| 272 | _Set(hw_scan_config.firmware_sku, identity, 'sku-id') |
| 273 | _Set(hw_scan_config.smbios_name_match, identity, 'smbios-name-match') |
Andrew Lamb | 7806ce9 | 2020-04-07 10:22:17 -0600 | [diff] [blame] | 274 | # 'platform-name' is needed to support 'mosys platform name'. Clients should |
| 275 | # longer require platform name, but set it here for backwards compatibility. |
| 276 | _Set(program.name, identity, 'platform-name') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 277 | # ARM architecture |
| 278 | _Set(hw_scan_config.device_tree_compatible_match, identity, |
| 279 | 'device-tree-compatible-match') |
| 280 | |
| 281 | if brand_scan_config: |
| 282 | _Set(brand_scan_config.whitelabel_tag, identity, 'whitelabel-tag') |
| 283 | |
| 284 | return identity |
| 285 | |
| 286 | |
| 287 | def _Lookup(id_value, id_map): |
| 288 | if id_value.value: |
| 289 | key = id_value.value |
| 290 | if key in id_map: |
| 291 | return id_map[id_value.value] |
| 292 | error = 'Failed to lookup %s with value: %s' % ( |
| 293 | id_value.__class__.__name__.replace('Id', ''), key) |
| 294 | print(error) |
| 295 | print('Check the config contents provided:') |
| 296 | pp = pprint.PrettyPrinter(indent=4) |
| 297 | pp.pprint(id_map) |
| 298 | raise Exception(error) |
| 299 | |
| 300 | |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 301 | def _BuildTouchFileConfig(config, project_name): |
| 302 | partners = dict([(x.id.value, x) for x in config.partners.value]) |
| 303 | files = [] |
| 304 | for comp in config.components: |
C Shapiro | 4813be6 | 2020-05-13 17:31:58 -0500 | [diff] [blame] | 305 | touch = comp.touchscreen |
| 306 | # Everything is the same for Touch screen/pad, except different fields |
| 307 | if comp.HasField('touchpad'): |
| 308 | touch = comp.touchpad |
| 309 | if touch.product_id: |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 310 | vendor = _Lookup(comp.manufacturer_id, partners) |
| 311 | if not vendor: |
| 312 | raise Exception( |
C Shapiro | 4813be6 | 2020-05-13 17:31:58 -0500 | [diff] [blame] | 313 | "Manufacturer must be set for touch device %s" % comp.id.value) |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 314 | |
C Shapiro | 4813be6 | 2020-05-13 17:31:58 -0500 | [diff] [blame] | 315 | product_id = touch.product_id |
| 316 | fw_version = touch.fw_version |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 317 | |
C Shapiro | 5c6fc21 | 2020-05-13 16:32:09 -0500 | [diff] [blame] | 318 | touch_vendor = vendor.touch_vendor |
| 319 | sym_link = touch_vendor.fw_file_format.format( |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 320 | vendor_name = vendor.name, |
C Shapiro | 5c6fc21 | 2020-05-13 16:32:09 -0500 | [diff] [blame] | 321 | vendor_id = touch_vendor.vendor_id, |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 322 | product_id = product_id, |
| 323 | fw_version = fw_version, |
C Shapiro | 4813be6 | 2020-05-13 17:31:58 -0500 | [diff] [blame] | 324 | product_series = touch.product_series |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 325 | ) |
| 326 | |
| 327 | file_name = "%s_%s.bin" % (product_id, fw_version) |
| 328 | fw_file_path = os.path.join(TOUCH_PATH, vendor.name, file_name) |
| 329 | |
| 330 | if not os.path.exists(fw_file_path): |
| 331 | raise Exception( |
| 332 | "Touchscreen fw bin file doesn't exist at: %s" % fw_file_path) |
| 333 | |
| 334 | files.append({ |
| 335 | "destination": "/opt/google/touch/firmware/%s_%s" % ( |
| 336 | vendor.name, file_name), |
| 337 | "source": os.path.join(project_name, fw_file_path), |
| 338 | "symlink": os.path.join("/lib/firmware", sym_link), |
| 339 | }) |
| 340 | |
| 341 | result = {} |
| 342 | _Set(files, result, 'files') |
| 343 | return result |
| 344 | |
| 345 | |
| 346 | def _TransformBuildConfigs(config, config_files=ConfigFiles({}, {}, {}, None)): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 347 | partners = dict([(x.id.value, x) for x in config.partners.value]) |
| 348 | programs = dict([(x.id.value, x) for x in config.programs.value]) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 349 | sw_configs = list(config.software_configs) |
| 350 | brand_configs = dict([(x.brand_id.value, x) for x in config.brand_configs]) |
| 351 | |
C Shapiro | a0b766c | 2020-03-31 08:35:28 -0500 | [diff] [blame] | 352 | if len(config.build_targets) != 1: |
| 353 | # Artifact of sharing the config_bundle for analysis and transforms. |
| 354 | # Integrated analysis of multiple programs/projects it the only time |
| 355 | # having multiple build targets would be valid. |
| 356 | raise Exception('Single build_target required for transform') |
| 357 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 358 | results = {} |
| 359 | for hw_design in config.designs.value: |
| 360 | if config.device_brands.value: |
| 361 | device_brands = [x for x in config.device_brands.value |
| 362 | if x.design_id.value == hw_design.id.value] |
| 363 | else: |
| 364 | device_brands = [device_brand_pb2.DeviceBrand()] |
| 365 | |
| 366 | for device_brand in device_brands: |
| 367 | # Brand config can be empty since platform JSON config allows it |
| 368 | brand_config = brand_config_pb2.BrandConfig() |
| 369 | if device_brand.id.value in brand_configs: |
| 370 | brand_config = brand_configs[device_brand.id.value] |
| 371 | |
| 372 | for hw_design_config in hw_design.configs: |
| 373 | design_id = hw_design_config.id.value |
| 374 | sw_config_matches = [x for x in sw_configs |
| 375 | if x.design_config_id.value == design_id] |
| 376 | if len(sw_config_matches) == 1: |
| 377 | sw_config = sw_config_matches[0] |
| 378 | elif len(sw_config_matches) > 1: |
| 379 | raise Exception('Multiple software configs found for: %s' % design_id) |
| 380 | else: |
| 381 | raise Exception('Software config is required for: %s' % design_id) |
| 382 | |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 383 | program = _Lookup(hw_design.program_id, programs) |
| 384 | signer_configs = dict( |
| 385 | [(x.brand_id.value, x) for x in program.device_signer_configs]) |
| 386 | device_signer_config = None |
| 387 | if signer_configs: |
| 388 | device_signer_config = _Lookup(device_brand.id, signer_configs) |
| 389 | |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 390 | transformed_config = _TransformBuildConfig( |
| 391 | Config( |
| 392 | program=program, |
| 393 | hw_design=hw_design, |
| 394 | odm=_Lookup(hw_design.odm_id, partners), |
| 395 | hw_design_config=hw_design_config, |
| 396 | device_brand=device_brand, |
| 397 | device_signer_config=device_signer_config, |
| 398 | oem=_Lookup(device_brand.oem_id, partners), |
| 399 | sw_config=sw_config, |
| 400 | brand_config=brand_config, |
| 401 | build_target=config.build_targets[0]), |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 402 | config_files) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 403 | |
| 404 | config_json = json.dumps(transformed_config, |
| 405 | sort_keys=True, |
| 406 | indent=2, |
| 407 | separators=(',', ': ')) |
| 408 | |
| 409 | if config_json not in results: |
| 410 | results[config_json] = transformed_config |
| 411 | |
| 412 | return list(results.values()) |
| 413 | |
| 414 | |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 415 | def _TransformBuildConfig(config, config_files): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 416 | """Transforms Config instance into target platform JSON schema. |
| 417 | |
| 418 | Args: |
| 419 | config: Config namedtuple |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 420 | config_files: Map to look up the generated config files. |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 421 | |
| 422 | Returns: |
| 423 | Unique config payload based on the platform JSON schema. |
| 424 | """ |
| 425 | result = { |
| 426 | 'identity': _BuildIdentity( |
| 427 | config.sw_config.id_scan_config, |
Andrew Lamb | 7806ce9 | 2020-04-07 10:22:17 -0600 | [diff] [blame] | 428 | config.program, |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 429 | config.brand_config.scan_config), |
| 430 | 'name': config.hw_design.name.lower(), |
| 431 | } |
| 432 | |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 433 | _Set(_BuildArc(config, config_files), result, 'arc') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 434 | _Set(_BuildAudio(config), result, 'audio') |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 435 | _Set(_BuildBluetooth(config, config_files.bluetooth), result, 'bluetooth') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 436 | _Set(config.device_brand.brand_code, result, 'brand-code') |
David Burger | 8aa8fa3 | 2020-04-14 08:30:34 -0600 | [diff] [blame] | 437 | _Set(_BuildCamera( |
| 438 | config.hw_design_config.hardware_topology), result, 'camera') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 439 | _Set(_BuildFirmware(config), result, 'firmware') |
| 440 | _Set(_BuildFwSigning(config), result, 'firmware-signing') |
| 441 | _Set(_BuildFingerprint( |
| 442 | config.hw_design_config.hardware_topology), result, 'fingerprint') |
| 443 | power_prefs = config.sw_config.power_config.preferences |
| 444 | power_prefs_map = dict( |
| 445 | (x.replace('_', '-'), |
| 446 | power_prefs[x]) for x in power_prefs) |
| 447 | _Set(power_prefs_map, result, 'power') |
C Shapiro | 6830e6c | 2020-04-29 13:29:56 -0500 | [diff] [blame] | 448 | _Set(config_files.dptf_file, result, 'thermal') |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 449 | _Set(config_files.touch_fw, result, 'touch') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 450 | |
| 451 | return result |
| 452 | |
| 453 | |
| 454 | def WriteOutput(configs, output=None): |
| 455 | """Writes a list of configs to platform JSON format. |
| 456 | |
| 457 | Args: |
| 458 | configs: List of config dicts defined in cros_config_schema.yaml |
| 459 | output: Target file output (if None, prints to stdout) |
| 460 | """ |
| 461 | json_output = json.dumps( |
| 462 | {'chromeos': { |
| 463 | 'configs': configs, |
| 464 | }}, |
| 465 | sort_keys=True, |
| 466 | indent=2, |
| 467 | separators=(',', ': ')) |
| 468 | if output: |
| 469 | with open(output, 'w') as output_stream: |
| 470 | # Using print function adds proper trailing newline. |
| 471 | print(json_output, file=output_stream) |
| 472 | else: |
| 473 | print(json_output) |
| 474 | |
| 475 | |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 476 | def _BluetoothId(project_name, bt_comp): |
| 477 | return '_'.join([project_name, |
| 478 | bt_comp.vendor_id, |
| 479 | bt_comp.product_id, |
| 480 | bt_comp.bcd_device]) |
| 481 | |
| 482 | |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 483 | def _Feature(name, present): |
| 484 | attrib = {'name': name} |
| 485 | if present: |
| 486 | return etree.Element('feature', attrib=attrib) |
| 487 | else: |
| 488 | return etree.Element('unavailable-feature', attrib=attrib) |
| 489 | |
| 490 | |
| 491 | def _AnyPresent(features): |
| 492 | return topology_pb2.HardwareFeatures.PRESENT in features; |
| 493 | |
| 494 | |
| 495 | def _ArcHardwareFeatureId(design_config): |
| 496 | return design_config.id.value.lower().replace(':', '_') |
| 497 | |
| 498 | |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 499 | def _WriteArcHardwareFeatureFile(output_dir, file_name, config_content): |
| 500 | output = '%s/arc/%s' % (output_dir, file_name) |
| 501 | file_content = minidom.parseString( |
| 502 | config_content).toprettyxml(indent=' ', encoding='utf-8') |
| 503 | |
| 504 | with open(output, 'wb') as f: |
| 505 | f.write(file_content) |
| 506 | |
| 507 | |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 508 | def WriteArcHardwareFeatureFiles(config, output_dir, build_root_dir): |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 509 | """Writes ARC hardware_feature.xml files for each config |
| 510 | |
| 511 | Args: |
| 512 | config: Source ConfigBundle to process. |
| 513 | output_dir: Path to the generated output. |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 514 | build_root_path: Path to the config file from portage's perspective. |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 515 | Returns: |
| 516 | dict that maps the design_config_id onto the correct file. |
| 517 | """ |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 518 | result = {} |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 519 | configs_by_design = {} |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 520 | for hw_design in config.designs.value: |
| 521 | for design_config in hw_design.configs: |
| 522 | hw_features = design_config.hardware_features |
| 523 | multi_camera = hw_features.camera.count == 2 |
| 524 | touchscreen = _AnyPresent([hw_features.screen.touch_support]) |
| 525 | acc = hw_features.accelerometer |
| 526 | gyro = hw_features.gyroscope |
| 527 | compass = hw_features.magnetometer |
| 528 | ls = hw_features.light_sensor |
| 529 | root = etree.Element('permissions') |
| 530 | root.extend([ |
| 531 | _Feature('android.hardware.camera', multi_camera), |
| 532 | _Feature('android.hardware.camera.autofocus', multi_camera), |
| 533 | _Feature('android.hardware.sensor.accelerometer', |
| 534 | _AnyPresent( |
| 535 | [acc.lid_accelerometer, acc.base_accelerometer])), |
| 536 | _Feature('android.hardware.sensor.gyroscope', |
| 537 | _AnyPresent( |
| 538 | [gyro.lid_gyroscope, gyro.base_gyroscope])), |
| 539 | _Feature('android.hardware.sensor.compass', |
| 540 | _AnyPresent( |
| 541 | [compass.lid_magnetometer, compass.base_magnetometer])), |
| 542 | _Feature('android.hardware.sensor.light', |
| 543 | _AnyPresent( |
| 544 | [ls.lid_lightsensor, ls.base_lightsensor])), |
| 545 | _Feature('android.hardware.touchscreen', touchscreen), |
| 546 | _Feature('android.hardware.touchscreen.multitouch', touchscreen), |
| 547 | _Feature( |
| 548 | 'android.hardware.touchscreen.multitouch.distinct', touchscreen), |
| 549 | _Feature( |
| 550 | 'android.hardware.touchscreen.multitouch.jazzhand', touchscreen), |
| 551 | ]) |
| 552 | |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 553 | design_name = hw_design.name.lower() |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 554 | |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 555 | # Constructs the following map: |
| 556 | # design_name -> config -> design_configs |
| 557 | # This allows any of the following file naming schemes: |
| 558 | # - All configs within a design share config (design_name prefix only) |
| 559 | # - Nobody shares (full design_name and config id prefix needed) |
| 560 | # |
| 561 | # Having shared configs when possible makes code reviews easier around |
| 562 | # the configs and makes debugging easier on the platform side. |
| 563 | config_content = etree.tostring(root) |
| 564 | arc_configs = configs_by_design.get(design_name, {}) |
| 565 | design_configs = arc_configs.get(config_content, []) |
| 566 | design_configs.append(design_config) |
| 567 | arc_configs[config_content] = design_configs |
| 568 | configs_by_design[design_name] = arc_configs |
C Shapiro | 9a3ac8c | 2020-04-25 07:49:21 -0500 | [diff] [blame] | 569 | |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 570 | for design_name, unique_configs in configs_by_design.items(): |
| 571 | for file_content, design_configs in unique_configs.items(): |
| 572 | file_name = 'hardware_features_%s.xml' % design_name |
| 573 | if len(unique_configs) == 1: |
| 574 | _WriteArcHardwareFeatureFile(output_dir, file_name, file_content) |
C Shapiro | 9a3ac8c | 2020-04-25 07:49:21 -0500 | [diff] [blame] | 575 | |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 576 | for design_config in design_configs: |
| 577 | feature_id = _ArcHardwareFeatureId(design_config) |
| 578 | if len(unique_configs) > 1: |
| 579 | file_name = 'hardware_features_%s.xml' % feature_id |
| 580 | _WriteArcHardwareFeatureFile(output_dir, file_name, file_content) |
| 581 | result[feature_id] = { |
| 582 | 'build-path': '%s/arc/%s' % (build_root_dir, file_name), |
| 583 | 'system-path': '/etc/%s' % file_name, |
| 584 | } |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 585 | return result |
| 586 | |
| 587 | |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 588 | def WriteBluetoothConfigFiles(config, output_dir, build_root_path): |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 589 | """Writes bluetooth conf files for every unique bluetooth chip. |
| 590 | |
| 591 | Args: |
| 592 | config: Source ConfigBundle to process. |
| 593 | output_dir: Path to the generated output. |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 594 | build_root_path: Path to the config file from portage's perspective. |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 595 | Returns: |
| 596 | dict that maps the bluetooth component id onto the file config. |
| 597 | """ |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 598 | result = {} |
| 599 | for hw_design in config.designs.value: |
| 600 | project_name = hw_design.name.lower() |
| 601 | for design_config in hw_design.configs: |
C Shapiro | 74da76e | 2020-05-04 13:02:20 -0500 | [diff] [blame] | 602 | bt_comp = design_config.hardware_features.bluetooth.component.usb |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 603 | if bt_comp.vendor_id: |
| 604 | bt_id = _BluetoothId(project_name, bt_comp) |
| 605 | result[bt_id] = { |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 606 | 'build-path': '%s/bluetooth/%s.conf' % (build_root_path, bt_id), |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 607 | 'system-path': '/etc/bluetooth/%s/main.conf' % bt_id, |
| 608 | } |
| 609 | bt_content = '''[General] |
| 610 | DeviceID = bluetooth:%s:%s:%s''' % (bt_comp.vendor_id, |
| 611 | bt_comp.product_id, |
| 612 | bt_comp.bcd_device) |
| 613 | |
| 614 | output = '%s/bluetooth/%s.conf' % (output_dir, bt_id) |
| 615 | with open(output, 'w') as output_stream: |
| 616 | # Using print function adds proper trailing newline. |
| 617 | print(bt_content, file=output_stream) |
| 618 | return result |
| 619 | |
| 620 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 621 | def _ReadConfig(path): |
David Burger | d4f3296 | 2020-05-02 12:07:40 -0600 | [diff] [blame] | 622 | """Reads a ConfigBundle proto from a json pb file. |
David Burger | e6f7622 | 2020-04-27 11:08:01 -0600 | [diff] [blame] | 623 | |
| 624 | Args: |
David Burger | d4f3296 | 2020-05-02 12:07:40 -0600 | [diff] [blame] | 625 | path: Path to the file encoding the json pb proto. |
David Burger | e6f7622 | 2020-04-27 11:08:01 -0600 | [diff] [blame] | 626 | """ |
| 627 | config = config_bundle_pb2.ConfigBundle() |
| 628 | with open(path, 'r') as f: |
| 629 | return json_format.Parse(f.read(), config) |
| 630 | |
| 631 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 632 | def _MergeConfigs(configs): |
| 633 | result = config_bundle_pb2.ConfigBundle() |
| 634 | for config in configs: |
| 635 | result.MergeFrom(config) |
| 636 | |
| 637 | return result |
| 638 | |
| 639 | |
| 640 | def Main(project_configs, |
| 641 | program_config, |
| 642 | output): |
| 643 | """Transforms source proto config into platform JSON. |
| 644 | |
| 645 | Args: |
| 646 | project_configs: List of source project configs to transform. |
| 647 | program_config: Program config for the given set of projects. |
| 648 | output: Output file that will be generated by the transform. |
| 649 | """ |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 650 | configs =_MergeConfigs( |
| 651 | [_ReadConfig(program_config)] + |
| 652 | [_ReadConfig(config) for config in project_configs]) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 653 | bluetooth_files = {} |
| 654 | arc_hw_feature_files = {} |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 655 | touch_fw = {} |
C Shapiro | 6830e6c | 2020-04-29 13:29:56 -0500 | [diff] [blame] | 656 | dptf_file = None |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 657 | output_dir = os.path.dirname(output) |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 658 | build_root_dir = output_dir |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 659 | if 'sw_build_config' in output_dir: |
| 660 | full_path = os.path.realpath(output) |
C Shapiro | 6438fb3 | 2020-05-01 16:43:49 -0500 | [diff] [blame] | 661 | project_name = re.match( |
| 662 | r'.*/(\w*)/sw_build_config/.*', full_path).groups(1)[0] |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 663 | # Projects don't know about each other until they are integrated into the |
| 664 | # build system. When this happens, the files need to be able to co-exist |
| 665 | # without any collisions. This prefixes the project name (which is how |
| 666 | # portage maps in the project), so project files co-exist and can be |
| 667 | # installed together. |
| 668 | # This is necessary to allow projects to share files at the program level |
| 669 | # without having portage file installation collisions. |
| 670 | build_root_dir = os.path.join(project_name, output_dir) |
C Shapiro | 6830e6c | 2020-04-29 13:29:56 -0500 | [diff] [blame] | 671 | |
C Shapiro | 7356bd6 | 2020-05-02 05:21:33 -0500 | [diff] [blame] | 672 | if os.path.exists(DPTF_PATH): |
| 673 | project_dptf_path = os.path.join(project_name, 'dptf.dv') |
| 674 | dptf_file = { |
| 675 | 'dptf-dv': project_dptf_path, |
| 676 | 'files': [_File(os.path.join(project_name, DPTF_PATH), |
| 677 | os.path.join('/etc/dptf', project_dptf_path))] |
| 678 | } |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 679 | if os.path.exists(TOUCH_PATH): |
| 680 | touch_fw = _BuildTouchFileConfig(configs, project_name) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 681 | if os.path.exists(os.path.join(output_dir, 'bluetooth')): |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 682 | bluetooth_files = WriteBluetoothConfigFiles( |
| 683 | configs, output_dir, build_root_dir) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 684 | if os.path.exists(os.path.join(output_dir, 'arc')): |
| 685 | arc_hw_feature_files = WriteArcHardwareFeatureFiles( |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 686 | configs, output_dir, build_root_dir) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 687 | config_files = ConfigFiles( |
| 688 | bluetooth=bluetooth_files, |
| 689 | arc_hw_features=arc_hw_feature_files, |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 690 | touch_fw=touch_fw, |
C Shapiro | 6830e6c | 2020-04-29 13:29:56 -0500 | [diff] [blame] | 691 | dptf_file=dptf_file |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 692 | ) |
| 693 | WriteOutput(_TransformBuildConfigs(configs, config_files), output) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 694 | |
| 695 | |
| 696 | def main(argv=None): |
| 697 | """Main program which parses args and runs |
| 698 | |
| 699 | Args: |
| 700 | argv: List of command line arguments, if None uses sys.argv. |
| 701 | """ |
| 702 | if argv is None: |
| 703 | argv = sys.argv[1:] |
| 704 | opts = ParseArgs(argv) |
| 705 | Main(opts.project_configs, opts.program_config, opts.output) |
| 706 | |
| 707 | |
| 708 | if __name__ == '__main__': |
| 709 | sys.exit(main(sys.argv[1:])) |