|
9 | 9 | import logging
|
10 | 10 | import os
|
11 | 11 | import shutil
|
| 12 | +from argparse import Namespace |
| 13 | +from itertools import groupby |
12 | 14 |
|
| 15 | +import list_boards |
13 | 16 | import scl
|
14 | 17 | from twisterlib.constants import SUPPORTED_SIMS
|
15 | 18 | from twisterlib.environment import ZEPHYR_BASE
|
@@ -83,28 +86,18 @@ def __init__(self):
|
83 | 86 | self.filter_data = dict()
|
84 | 87 | self.uart = ""
|
85 | 88 | self.resc = ""
|
86 |
| - self.qualifier = None |
87 | 89 |
|
88 |
| - def load(self, board, target, aliases, data): |
| 90 | + def load(self, board, target, aliases, data, variant_data): |
89 | 91 | """Load the platform data from the board data and target data
|
90 | 92 | board: the board object as per the zephyr build system
|
91 | 93 | target: the target name of the board as per the zephyr build system
|
92 | 94 | aliases: list of aliases for the target
|
93 |
| - data: the data from the twister.yaml file for the target |
| 95 | + data: the default data from the twister.yaml file for the board |
| 96 | + variant_data: the target-specific data to replace the default data |
94 | 97 | """
|
95 | 98 | self.name = target
|
96 | 99 | self.aliases = aliases
|
97 | 100 |
|
98 |
| - # Get data for various targets and use the main board data as a |
99 |
| - # defauly. Individual variant information will replace the default data |
100 |
| - # provded in the main twister configuration for this board. |
101 |
| - variants = data.get("variants", {}) |
102 |
| - variant_data = {} |
103 |
| - for alias in aliases: |
104 |
| - variant_data = variants.get(alias, {}) |
105 |
| - if variant_data: |
106 |
| - break |
107 |
| - |
108 | 101 | self.normalized_name = self.name.replace("/", "_")
|
109 | 102 | self.sysbuild = variant_data.get("sysbuild", data.get("sysbuild", self.sysbuild))
|
110 | 103 | self.twister = variant_data.get("twister", data.get("twister", self.twister))
|
@@ -184,3 +177,116 @@ def simulator_by_name(self, sim_name: str | None) -> Simulator | None:
|
184 | 177 |
|
185 | 178 | def __repr__(self):
|
186 | 179 | return f"<{self.name} on {self.arch}>"
|
| 180 | + |
| 181 | + |
| 182 | +def generate_platforms(board_roots, soc_roots, arch_roots): |
| 183 | + """Initialize and yield all Platform instances. |
| 184 | +
|
| 185 | + Using the provided board/soc/arch roots, determine the available |
| 186 | + platform names and load the test platform description files. |
| 187 | +
|
| 188 | + An exception is raised if not all platform files are valid YAML, |
| 189 | + or if not all platform names are unique. |
| 190 | + """ |
| 191 | + alias2target = {} |
| 192 | + target2board = {} |
| 193 | + target2data = {} |
| 194 | + dir2data = {} |
| 195 | + legacy_files = [] |
| 196 | + |
| 197 | + lb_args = Namespace(board_roots=board_roots, soc_roots=soc_roots, arch_roots=arch_roots, |
| 198 | + board=None, board_dir=None) |
| 199 | + |
| 200 | + for board in list_boards.find_v2_boards(lb_args).values(): |
| 201 | + for board_dir in board.directories: |
| 202 | + if board_dir in dir2data: |
| 203 | + # don't load the same board data twice |
| 204 | + continue |
| 205 | + file = board_dir / "twister.yaml" |
| 206 | + if file.is_file(): |
| 207 | + data = scl.yaml_load_verify(file, Platform.platform_schema) |
| 208 | + else: |
| 209 | + data = None |
| 210 | + dir2data[board_dir] = data |
| 211 | + |
| 212 | + legacy_files.extend( |
| 213 | + file for file in board_dir.glob("*.yaml") if file.name != "twister.yaml" |
| 214 | + ) |
| 215 | + |
| 216 | + for qual in list_boards.board_v2_qualifiers(board): |
| 217 | + if board.revisions: |
| 218 | + for rev in board.revisions: |
| 219 | + if rev.name: |
| 220 | + target = f"{board.name}@{rev.name}/{qual}" |
| 221 | + alias2target[target] = target |
| 222 | + if rev.name == board.revision_default: |
| 223 | + alias2target[f"{board.name}/{qual}"] = target |
| 224 | + if '/' not in qual and len(board.socs) == 1: |
| 225 | + if rev.name == board.revision_default: |
| 226 | + alias2target[f"{board.name}"] = target |
| 227 | + alias2target[f"{board.name}@{rev.name}"] = target |
| 228 | + else: |
| 229 | + target = f"{board.name}/{qual}" |
| 230 | + alias2target[target] = target |
| 231 | + if '/' not in qual and len(board.socs) == 1 \ |
| 232 | + and rev.name == board.revision_default: |
| 233 | + alias2target[f"{board.name}"] = target |
| 234 | + |
| 235 | + target2board[target] = board |
| 236 | + else: |
| 237 | + target = f"{board.name}/{qual}" |
| 238 | + alias2target[target] = target |
| 239 | + if '/' not in qual and len(board.socs) == 1: |
| 240 | + alias2target[board.name] = target |
| 241 | + target2board[target] = board |
| 242 | + |
| 243 | + for board_dir, data in dir2data.items(): |
| 244 | + if data is None: |
| 245 | + continue |
| 246 | + # Separate the default and variant information in the loaded board data. |
| 247 | + # The default (top-level) data can be shared by multiple board targets; |
| 248 | + # it will be overlaid by the variant data (if present) for each target. |
| 249 | + variant_data = data.pop("variants", {}) |
| 250 | + for variant in variant_data: |
| 251 | + target = alias2target.get(variant) |
| 252 | + if target is None: |
| 253 | + continue |
| 254 | + if target in target2data: |
| 255 | + logger.error(f"Duplicate platform {target} in {board_dir}") |
| 256 | + raise Exception(f"Duplicate platform identifier {target} found") |
| 257 | + target2data[target] = variant_data[variant] |
| 258 | + |
| 259 | + # note: this inverse mapping will only be used for loading legacy files |
| 260 | + target2aliases = {} |
| 261 | + |
| 262 | + for target, aliases in groupby(alias2target, alias2target.get): |
| 263 | + aliases = list(aliases) |
| 264 | + board = target2board[target] |
| 265 | + |
| 266 | + # Default board data always comes from the primary 'board.dir'. |
| 267 | + # Other 'board.directories' can only supply variant data. |
| 268 | + data = dir2data[board.dir] |
| 269 | + if data is not None: |
| 270 | + variant_data = target2data.get(target, {}) |
| 271 | + |
| 272 | + platform = Platform() |
| 273 | + platform.load(board, target, aliases, data, variant_data) |
| 274 | + yield platform |
| 275 | + |
| 276 | + target2aliases[target] = aliases |
| 277 | + |
| 278 | + for file in legacy_files: |
| 279 | + data = scl.yaml_load_verify(file, Platform.platform_schema) |
| 280 | + target = alias2target.get(data.get("identifier")) |
| 281 | + if target is None: |
| 282 | + continue |
| 283 | + |
| 284 | + board = target2board[target] |
| 285 | + if dir2data[board.dir] is not None: |
| 286 | + # all targets are already loaded for this board |
| 287 | + logger.error(f"Duplicate platform {target} in {file.parent}") |
| 288 | + raise Exception(f"Duplicate platform identifier {target} found") |
| 289 | + |
| 290 | + platform = Platform() |
| 291 | + platform.load(board, target, target2aliases[target], data, variant_data={}) |
| 292 | + yield platform |
0 commit comments