v0.1.5: fix bump_version.py BOM/encoding/CRLF, fix double banner on power-up

This commit is contained in:
David Rice
2026-06-10 13:12:57 +02:00
parent 134d1e7b7f
commit 648470fe35
3 changed files with 120 additions and 84 deletions

View File

@@ -1,61 +1,43 @@
#!/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 not VERSION_FILE.exists():
sys.exit("Error: version.txt not found")
if not TOP_V_FILE.exists():
sys.exit("Error: top.v not found")
old_version = VERSION_FILE.read_text(encoding='utf-8').strip()
parts = old_version.split(".")
if len(parts) != 3 or not all(p.isdigit() for p in parts):
sys.exit(f"Error: unexpected version format '{old_version}'")
new_version = f"{parts[0]}.{parts[1]}.{int(parts[2])+1}"
padded = new_version.ljust(VERSION_FIELD_LEN)
content = TOP_V_FILE.read_text(encoding='utf-8-sig', newline='\n')
m = re.search(r'version chars at indices (\d+)', content)
if not m:
sys.exit("Error: could not find 'version chars at indices' comment in top.v")
start_idx = int(m.group(1))
for offset, ch in enumerate(padded):
idx = start_idx + offset
pattern = rf"(9'd{idx}:\s+banner_char\s*=\s*)[^\n]+;"
new_content, n = re.subn(pattern, lambda mo, c=ch: mo.group(1) + f'"{c}";', content)
if n == 0:
sys.exit(f"Error: could not find banner_char entry for index {idx}")
content = new_content
TOP_V_FILE.write_text(content, encoding='utf-8', newline='\n')
VERSION_FILE.write_text(new_version + "\n", encoding='utf-8')
print(f"Version bumped to {new_version}")
if __name__ == "__main__":
main()