Status file format Status file := [section] section = [CONDITION, section_rules] section_rules := {path: outcomes} outcomes := outcome | [outcome, ...] outcome := SINGLE_OUTCOME | [CONDITION, SINGLE_OUTCOME, SINGLE_OUTCOME, ...]
(content, variables)
| 238 | |
| 239 | |
| 240 | def ReadStatusFile(content, variables): |
| 241 | """Status file format |
| 242 | Status file := [section] |
| 243 | section = [CONDITION, section_rules] |
| 244 | section_rules := {path: outcomes} |
| 245 | outcomes := outcome | [outcome, ...] |
| 246 | outcome := SINGLE_OUTCOME | [CONDITION, SINGLE_OUTCOME, SINGLE_OUTCOME, ...] |
| 247 | """ |
| 248 | |
| 249 | # Empty defaults for rules and prefix_rules. Variant-independent |
| 250 | # rules are mapped by "", others by the variant name. |
| 251 | rules = {variant: {} for variant in ALL_VARIANTS} |
| 252 | rules[""] = {} |
| 253 | prefix_rules = {variant: {} for variant in ALL_VARIANTS} |
| 254 | prefix_rules[""] = {} |
| 255 | |
| 256 | # This method can be called with the same `variables` object multiple times. |
| 257 | # Ensure we only update `variables` (and check it for consistency) once. |
| 258 | if ALWAYS not in variables: |
| 259 | # Ensure we don't silently overwrite any build variables with our set of |
| 260 | # default keywords in VARIABLES. |
| 261 | for var in VARIABLES: |
| 262 | assert var not in variables, ( |
| 263 | "build_config variable '%s' conflicts with VARIABLES" % var) |
| 264 | variables.update(VARIABLES) |
| 265 | |
| 266 | for conditional_section in ReadContent(content): |
| 267 | assert type(conditional_section) == list |
| 268 | assert len(conditional_section) == 2 |
| 269 | condition, section = conditional_section |
| 270 | exp = _EvalExpression(condition, variables) |
| 271 | |
| 272 | # The expression is variant-independent and evaluates to False. |
| 273 | if exp is False: |
| 274 | continue |
| 275 | |
| 276 | # The expression is variant-independent and evaluates to True. |
| 277 | if exp is True: |
| 278 | _ReadSection( |
| 279 | section, |
| 280 | variables, |
| 281 | rules[''], |
| 282 | prefix_rules[''], |
| 283 | ) |
| 284 | continue |
| 285 | |
| 286 | # The expression is variant-dependent (contains "variant" keyword) |
| 287 | if exp == VARIANT_EXPRESSION: |
| 288 | # If the expression contains one or more "variant" keywords, we evaluate |
| 289 | # it for all possible variants and create rules for those that apply. |
| 290 | for variant in ALL_VARIANTS: |
| 291 | _EvalVariantExpression( |
| 292 | condition, section, variables, variant, rules, prefix_rules) |
| 293 | continue |
| 294 | |
| 295 | assert False, "Make sure expressions evaluate to boolean values" |
| 296 | |
| 297 | return Freeze(rules), Freeze(prefix_rules) |
no test coverage detected