Skip to content

Commit e22c614

Browse files
authored
feat: Scrape the whole MODULE file (#18)
Swap out looking at the versions of modules that opted into telemetry for the versions of all modules from BCR. Note that local/private modules and source overridden modules aren't captured. We do detect BCR mirrors/rehosting and identify rehosted packages. ### Changes are visible to end-users: yes - Searched for relevant documentation and updated as needed: yes - Breaking change (forces users to change their own code or config): no - Suggested release notes appear below: no ### Test plan - Manual testing; please provide instructions so we can reproduce: ``` ❯ cat bazel-bin/report.json { "tools_telemetry": { "arch": "aarch64", "bazel_version": "8.4.2", "bazelisk": true, "ci": false, "counter": null, "deps": { "bazel_features": "1.30.0", "bazel_lib": "3.0.0", "bazel_skylib": "1.8.1", "rules_android": "0.1.1", "rules_cc": "0.1.1", "rules_fuzzing": "0.5.2", "rules_java": "8.14.0", "rules_jvm_external": "6.3", "rules_kotlin": "1.9.6", "rules_license": "1.0.0", "rules_pkg": "1.0.1", "rules_proto": "7.0.2", "rules_python": "0.40.0", "rules_shell": "0.4.1" }, "has_bazel_module": true, "has_bazel_prelude": false, "has_bazel_tool": false, "has_bazel_workspace": true, "id": "11e79f7905b252a08bc51ed59f3a8360b0b72eab", "org": null, "os": "mac os x", "runner": null, "shell": "/bin/zsh", "user": "43d65459434f0929abcb0605c59cf65093670ce5" } }% ```
1 parent 616b1ab commit e22c614

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

MODULE.bazel.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/simple/MODULE.bazel.lock

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extension.bzl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,35 @@ tel_repository = repository_rule(
171171

172172

173173
def _tel_impl(module_ctx):
174+
lock_content = json.decode(module_ctx.read(module_ctx.path(Label("@@//:MODULE.bazel.lock"))))
175+
raw_deps = lock_content.get("registryFileHashes", {})
176+
registries = [
177+
it.replace("/bazel_registry.json", "/modules/") for it in raw_deps.keys()
178+
if it.endswith("/bazel_registry.json")
179+
]
180+
deps = {}
181+
for url, _sha in raw_deps.items():
182+
if not url.endswith("/source.json"):
183+
continue
184+
185+
# https://bcr.bazel.build/modules/jsoncpp/1.9.5/source.json
186+
187+
url = url.replace("/source.json", "")
188+
189+
# https://bcr.bazel.build/modules/jsoncpp/1.9.5
190+
191+
for registry in registries:
192+
url = url.replace(registry, "")
193+
194+
# jsoncpp/1.9.5
195+
196+
if "/" in url:
197+
pkg, rev = url.split("/", 1)
198+
deps[pkg] = rev
199+
174200
tel_repository(
175201
name = "aspect_tools_telemetry_report",
176-
deps = {it.name: it.version for it in module_ctx.modules}
202+
deps = deps
177203
)
178204

179205
# TODO: Should the extension in the main module be able to set telemetry feature

0 commit comments

Comments
 (0)