mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-19 19:27:04 +00:00
Adds a script that queries bazel central registry and other sources to get the latest versions. Gemini generated something similar on the fly for checks, and I figured it's helpful to formalize. ``` - BCR: - abseil-cpp: 20260107.1 - bazel_skylib: 1.9.0 - google_benchmark: 1.9.5 - googletest: 1.17.0.bcr.2 - libpfm: 4.13.0 - platforms: 1.0.0 - protobuf: 34.0.bcr.1 - re2: 2025-11-05.bcr.1 - rules_bazel_integration_test: 0.37.1 - rules_cc: 0.2.17 - rules_pkg: 1.2.0 - rules_python: 1.9.0 - rules_shell: 0.6.1 - tcmalloc: 0.0.0-20250927-12f2552 - tree-sitter-bazel: 0.26.5 - zlib-ng: 2.0.7 - zstd: 1.5.7.bcr.1 - GitHub Tag: - libpfm: v4.13.0 - Git HEAD: - bazel_clang_tidy: c4d35e0d0b838309358e57a2efed831780f85cd0 - hedron_compile_commands: abb61a688167623088f8768cc9264798df6a9d10 ``` Assisted-by: Google Antigravity with Gemini
110 lines
3.3 KiB
Python
Executable File
110 lines
3.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
"""Queries latest module versions from MODULE.bazel."""
|
|
|
|
__copyright__ = """
|
|
Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
Exceptions. See /LICENSE for license information.
|
|
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
"""
|
|
|
|
import json
|
|
import re
|
|
import subprocess
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
|
|
def _query_bazel_deps(module_text: str) -> None:
|
|
"""Query BCR for `bazel_dep` rule versions."""
|
|
bazel_dep_re = re.compile(
|
|
r'bazel_dep\([^)]*name\s*=\s*"([^"]+)"[^)]*version\s*='
|
|
)
|
|
packages = sorted([m[1] for m in bazel_dep_re.finditer(module_text)])
|
|
print("- BCR:")
|
|
for pkg in packages:
|
|
try:
|
|
url = f"https://bcr.bazel.build/modules/{pkg}/metadata.json"
|
|
with urllib.request.urlopen(url) as response:
|
|
data = json.loads(response.read().decode())
|
|
versions = data.get("versions", [])
|
|
print(f" - {pkg}: {versions[-1] if versions else 'Unknown'}")
|
|
except Exception as e:
|
|
print(f" - {pkg}: Error {e}")
|
|
|
|
|
|
def _query_archive_overrides(module_text: str) -> None:
|
|
"""Query Git for `archive_override` rule versions."""
|
|
archive_re = re.compile(
|
|
r"archive_override\(\s*"
|
|
r'module_name\s*=\s*"([^"]+)".*?'
|
|
r'urls\s*=\s*\["[^"]*?github\.com/([^/]+/[^/]+?)/archive',
|
|
re.DOTALL,
|
|
)
|
|
github_tags = sorted(
|
|
[
|
|
(m[1], f"https://github.com/{m[2]}.git")
|
|
for m in archive_re.finditer(module_text)
|
|
]
|
|
)
|
|
|
|
print("- GitHub Tag:")
|
|
for pkg, url in github_tags:
|
|
try:
|
|
output = subprocess.check_output(
|
|
["git", "ls-remote", "--tags", url], text=True
|
|
)
|
|
# Find the latest tag by sorting them (excluding the ^{}
|
|
# dereferenced tags).
|
|
tags = [
|
|
line.split("/")[-1]
|
|
for line in output.splitlines()
|
|
if not line.endswith("^{}")
|
|
]
|
|
|
|
# Simple version sort (git-style) using split by common delimiters.
|
|
tags.sort(
|
|
key=lambda tag: [
|
|
int(x) if x.isdigit() else x
|
|
for x in re.split(r"(\d+)", tag)
|
|
]
|
|
)
|
|
latest_tag = tags[-1] if tags else "Unknown"
|
|
print(f" - {pkg}: {latest_tag}")
|
|
except Exception as e:
|
|
print(f" - {pkg}: Error {e}")
|
|
|
|
|
|
def _query_git_overrides(module_text: str) -> None:
|
|
"""Query GitHub for `git_override` rule versions."""
|
|
git_re = re.compile(
|
|
r"git_override\(\s*"
|
|
r'module_name\s*=\s*"([^"]+)".*?'
|
|
r'remote\s*=\s*"([^"]+)"',
|
|
re.DOTALL,
|
|
)
|
|
git_repos = sorted([(m[1], m[2]) for m in git_re.finditer(module_text)])
|
|
print("- Git HEAD:")
|
|
for pkg, url in git_repos:
|
|
try:
|
|
output = subprocess.check_output(
|
|
["git", "ls-remote", url, "HEAD"], text=True
|
|
)
|
|
commit = output.split()[0]
|
|
print(f" - {pkg}: {commit}")
|
|
except Exception as e:
|
|
print(f" - {pkg}: Error {e}")
|
|
|
|
|
|
def main() -> None:
|
|
with open("MODULE.bazel", "r") as f:
|
|
module_text = f.read()
|
|
|
|
_query_bazel_deps(module_text)
|
|
_query_archive_overrides(module_text)
|
|
_query_git_overrides(module_text)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|