|
| 1 | +"""Artifact-related domain models.""" |
| 2 | + |
| 3 | +from dataclasses import dataclass |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +from packaging.version import Version |
| 7 | + |
| 8 | +from ..platform_capabilities import EmulationCapability |
| 9 | +from .platforms import Platform |
| 10 | +from .versions import SolcVersion |
| 11 | + |
| 12 | + |
| 13 | +@dataclass(kw_only=True) |
| 14 | +class SolcArtifactOnDisk: |
| 15 | + """Represents a Solidity compiler artifact on disk.""" |
| 16 | + |
| 17 | + version: SolcVersion |
| 18 | + platform: Platform |
| 19 | + file_path: Path |
| 20 | + emulation: EmulationCapability | None = None # Emulation info if not native |
| 21 | + |
| 22 | + |
| 23 | +@dataclass(kw_only=True) |
| 24 | +class SolcArtifact(SolcArtifactOnDisk): |
| 25 | + """Represents a downloadable Solidity compiler artifact.""" |
| 26 | + |
| 27 | + download_url: str |
| 28 | + checksum_sha256: str |
| 29 | + checksum_keccak256: str | None |
| 30 | + |
| 31 | + def __post_init__(self) -> None: |
| 32 | + """Validate artifact properties.""" |
| 33 | + if not self.download_url: |
| 34 | + raise ValueError("Download URL cannot be empty") |
| 35 | + if not self.checksum_sha256: |
| 36 | + raise ValueError("SHA256 checksum cannot be empty") |
| 37 | + if self.checksum_sha256.startswith("0x"): |
| 38 | + # Normalize by removing 0x prefix |
| 39 | + object.__setattr__(self, "checksum_sha256", self.checksum_sha256[2:]) |
| 40 | + if self.checksum_keccak256 and self.checksum_keccak256.startswith("0x"): |
| 41 | + # Normalize by removing 0x prefix |
| 42 | + object.__setattr__(self, "checksum_keccak256", self.checksum_keccak256[2:]) |
| 43 | + |
| 44 | + @property |
| 45 | + def is_zip_archive(self) -> bool: |
| 46 | + """Check if this artifact is a ZIP archive (older Windows versions).""" |
| 47 | + return self.platform.os_type == "windows" and self.version <= Version("0.7.1") |
| 48 | + |
| 49 | + def get_binary_name_in_zip(self) -> str: |
| 50 | + """Get the binary name inside ZIP archives.""" |
| 51 | + if not self.is_zip_archive: |
| 52 | + raise ValueError("Not a ZIP archive") |
| 53 | + return "solc.exe" |
0 commit comments