From a514acb3f06a11cb8183f249ff516249227f54ae Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Thu, 9 Jul 2026 10:53:41 -0700 Subject: [PATCH] Return repo/extension metadata from rules This allows the remote repo contents cache to cache the result of this repo --- bzlmod_extensions/apksig.bzl | 8 +++++++- bzlmod_extensions/com_android_dex.bzl | 8 +++++++- rules/android_sdk_repository/rule.bzl | 13 +++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/bzlmod_extensions/apksig.bzl b/bzlmod_extensions/apksig.bzl index 39babbdd9..c73f0ec4f 100644 --- a/bzlmod_extensions/apksig.bzl +++ b/bzlmod_extensions/apksig.bzl @@ -20,7 +20,7 @@ visibility(PROJECT_VISIBILITY) APKSIG_COMMIT = "24e3075e68ebe17c0b529bb24bfda819db5e2f3b" -def apksig(_ctx = None): +def apksig(mctx = None): # NOTE(b/317109605): Cannot depend on a stable sha256 hash for googlesource repositories. http_archive( name = "apksig", @@ -33,6 +33,12 @@ def apksig(_ctx = None): build_file = Label("//bzlmod_extensions:apksig.BUILD"), ) + # NOTE: 'watch' is the best approximation for the extension_metadata + # function accepting the reproducible paramater + if mctx and hasattr(mctx, "watch"): + return mctx.extension_metadata(reproducible = True) + return None + apksig_extension = module_extension( implementation = apksig, ) diff --git a/bzlmod_extensions/com_android_dex.bzl b/bzlmod_extensions/com_android_dex.bzl index 0c052dba6..8ddb0af73 100644 --- a/bzlmod_extensions/com_android_dex.bzl +++ b/bzlmod_extensions/com_android_dex.bzl @@ -18,7 +18,7 @@ load("//rules:visibility.bzl", "PROJECT_VISIBILITY") visibility(PROJECT_VISIBILITY) -def com_android_dex(_ctx = None): +def com_android_dex(mctx = None): # NOTE(b/317109605): Cannot depend on a stable sha256 hash for googlesource repositories. http_archive( name = "com_android_dex", @@ -31,6 +31,12 @@ def com_android_dex(_ctx = None): sha256 = "86b4848c038bf687fadc812239cb01fb8d1d15cef3125b480a0448360992b95d", ) + # NOTE: 'watch' is the best approximation for the extension_metadata + # function accepting the reproducible paramater + if mctx and hasattr(mctx, "watch"): + return mctx.extension_metadata(reproducible = True) + return None + com_android_dex_extension = module_extension( implementation = com_android_dex, ) diff --git a/rules/android_sdk_repository/rule.bzl b/rules/android_sdk_repository/rule.bzl index 34de2b53e..04999c943 100644 --- a/rules/android_sdk_repository/rule.bzl +++ b/rules/android_sdk_repository/rule.bzl @@ -107,6 +107,9 @@ def _find_system_images(repo_ctx, android_sdk_path): return system_images def _android_sdk_repository_impl(repo_ctx): + repo_metadata = None + if hasattr(repo_ctx, "repo_metadata"): + repo_metadata = repo_ctx.repo_metadata(reproducible = True) # Determine the SDK path to use, either from the attribute or the environment. android_sdk_path = repo_ctx.attr.path if not android_sdk_path: @@ -114,7 +117,7 @@ def _android_sdk_repository_impl(repo_ctx): if not android_sdk_path: # Create an empty repository that allows non-Android code to build. repo_ctx.template("BUILD.bazel", _EMPTY_SDK_REPO_TEMPLATE) - return None + return repo_metadata if android_sdk_path.startswith("$WORKSPACE_ROOT"): android_sdk_path = str(repo_ctx.workspace_root) + android_sdk_path.removeprefix("$WORKSPACE_ROOT") @@ -184,7 +187,7 @@ def _android_sdk_repository_impl(repo_ctx): ) # repo is reproducible - return None + return repo_metadata _android_sdk_repository = repository_rule( implementation = _android_sdk_repository_impl, @@ -245,6 +248,12 @@ def _android_sdk_repository_extension_impl(module_ctx): **kwargs ) + # NOTE: 'watch' is the best approximation for the extension_metadata + # function accepting the reproducible paramater + if hasattr(module_ctx, "watch"): + return module_ctx.extension_metadata(reproducible = True) + return None + android_sdk_repository_extension = module_extension( implementation = _android_sdk_repository_extension_impl, tag_classes = {