#!/usr/bin/env python3 """Increment the PATCH component of version.txt and update banner_char in top.v.""" import re import sys from pathlib import Path VERSION_FILE = Path("version.txt") TOP_V_FILE = Path("top.v") # Fixed 9-character field in banner_char; indices 343-351. VERSION_FIELD_LEN = 9 VERSION_START_IDX = 343 def read_version(): if not VERSION_FILE.exists(): sys.exit(f"Error: {VERSION_FILE} not found") return VERSION_FILE.read_text().strip() def bump_patch(version): parts = version.split(".") if len(parts) != 3 or not all(p.isdigit() for p in parts): sys.exit(f"Error: unexpected version format '{version}'") major, minor, patch = int(parts[0]), int(parts[1]), int(parts[2]) return f"{major}.{minor}.{patch + 1}" def update_top_v(new_version): if not TOP_V_FILE.exists(): sys.exit(f"Error: {TOP_V_FILE} not found") padded = new_version.ljust(VERSION_FIELD_LEN) if len(padded) > VERSION_FIELD_LEN: sys.exit(f"Error: version '{new_version}' exceeds {VERSION_FIELD_LEN} characters") content = TOP_V_FILE.read_text() for offset, ch in enumerate(padded): idx = VERSION_START_IDX + offset pattern = rf"(9'd{idx}:\s+banner_char\s*=\s*)[^\n]+;" replacement = rf'\g<1>"{ch}";' new_content = re.sub(pattern, replacement, content) if new_content == content: sys.exit(f"Error: could not find banner_char entry for index {idx} in {TOP_V_FILE}") content = new_content TOP_V_FILE.write_text(content) def main(): old_version = read_version() new_version = bump_patch(old_version) update_top_v(new_version) VERSION_FILE.write_text(new_version + "\n") print(f"Version bumped to {new_version}") if __name__ == "__main__": main()