Skip to content

Commit ddc9cd6

Browse files
authored
Setup bazel workspace for registry tools (bazelbuild#416)
* Setup bazel workspace for registry tools * Add calls to chdir
1 parent b6ded3e commit ddc9cd6

16 files changed

+183
-3
lines changed

.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
common --enable_bzlmod

.bazelversion

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.0.0

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
tools/__pycache__
2+
/bazel-*

MODULE.bazel

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module(
2+
name = "bazel_central_registry",
3+
compatibility_level = 1,
4+
version = "0.0.0",
5+
)
6+
7+
bazel_dep(name = "rules_python", version = "0.17.3")
8+
9+
python = use_extension("@rules_python//python:extensions.bzl", "python")
10+
11+
python.toolchain(
12+
name = "python3",
13+
python_version = "3.11",
14+
)
15+
16+
use_repo(python, "python3_toolchains")
17+
18+
register_toolchains(
19+
"@python3_toolchains//:all",
20+
)
21+
22+
pip = use_extension("@rules_python//python:extensions.bzl", "pip")
23+
24+
pip.parse(
25+
name = "tools_deps",
26+
requirements_lock = "//tools:requirements_lock.txt",
27+
)
28+
29+
use_repo(pip, "tools_deps")

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ If you consider it necessary, you can do the following to avoid depending on the
1717

1818
- Clone the BCR repository or mirror the content to your own infrastructure and use the [--registry](https://bazel.build/reference/command-line-reference#flag--registry) option to change the default Bazel registry to your own.
1919
- Host your own mirror for all source archive URLs and add the mirror URL in `./bazel_registry.json`.
20-
You can run the `./tools/print_all_src_urls.py` script to get the list of source URLs to mirror for all Bazel modules checked into the BCR.
20+
You can run `bazel run //tools:print_all_src_urls` to get the list of source URLs to mirror for all Bazel modules checked into the BCR.
2121
For example, `https://foo.com/bar.zip` should be mirrored to `https://<your mirror>/foo.com/bar.zip`.

WORKSPACE

Whitespace-only changes.

tools/BUILD

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
load("@rules_python//python:defs.bzl", "py_binary", "py_library")
2+
load("@rules_python//python:pip.bzl", "compile_pip_requirements")
3+
load("@tools_deps//:requirements.bzl", "requirement")
4+
5+
compile_pip_requirements(
6+
name = "requirements",
7+
requirements_in = "requirements.in",
8+
requirements_txt = "requirements_lock.txt",
9+
)
10+
11+
py_binary(
12+
name = "add_module",
13+
srcs = ["add_module.py"],
14+
deps = [
15+
":bcr_validation",
16+
":registry",
17+
],
18+
)
19+
20+
py_binary(
21+
name = "calc_integrity",
22+
srcs = ["calc_integrity.py"],
23+
deps = [
24+
":registry",
25+
requirement("validators"),
26+
],
27+
)
28+
29+
py_binary(
30+
name = "migrate_to_bzlmod",
31+
srcs = ["migrate_to_bzlmod.py"],
32+
deps = [
33+
":registry",
34+
],
35+
)
36+
37+
py_binary(
38+
name = "print_all_src_urls",
39+
srcs = ["print_all_src_urls.py"],
40+
deps = [
41+
":registry",
42+
],
43+
)
44+
45+
py_library(
46+
name = "bcr_validation",
47+
srcs = ["bcr_validation.py"],
48+
deps = [
49+
":registry",
50+
":verify_stable_archives",
51+
],
52+
)
53+
54+
py_library(
55+
name = "verify_stable_archives",
56+
srcs = ["verify_stable_archives.py"],
57+
)
58+
59+
py_library(
60+
name = "registry",
61+
srcs = ["registry.py"],
62+
imports = ["."],
63+
deps = [
64+
requirement("pyyaml"),
65+
],
66+
)
67+
68+
py_test(
69+
name = "version_test",
70+
srcs = [
71+
"version_test.py",
72+
],
73+
deps = [
74+
"registry",
75+
],
76+
)

tools/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
An interactive script for adding a module to the BCR.
66
```
7-
$ ./tools/add_module.py
7+
$ bazel run //tools:add_module
88
INFO: Getting module information from user input...
99
ACTION: Please enter the module name:
1010
...
@@ -41,7 +41,7 @@ optional arguments:
4141

4242
Print the list of source archive URLs of all modules in the BCR.
4343
```
44-
$ ./tools/print_all_src_urls.py
44+
$ bazel run //tools:print_all_src_urls
4545
https://github.com/bazelbuild/rules_jvm_external/archive/refs/tags/4.4.2.zip
4646
https://github.com/bazelbuild/rules_jvm_external/archive/refs/tags/4.5.zip
4747
...

tools/add_module.py

100755100644
+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"""
3838

3939
import argparse
40+
import os
4041
import sys
4142
import time
4243

@@ -213,4 +214,7 @@ def main(argv=None):
213214

214215

215216
if __name__ == "__main__":
217+
# Under 'bazel run' we want to run within the source folder instead of the execroot.
218+
if os.getenv("BUILD_WORKSPACE_DIRECTORY"):
219+
os.chdir(os.getenv("BUILD_WORKSPACE_DIRECTORY"))
216220
sys.exit(main())

tools/bcr_validation.py

100755100644
+3
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,7 @@ def main(argv=None):
334334
return validator.getValidationReturnCode()
335335

336336
if __name__ == "__main__":
337+
# Under 'bazel run' we want to run within the source folder instead of the execroot.
338+
if os.getenv("BUILD_WORKSPACE_DIRECTORY"):
339+
os.chdir(os.getenv("BUILD_WORKSPACE_DIRECTORY"))
337340
sys.exit(main())

tools/calc_integrity.py

100755100644
+4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
# limitations under the License.
1616

1717
import validators
18+
import os
1819
import sys
1920

2021
from registry import read
2122
from registry import download
2223
from registry import integrity
2324

2425
if __name__ == "__main__":
26+
# Under 'bazel run' we want to run within the source folder instead of the execroot.
27+
if os.getenv("BUILD_WORKSPACE_DIRECTORY"):
28+
os.chdir(os.getenv("BUILD_WORKSPACE_DIRECTORY"))
2529
if validators.url(sys.argv[1]):
2630
print(integrity(download(sys.argv[1])))
2731
else:

tools/print_all_src_urls.py

100755100644
+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# pylint: disable=line-too-long
1818
# pylint: disable=missing-function-docstring
1919

20+
import os
2021
import sys
2122

2223
from registry import RegistryClient
@@ -27,4 +28,7 @@ def main():
2728
print(client.get_source(name, version)["url"])
2829

2930
if __name__ == "__main__":
31+
# Under 'bazel run' we want to run within the source folder instead of the execroot.
32+
if os.getenv("BUILD_WORKSPACE_DIRECTORY"):
33+
os.chdir(os.getenv("BUILD_WORKSPACE_DIRECTORY"))
3034
sys.exit(main())

tools/registry.py

100755100644
File mode changed.

tools/requirements.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyyaml
2+
validators

tools/requirements_lock.txt

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# This file is autogenerated by pip-compile with Python 3.11
3+
# by the following command:
4+
#
5+
# bazel run //tools:requirements.update
6+
#
7+
decorator==5.1.1 \
8+
--hash=sha256:637996211036b6385ef91435e4fae22989472f9d571faba8927ba8253acbc330 \
9+
--hash=sha256:b8c3f85900b9dc423225913c5aace94729fe1fa9763b38939a95226f02d37186
10+
# via validators
11+
pyyaml==6.0 \
12+
--hash=sha256:01b45c0191e6d66c470b6cf1b9531a771a83c1c4208272ead47a3ae4f2f603bf \
13+
--hash=sha256:0283c35a6a9fbf047493e3a0ce8d79ef5030852c51e9d911a27badfde0605293 \
14+
--hash=sha256:055d937d65826939cb044fc8c9b08889e8c743fdc6a32b33e2390f66013e449b \
15+
--hash=sha256:07751360502caac1c067a8132d150cf3d61339af5691fe9e87803040dbc5db57 \
16+
--hash=sha256:0b4624f379dab24d3725ffde76559cff63d9ec94e1736b556dacdfebe5ab6d4b \
17+
--hash=sha256:0ce82d761c532fe4ec3f87fc45688bdd3a4c1dc5e0b4a19814b9009a29baefd4 \
18+
--hash=sha256:1e4747bc279b4f613a09eb64bba2ba602d8a6664c6ce6396a4d0cd413a50ce07 \
19+
--hash=sha256:213c60cd50106436cc818accf5baa1aba61c0189ff610f64f4a3e8c6726218ba \
20+
--hash=sha256:231710d57adfd809ef5d34183b8ed1eeae3f76459c18fb4a0b373ad56bedcdd9 \
21+
--hash=sha256:277a0ef2981ca40581a47093e9e2d13b3f1fbbeffae064c1d21bfceba2030287 \
22+
--hash=sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513 \
23+
--hash=sha256:40527857252b61eacd1d9af500c3337ba8deb8fc298940291486c465c8b46ec0 \
24+
--hash=sha256:432557aa2c09802be39460360ddffd48156e30721f5e8d917f01d31694216782 \
25+
--hash=sha256:473f9edb243cb1935ab5a084eb238d842fb8f404ed2193a915d1784b5a6b5fc0 \
26+
--hash=sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92 \
27+
--hash=sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f \
28+
--hash=sha256:68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2 \
29+
--hash=sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc \
30+
--hash=sha256:81957921f441d50af23654aa6c5e5eaf9b06aba7f0a19c18a538dc7ef291c5a1 \
31+
--hash=sha256:819b3830a1543db06c4d4b865e70ded25be52a2e0631ccd2f6a47a2822f2fd7c \
32+
--hash=sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86 \
33+
--hash=sha256:98c4d36e99714e55cfbaaee6dd5badbc9a1ec339ebfc3b1f52e293aee6bb71a4 \
34+
--hash=sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c \
35+
--hash=sha256:9fa600030013c4de8165339db93d182b9431076eb98eb40ee068700c9c813e34 \
36+
--hash=sha256:a80a78046a72361de73f8f395f1f1e49f956c6be882eed58505a15f3e430962b \
37+
--hash=sha256:afa17f5bc4d1b10afd4466fd3a44dc0e245382deca5b3c353d8b757f9e3ecb8d \
38+
--hash=sha256:b3d267842bf12586ba6c734f89d1f5b871df0273157918b0ccefa29deb05c21c \
39+
--hash=sha256:b5b9eccad747aabaaffbc6064800670f0c297e52c12754eb1d976c57e4f74dcb \
40+
--hash=sha256:bfaef573a63ba8923503d27530362590ff4f576c626d86a9fed95822a8255fd7 \
41+
--hash=sha256:c5687b8d43cf58545ade1fe3e055f70eac7a5a1a0bf42824308d868289a95737 \
42+
--hash=sha256:cba8c411ef271aa037d7357a2bc8f9ee8b58b9965831d9e51baf703280dc73d3 \
43+
--hash=sha256:d15a181d1ecd0d4270dc32edb46f7cb7733c7c508857278d3d378d14d606db2d \
44+
--hash=sha256:d4b0ba9512519522b118090257be113b9468d804b19d63c71dbcf4a48fa32358 \
45+
--hash=sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53 \
46+
--hash=sha256:d4eccecf9adf6fbcc6861a38015c2a64f38b9d94838ac1810a9023a0609e1b78 \
47+
--hash=sha256:d67d839ede4ed1b28a4e8909735fc992a923cdb84e618544973d7dfc71540803 \
48+
--hash=sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a \
49+
--hash=sha256:dbad0e9d368bb989f4515da330b88a057617d16b6a8245084f1b05400f24609f \
50+
--hash=sha256:e61ceaab6f49fb8bdfaa0f92c4b57bcfbea54c09277b1b4f7ac376bfb7a7c174 \
51+
--hash=sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5
52+
# via -r tools/requirements.in
53+
validators==0.20.0 \
54+
--hash=sha256:24148ce4e64100a2d5e267233e23e7afeb55316b47d30faae7eb6e7292bc226a
55+
# via -r tools/requirements.in

tools/version_test.py

100755100644
File mode changed.

0 commit comments

Comments
 (0)