scripts/bump-subproject-wraps.py: Handle updates from wrapdb

This commit is contained in:
Matt Borgerson
2026-01-31 12:24:54 -07:00
committed by mborgerson
parent 6d47853eaa
commit 98b0051138
+106 -1
View File
@@ -12,7 +12,9 @@ import json
import logging
import os
import re
import subprocess
import sys
import urllib.parse
from pathlib import Path
from dataclasses import dataclass, asdict
@@ -107,6 +109,106 @@ class UpdatedWrap:
new_tag: str
def update_wrapdb_wrap(path: Path) -> None | UpdatedWrap:
"""
Update a wrapdb wrap file using `meson wrap update`.
"""
wrap_name = path.stem
# Read current version
cp_before = configparser.ConfigParser(interpolation=None)
cp_before.read(path, encoding="utf-8")
if "wrap-file" not in cp_before:
return None
# Extract version info before update
w_before = cp_before["wrap-file"]
source_url_before = w_before.get("source_url", "")
source_hash_before = w_before.get("source_hash", "")
patch_hash_before = w_before.get("patch_hash", "")
wrapdb_version_before = w_before.get("wrapdb_version", "")
# Try to extract version from wrapdb_version or filename in source_url
old_version = wrapdb_version_before
if not old_version and source_url_before:
# Common pattern: package-version.tar.gz or package_version.tar.gz
filename = urllib.parse.urlparse(source_url_before).path.split("/")[-1]
# Try to extract version (this is a heuristic)
version_match = re.search(r"[-_]v?(\d+(?:\.\d+)*(?:[.-]\w+)?)", filename)
if version_match:
old_version = version_match.group(1)
# Call meson wrap update
try:
result = subprocess.run(
["meson", "wrap", "update", wrap_name],
cwd=ROOT,
capture_output=True,
text=True,
check=False,
)
if result.returncode != 0:
log.info("meson wrap update failed for %s: %s", wrap_name, result.stderr)
return None
except FileNotFoundError:
log.error("meson command not found. Cannot update wrapdb wraps.")
return None
except Exception as e:
log.exception(e)
return None
# Read updated version
cp_after = configparser.ConfigParser(interpolation=None)
cp_after.read(path, encoding="utf-8")
if "wrap-file" not in cp_after:
return None
w_after = cp_after["wrap-file"]
source_url_after = w_after.get("source_url", "")
source_hash_after = w_after.get("source_hash", "")
patch_hash_after = w_after.get("patch_hash", "")
wrapdb_version_after = w_after.get("wrapdb_version", "")
# Check if anything changed (compare multiple fields)
if (source_url_before == source_url_after and
source_hash_before == source_hash_after and
patch_hash_before == patch_hash_after and
wrapdb_version_before == wrapdb_version_after):
log.info("%s already up to date", path.name)
return None
# Try to extract new version from wrapdb_version or filename
new_version = wrapdb_version_after
if not new_version and source_url_after:
filename = urllib.parse.urlparse(source_url_after).path.split("/")[-1]
version_match = re.search(r"[-_]v?(\d+(?:\.\d+)*(?:[.-]\w+)?)", filename)
if version_match:
new_version = version_match.group(1)
# Try to extract GitHub info if the source is on GitHub
owner, repo = "wrapdb", wrap_name
old_rev = old_version or "old"
new_rev = new_version or "new"
new_tag = new_version or "latest"
# Check if source_url points to GitHub
gh_match = re.match(
r".*github\.com[:/](?P<owner>[^/]+)/(?P<repo>[^/]+)/",
source_url_after
)
if gh_match:
owner = gh_match.group("owner")
repo = gh_match.group("repo")
log.info("%s updated from %s to %s", path.name, old_version or "?", new_version or "?")
return UpdatedWrap(str(path), owner, repo, old_rev, new_rev, new_tag)
def update_wrap(path: Path) -> None | UpdatedWrap:
"""
Return (tag_name, commit_sha) if updated, otherwise None.
@@ -114,8 +216,11 @@ def update_wrap(path: Path) -> None | UpdatedWrap:
cp = configparser.ConfigParser(interpolation=None)
cp.read(path, encoding="utf-8")
if "wrap-file" in cp:
# Handle wrapdb wraps using meson wrap update
return update_wrapdb_wrap(path)
if "wrap-git" not in cp:
# FIXME: Support wrap-file from wrapdb
return None
w = cp["wrap-git"]