|
| 1 | +# Copyright lowRISC contributors (OpenTitan project). |
| 2 | +# Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +"""Pydantic models for lint flow configuration.""" |
| 6 | + |
| 7 | + |
| 8 | +from pydantic import BaseModel, ConfigDict, Field |
| 9 | + |
| 10 | + |
| 11 | +class MessageBucket(BaseModel): |
| 12 | + """Message bucket configuration for categorizing lint messages.""" |
| 13 | + |
| 14 | + model_config = ConfigDict(frozen=True) |
| 15 | + |
| 16 | + category: str = Field(..., description="Message category (e.g., 'flow', 'lint')") |
| 17 | + severity: str = Field(..., description="Message severity (e.g., 'info', 'warning', 'error')") |
| 18 | + label: str = Field(default="", description="Optional label for the bucket") |
| 19 | + |
| 20 | + |
| 21 | +class LintFlowConfig(BaseModel): |
| 22 | + """Configuration for the lint flow. |
| 23 | +
|
| 24 | + This model represents the core lint flow configuration that can be parsed |
| 25 | + from hjson files. It focuses on lint-specific fields and does not include |
| 26 | + all the base flow configuration fields that are handled by the existing |
| 27 | + FlowCfg class hierarchy. |
| 28 | + """ |
| 29 | + |
| 30 | + # Flow identification |
| 31 | + flow: str = Field(default="lint", description="Flow type identifier") |
| 32 | + name: str = Field(..., description="Name of the lint configuration") |
| 33 | + |
| 34 | + # Build configuration |
| 35 | + build_dir: str = Field(default="", description="Build directory path") |
| 36 | + build_log: str = Field(default="", description="Build log file path") |
| 37 | + build_cmd: str = Field(default="", description="Build command") |
| 38 | + build_opts: list[str] = Field(default_factory=list, description="Build options") |
| 39 | + |
| 40 | + # FuseSoC configuration |
| 41 | + fusesoc_core: str = Field(default="", description="FuseSoC core to use") |
| 42 | + additional_fusesoc_argument: str = Field( |
| 43 | + default="", description="Additional FuseSoC argument (e.g., mapping)" |
| 44 | + ) |
| 45 | + |
| 46 | + # Lint-specific configuration |
| 47 | + is_style_lint: bool = Field(default=False, description="Whether this is a style lint run") |
| 48 | + report_severities: list[str] = Field( |
| 49 | + default_factory=lambda: ["info", "warning", "error"], |
| 50 | + description="Message severities to include in reports", |
| 51 | + ) |
| 52 | + fail_severities: list[str] = Field( |
| 53 | + default_factory=lambda: ["warning", "error"], |
| 54 | + description="Message severities that cause the flow to fail", |
| 55 | + ) |
| 56 | + message_buckets: list[MessageBucket] = Field( |
| 57 | + default_factory=list, description="Message bucket configuration" |
| 58 | + ) |
| 59 | + |
| 60 | + # Tool configuration |
| 61 | + tool: str | None = Field(default=None, description="Lint tool to use") |
| 62 | + dut: str = Field(default="", description="Design under test name") |
| 63 | + |
| 64 | + # Directory paths |
| 65 | + scratch_path: str = Field(default="", description="Scratch directory path") |
| 66 | + rel_path: str = Field(default="", description="Relative path for results") |
| 67 | + |
| 68 | + # Import and use configurations |
| 69 | + import_cfgs: list[str] = Field( |
| 70 | + default_factory=list, description="Configuration files to import" |
| 71 | + ) |
| 72 | + use_cfgs: list[dict | str] = Field( |
| 73 | + default_factory=list, description="Sub-configurations to use (for primary configs)" |
| 74 | + ) |
| 75 | + |
| 76 | + model_config = ConfigDict( |
| 77 | + frozen=True, # Make the model immutable |
| 78 | + extra="allow", # Allow extra fields for forwards compatibility |
| 79 | + ) |
0 commit comments