Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bzlmod_extensions/apksig.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
)
8 changes: 7 additions & 1 deletion bzlmod_extensions/com_android_dex.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
)
13 changes: 11 additions & 2 deletions rules/android_sdk_repository/rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,17 @@ 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:
android_sdk_path = repo_ctx.getenv("ANDROID_HOME")
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")

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {
Expand Down