Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a15681a

Browse files
committed
Bazel: ease update of local registry
1 parent 5bdd724 commit a15681a

11 files changed

Lines changed: 65 additions & 23 deletions

File tree

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ build:linux --cxxopt=-std=c++20
1414
build:macos --cxxopt=-std=c++20 --cpu=darwin_x86_64
1515
build:windows --cxxopt=/std:c++20 --cxxopt=/Zc:preprocessor
1616

17-
common --registry=file://%workspace%/misc/bazel/override_registry
17+
common --registry=file://%workspace%/misc/bazel/registry
1818
common --registry=https://bcr.bazel.build
1919

2020
import %workspace%/.bazelrc.exported

misc/bazel/override_registry/README.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

misc/bazel/override_registry/modules/rules_kotlin/metadata.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

misc/bazel/registry/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Versions to be patched can be taken from https://github.com/bazelbuild/bazel-central-repository. After adding patches
2+
inside `<repo>/<version>/patches`, and eventually renaming `<version>`, run [`fix.py`](./fix.py) to align all metadata
3+
to the renamed version and added patches.
File renamed without changes.

misc/bazel/registry/fix.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Fix metadata in overridden registry, updating `metadata.json` to list correct versions and `source.json`
5+
to list correct patches with sha256 hashes.
6+
"""
7+
8+
import pathlib
9+
import json
10+
import base64
11+
import hashlib
12+
import re
13+
14+
this_dir = pathlib.Path(__file__).resolve().parent
15+
16+
17+
def sha256(file):
18+
with open(file, 'rb') as input:
19+
hash = hashlib.sha256(input.read()).digest()
20+
hash = base64.b64encode(hash).decode()
21+
return f"sha256-{hash}"
22+
23+
24+
def patch_file(file, f):
25+
try:
26+
data = file.read_text()
27+
except FileNotFoundError:
28+
data = None
29+
file.write_text(f(data))
30+
31+
32+
def patch_json(file, **kwargs):
33+
def update(data):
34+
data = json.loads(data) if data else {}
35+
data.update(kwargs)
36+
return json.dumps(data, indent=4) + "\n"
37+
38+
patch_file(file, update)
39+
40+
41+
for entry in this_dir.joinpath("modules").iterdir():
42+
if not entry.is_dir():
43+
continue
44+
versions = [e for e in entry.iterdir() if e.is_dir()]
45+
46+
patch_json(entry / "metadata.json", versions=[v.name for v in versions])
47+
48+
for version in versions:
49+
patch_json(version / "source.json", patches={
50+
p.name: sha256(p) for p in version.joinpath("patches").iterdir()
51+
})
52+
patch_file(version / "MODULE.bazel",
53+
lambda s: re.sub(r'''version\s*=\s*['"].*['"]''', f'version = "{version.name}"', s, 1))

misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/MODULE.bazel renamed to misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/MODULE.bazel

File renamed without changes.

misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/patches/add_language_version_option.patch renamed to misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/patches/codeql_add_language_version_option.patch

File renamed without changes.

misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/patches/module_dot_bazel_version.patch renamed to misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/patches/module_dot_bazel_version.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
module(
66
name = "rules_kotlin",
77
- version = "1.9.0",
8-
+ version = "1.9.4",
8+
+ version = "1.9.4-patched",
99
repo_name = "rules_kotlin",
1010
)
1111

misc/bazel/override_registry/modules/rules_kotlin/1.9.4-patched/source.json renamed to misc/bazel/registry/modules/rules_kotlin/1.9.4-patched/source.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"integrity": "sha256-dsD8wsI+33NjIK3tGs2d3guuQY5XMd8Skz2IbLqGt5U=",
33
"url": "https://github.com/bazelbuild/rules_kotlin/releases/download/v1.9.4/rules_kotlin-v1.9.4.tar.gz",
44
"patches": {
5-
"module_dot_bazel_version.patch": "sha256-8Fu6NiXzckWm8oaVY/rPonGEqWG5ijV0r2GUf7ajKHM=",
6-
"add_language_version_option.patch": "sha256-uF6LFpkqe9ye7+avviY1NE5ZhxJ3WMLenS+mbg4XFTM="
5+
"module_dot_bazel_version.patch": "sha256-0GnFHOv9wuuv3jFcHBSXrdo7JMFP7y66O5C4rccy5wg=",
6+
"codeql_add_language_version_option.patch": "sha256-uF6LFpkqe9ye7+avviY1NE5ZhxJ3WMLenS+mbg4XFTM="
77
},
88
"patch_strip": 1
99
}

0 commit comments

Comments
 (0)