diff --git a/.bazelrc b/.bazelrc index 3b8604e4d9e..eb3efb676fe 100644 --- a/.bazelrc +++ b/.bazelrc @@ -14,7 +14,7 @@ build:linux --cxxopt=-std=c++20 build:macos --cxxopt=-std=c++20 --cpu=darwin_x86_64 build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor -common --registry=file://%workspace%/misc/bazel/override_registry +common --registry=file://%workspace%/misc/bazel/registry common --registry=https://bcr.bazel.build import %workspace%/.bazelrc.exported diff --git a/misc/bazel/override_registry/README.md b/misc/bazel/override_registry/README.md deleted file mode 100644 index 1728ff88946..00000000000 --- a/misc/bazel/override_registry/README.md +++ /dev/null @@ -1,8 +0,0 @@ -This was taken from https://github.com/bazelbuild/bazel-central-repository and readapted: -* The latest version was renamed with a `-patched` suffix -* The above rename was done also in the files: - * `modules/rules_kotlin/metadata.json` - * `module/rules_kotlin/1.9.4-patched/MODULE.bazel` -* `modules/rules_kotlin/1.9.4-patched/patches/add_language_version_option.patch` was added -* the above patch was added in `modules/rules_kotlin/1.9.4-patched/source.json`, with integrity SHAs generated via - `echo -n sha256-; cat | openssl dgst -sha256 -binary | base64`. diff --git a/misc/bazel/override_registry/modules/rules_kotlin/metadata.json b/misc/bazel/override_registry/modules/rules_kotlin/metadata.json deleted file mode 100644 index 14ddf135bec..00000000000 --- a/misc/bazel/override_registry/modules/rules_kotlin/metadata.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "homepage": "https://github.com/bazelbuild/rules_kotlin", - "maintainers": [], - "repository": [ - "github:bazelbuild/rules_kotlin" - ], - "versions": [ - "1.9.4-patched" - ], - "yanked_versions": {} -} diff --git a/misc/bazel/registry/README.md b/misc/bazel/registry/README.md new file mode 100644 index 00000000000..5d1723d0eac --- /dev/null +++ b/misc/bazel/registry/README.md @@ -0,0 +1,3 @@ +Versions to be patched can be taken from https://github.com/bazelbuild/bazel-central-repository. After adding patches +inside `//patches`, and eventually renaming ``, run [`fix.py`](./fix.py) to align all metadata +to the renamed version and added patches. diff --git a/misc/bazel/override_registry/bazel_registry.json b/misc/bazel/registry/bazel_registry.json similarity index 100% rename from misc/bazel/override_registry/bazel_registry.json rename to misc/bazel/registry/bazel_registry.json diff --git a/misc/bazel/registry/fix.py b/misc/bazel/registry/fix.py new file mode 100755 index 00000000000..c904ebf4951 --- /dev/null +++ b/misc/bazel/registry/fix.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +""" +Fix metadata in overridden registry, updating `metadata.json` to list correct versions and `source.json` +to list correct patches with sha256 hashes. +""" + +import pathlib +import json +import base64 +import hashlib +import re + +this_dir = pathlib.Path(__file__).resolve().parent + + +def sha256(file): + with open(file, 'rb') as input: + hash = hashlib.sha256(input.read()).digest() + hash = base64.b64encode(hash).decode() + return f"sha256-{hash}" + + +def patch_file(file, f): + try: + data = file.read_text() + except FileNotFoundError: + data = None + file.write_text(f(data)) + + +def patch_json(file, **kwargs): + def update(data): + data = json.loads(data) if data else {} + data.update(kwargs) + return json.dumps(data, indent=4) + "\n" + + patch_file(file, update) + + +for entry in this_dir.joinpath("modules").iterdir(): + if not entry.is_dir(): + continue + versions = [e for e in entry.iterdir() if e.is_dir()] + + patch_json(entry / "metadata.json", versions=[v.name for v in versions]) + + for version in versions: + patch_json(version / "source.json", patches={ + p.name: sha256(p) for p in version.joinpath("patches").iterdir() + }) + patch_file(version / "MODULE.bazel", + lambda s: re.sub(r'''version\s*=\s*['"].*['"]''', f'version = "{version.name}"', s, 1)) diff --git a/misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/MODULE.bazel b/misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/MODULE.bazel similarity index 100% rename from misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/MODULE.bazel rename to misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/MODULE.bazel diff --git a/misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/patches/add_language_version_option.patch b/misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/patches/codeql_add_language_version_option.patch similarity index 100% rename from misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/patches/add_language_version_option.patch rename to misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/patches/codeql_add_language_version_option.patch diff --git a/misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/patches/module_dot_bazel_version.patch b/misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/patches/module_dot_bazel_version.patch similarity index 89% rename from misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/patches/module_dot_bazel_version.patch rename to misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/patches/module_dot_bazel_version.patch index d5981f575cf..7a33385b170 100644 --- a/misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/patches/module_dot_bazel_version.patch +++ b/misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/patches/module_dot_bazel_version.patch @@ -5,7 +5,7 @@ module( name = "rules_kotlin", - version = "1.9.0", -+ version = "1.9.4", ++ version = "1.9.4-patched", repo_name = "rules_kotlin", ) diff --git a/misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/source.json b/misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/source.json similarity index 53% rename from misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/source.json rename to misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/source.json index bc0f0f2f4b0..8f652c667d1 100644 --- a/misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/source.json +++ b/misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/source.json @@ -2,8 +2,8 @@ "integrity": "sha256-dsD8wsI+33NjIK3tGs2d3guuQY5XMd8Skz2IbLqGt5U=", "url": "https://github.com/bazelbuild/rules_kotlin/releases/download/v1.9.4/rules_kotlin-v1.9.4.tar.gz", "patches": { - "module_dot_bazel_version.patch": "sha256-8Fu6NiXzckWm8oaVY/rPonGEqWG5ijV0r2GUf7ajKHM=", - "add_language_version_option.patch": "sha256-uF6LFpkqe9ye7+avviY1NE5ZhxJ3WMLenS+mbg4XFTM=" + "module_dot_bazel_version.patch": "sha256-0GnFHOv9wuuv3jFcHBSXrdo7JMFP7y66O5C4rccy5wg=", + "codeql_add_language_version_option.patch": "sha256-uF6LFpkqe9ye7+avviY1NE5ZhxJ3WMLenS+mbg4XFTM=" }, "patch_strip": 1 } diff --git a/misc/bazel/registry/modules/rules_kotlin/metadata.json b/misc/bazel/registry/modules/rules_kotlin/metadata.json new file mode 100644 index 00000000000..a271e042588 --- /dev/null +++ b/misc/bazel/registry/modules/rules_kotlin/metadata.json @@ -0,0 +1,5 @@ +{ + "versions": [ + "1.9.4-patched" + ] +}