mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Bazel: ease update of local registry
This commit is contained in:
2
.bazelrc
2
.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
|
||||
|
||||
@@ -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 <file> | openssl dgst -sha256 -binary | base64`.
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"homepage": "https://github.com/bazelbuild/rules_kotlin",
|
||||
"maintainers": [],
|
||||
"repository": [
|
||||
"github:bazelbuild/rules_kotlin"
|
||||
],
|
||||
"versions": [
|
||||
"1.9.4-patched"
|
||||
],
|
||||
"yanked_versions": {}
|
||||
}
|
||||
3
misc/bazel/registry/README.md
Normal file
3
misc/bazel/registry/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Versions to be patched can be taken from https://github.com/bazelbuild/bazel-central-repository. After adding patches
|
||||
inside `<repo>/<version>/patches`, and eventually renaming `<version>`, run [`fix.py`](./fix.py) to align all metadata
|
||||
to the renamed version and added patches.
|
||||
53
misc/bazel/registry/fix.py
Executable file
53
misc/bazel/registry/fix.py
Executable file
@@ -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))
|
||||
@@ -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",
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
5
misc/bazel/registry/modules/rules_kotlin/metadata.json
Normal file
5
misc/bazel/registry/modules/rules_kotlin/metadata.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"versions": [
|
||||
"1.9.4-patched"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user