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
1 change: 1 addition & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,4 @@ tasks:
build_targets:
- "//java/com/basicapp:basic_app"

buildifier: latest
5 changes: 5 additions & 0 deletions .buildifier.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"buildifier_disable": [
"sortLoadStatements"
]
}
4 changes: 3 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
workspace(name = "rules_android")

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

load("prereqs.bzl", "rules_android_prereqs")

rules_android_prereqs(dev_mode = True)

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")

compatibility_proxy_repo()

load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")

rules_java_dependencies()

# note that the following line is what is minimally required from protobuf for the java rules
Expand Down
1 change: 0 additions & 1 deletion android/rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ load(
"//rules/android_local_test:rule.bzl",
_android_local_test = "android_local_test",
)

load(
"//rules/android_sdk_repository:rule.bzl",
_android_sdk_repository = "android_sdk_repository",
Expand Down
2 changes: 1 addition & 1 deletion bzlmod_extensions/apksig.BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Defines targets for the apksigner build tool.
load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_test")
load("@rules_java//java:defs.bzl", "java_binary")

java_binary(
name = "apksigner",
Expand Down
2 changes: 1 addition & 1 deletion bzlmod_extensions/com_android_dex.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ java_library(
name = "dex",
srcs = glob(["dx/src/com/android/dex/**"]),
visibility = ["//visibility:public"],
)
)
14 changes: 8 additions & 6 deletions defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ def rules_android_workspace():
# put anything into @maven for WORKSPACE mode.
maven_install(
name = "maven",
artifacts = PROTOBUF_MAVEN_ARTIFACTS, # protobuf maven deps
repositories = [ # protobuf maven deps
"https://repo1.maven.org/maven2", # protobuf maven deps
"https://maven.google.com", # protobuf maven deps
], # protobuf maven deps
artifacts = PROTOBUF_MAVEN_ARTIFACTS, # protobuf maven deps
repositories = [
# protobuf maven deps
"https://repo1.maven.org/maven2", # protobuf maven deps
"https://maven.google.com", # protobuf maven deps
], # protobuf maven deps
)

bazel_skylib_workspace()
Expand Down Expand Up @@ -153,7 +154,8 @@ def rules_android_workspace():
# All lines in the artifacts list must be tagged "bazel worker api" for
# the presubmit maven artifact consistency checker to pass.
name = "bazel_worker_maven",
artifacts = [ # bazel worker api
artifacts = [
# bazel worker api
"com.google.code.gson:gson:2.10.1", # bazel worker api
"com.google.errorprone:error_prone_annotations:2.23.0", # bazel worker api
"com.google.guava:guava:33.0.0-jre", # bazel worker api
Expand Down
2 changes: 1 addition & 1 deletion examples/basicapp/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# Empty build file to satisfy gazelle for rules_go.
# Empty build file to satisfy gazelle for rules_go.
5 changes: 2 additions & 3 deletions examples/basicapp/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ module(
bazel_dep(name = "rules_java", version = "9.0.3")
bazel_dep(name = "bazel_skylib", version = "1.8.1")
bazel_dep(name = "rules_jvm_external", version = "6.7")

bazel_dep(
name = "rules_android",
version = "0.7.3",
)


# Local override to enable this app to be used for rules_android presubmit
# integration testing. If you're basing your app's MODULE file on this
# example, you do *not* need the following override.
Expand All @@ -22,7 +20,8 @@ local_path_override(

remote_android_extensions = use_extension(
"@rules_android//bzlmod_extensions:android_extensions.bzl",
"remote_android_tools_extensions")
"remote_android_tools_extensions",
)
use_repo(remote_android_extensions, "android_tools")

android_sdk_repository_extension = use_extension("@rules_android//rules/android_sdk_repository:rule.bzl", "android_sdk_repository_extension")
Expand Down
14 changes: 13 additions & 1 deletion examples/basicapp/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
local_repository(
name = "rules_android",
path = "../..", # rules_android's WORKSPACE relative to this inner workspace
path = "../..", # rules_android's WORKSPACE relative to this inner workspace
)

# --SNIP--: Everything below this line goes into the example WORKSPACE snippet in the release notes.

# Android rules dependencies
load("@rules_android//:prereqs.bzl", "rules_android_prereqs")

rules_android_prereqs()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")

compatibility_proxy_repo()

##### rules_java setup for rules_android #####
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")

rules_java_dependencies()

# note that the following line is what is minimally required from protobuf for the java rules
# consider using the protobuf_deps() public API from @com_google_protobuf//:protobuf_deps.bzl
load("@com_google_protobuf//bazel/private:proto_bazel_features.bzl", "proto_bazel_features") # buildifier: disable=bzl-visibility

proto_bazel_features(name = "proto_bazel_features")

# register toolchains
load("@rules_java//java:repositories.bzl", "rules_java_toolchains")

rules_java_toolchains()

##### rules_jvm_external setup for rules_android #####
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

##### rules_android setup #####
load("@rules_android//:defs.bzl", "rules_android_workspace")

rules_android_workspace()

# Android SDK setup
load("@rules_android//rules:rules.bzl", "android_sdk_repository")

android_sdk_repository(
name = "androidsdk",
)
Expand Down
6 changes: 3 additions & 3 deletions examples/basicapp/java/com/basicapp/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
load(
"@rules_android//android:rules.bzl",
"android_binary",
"android_library",
"android_application",
"android_application",
"android_binary",
"android_library",
)

android_binary(
Expand Down
4 changes: 2 additions & 2 deletions mobile_install/adapters/java_lite_proto_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def _aspect_attrs():
"""Attrs of the rule requiring traversal by the aspect."""
return ["deps", "_aspect_proto_toolchain_for_javalite", "_proto_toolchain_for_javalite"]

def _adapt(target, ctx):
def _adapt(_target, ctx):
"""Adapts the rule and target data.
Args:
target: The target.
_target: The target.
ctx: The context.
Returns:
Expand Down
21 changes: 20 additions & 1 deletion mobile_install/apks.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,26 @@ def make_split_apks(
key_rotation_min_sdk,
zipalign_alignment,
sibling):
"""Create a split for each dex and for resources"""
"""Create a split for each dex and for resources.
Args:
ctx: The context.
manifest: The merged AndroidManifest.xml.
r_dex: The generated R dex artifact.
dexes: A list of dex artifacts to package as splits.
resource_apk: The resource APK.
jar_resources: Java resource jars to package.
native_zips: Native library zips to package.
swigdeps_file: A generated SWIG deps file.
debug_signing_keys: Debug keystores used to sign APKs.
debug_signing_lineage_file: File containing the signing lineage.
key_rotation_min_sdk: Minimum API level to rotate signing keys for.
zipalign_alignment: Zip alignment used before signing.
sibling: The file used to root generated outputs.
Returns:
A tuple of the manifest package-name file and the generated split APKs.
"""
manifest_package_name = utils.isolated_declare_file(ctx, "manifest_package_name.txt", sibling = sibling)
manifests = {}
artifacts = {}
Expand Down
2 changes: 1 addition & 1 deletion mobile_install/constants.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ constants = struct(
EMPTY_LIST = [],
EMPTY_DICT = dict(),

# Skylark Types
# Starlark Types
TYPE_DEPSET = type(depset()),
TYPE_DICT = type(dict()),
TYPE_LIST = type([]),
Expand Down
2 changes: 2 additions & 0 deletions mobile_install/mi.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def make_aspect(
dex_shards: Number of dex shards to split the project across.
is_cmd: A Boolean, when True the aspect is running in the context of the
mobile-install command. If False it is as a rule (e.g. mi_test).
is_test: Whether the aspect is running for a test rule.
res_shards: Number of Android resource shards during processing.
tools: Tool attributes to attach to the aspect.
Returns:
A configured aspect.
"""
Expand Down
1 change: 1 addition & 0 deletions mobile_install/process.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def process(
debug_signing_keys: Debug keystores to be used to sign the apk.
debug_signing_lineage_file: File containing the signing lineage.
key_rotation_min_sdk: String of the minimum API level to rotate signing keys for.
zipalign_alignment: Zip alignment used before signing.
apk: The generated apk for the app.
sibling: The path to the launcher file.
Expand Down
10 changes: 9 additions & 1 deletion mobile_install/resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ res_types = [
]

def get_assets_dir(asset, base_dir):
"""Build the full assets directory sanitizing the input first."""
"""Build the full assets directory sanitizing the input first.

Args:
asset: The asset file or directory.
base_dir: The base assets directory.

Returns:
The sanitized assets directory path.
"""
if base_dir == "":
# some targets specify assets files and set assets_dirs = ""
return asset.dirname
Expand Down
2 changes: 0 additions & 2 deletions mobile_install/tools_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ TOOL_ATTRS = dict(
executable = True,
),


# Versioned Host Attrs
_android_kit = attr.label(
default = versioned_deps.android_kit.head,
Expand Down Expand Up @@ -163,5 +162,4 @@ TOOL_ATTRS = dict(
allow_single_file = True,
default = versioned_deps.res_v3_dummy_r_txt.head,
),

)
2 changes: 1 addition & 1 deletion mobile_install/transform.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def merge_dex_shards(ctx, data, sibling):
action per shard that runs dex_shard_merger on all dex files within that
shard.
Arguments:
Args:
ctx: The context.
data: A list of lists, where the inner list contains dex shards.
sibling: A file used to root the merged_dex shards.
Expand Down
4 changes: 2 additions & 2 deletions mobile_install/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ load("//rules:min_sdk_version.bzl", _min_sdk_version = "min_sdk_version")
load("//rules:visibility.bzl", "PROJECT_VISIBILITY")
load("//rules/flags:flags.bzl", "flags")
load("@rules_java//java/common:java_common.bzl", "java_common")

# Copybara: placeholder for GeneratedExtensionRegistryInfo load
load("//tools/jdk:jvmopts.bzl", "BASE_JVMOPTS")
load(":constants.bzl", "constants")
Expand Down Expand Up @@ -273,7 +274,6 @@ def merge_dex_shards(
"""
args = ctx.actions.args()


args.add("--multidex", "best_effort")
args.add("--output", out_dex_zip.path)
args.add_all(dex_archives, before_each = "--input")
Expand Down Expand Up @@ -340,7 +340,7 @@ def _extract_package_name(ctx, apk, package_name_output_file):
progress_message = "MI Extracts the package name from %s" % apk.path,
)

def _get_extension_registry_class_jar(target):
def _get_extension_registry_class_jar(target): # @unused

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is used in google? otherwise we can toss this here instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im trying to toss all the unused stuff in #530 so we can discuss that there

class_jar = None

return class_jar
Expand Down
6 changes: 5 additions & 1 deletion prereqs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ load("//bzlmod_extensions:apksig.bzl", _apksig_archive = "apksig")
load("//bzlmod_extensions:com_android_dex.bzl", _com_android_dex_archive = "com_android_dex")

def rules_android_prereqs(dev_mode = False):
"""Downloads prerequisite repositories for rules_android."""
"""Downloads prerequisite repositories for rules_android.

Args:
dev_mode: Whether to include development dependencies.
"""

maybe(
http_archive,
Expand Down
9 changes: 1 addition & 8 deletions providers/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@ load("//rules:visibility.bzl", "PROJECT_VISIBILITY")

visibility(PROJECT_VISIBILITY)



AndroidAppsInfo = provider(
doc = "Provides information about app to install.",
fields = dict(
apps = "List of app provider artifacts.",
),
)






AndroidFilteredJdepsInfo = provider(
doc = "Provides a filtered jdeps proto.",
fields = dict(
Expand Down Expand Up @@ -114,7 +107,6 @@ AndroidFeatureModuleInfo = provider(
),
)


Dex2OatApkInfo = provider(
doc = "Contains data about artifacts generated through host dex2oat.",
fields = dict(
Expand All @@ -133,6 +125,7 @@ InstrumentedAppInfo = provider(
)

FailureInfo = provider(
doc = "Provides failure information.",
fields = dict(
error = "Error message",
),
Expand Down
14 changes: 12 additions & 2 deletions rules/acls.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,21 @@ BYTECODE_TRANSFORMERS_DICT = make_dict(BYTECODE_TRANSFORMERS)
AAR_IMPORT_PROPAGATE_NATIVE_LIBS_FALLBACK_DICT = make_dict(AAR_IMPORT_PROPAGATE_NATIVE_LIBS_FALLBACK)

def matches(fqn, dct):
"""Returns whether a fully qualified label matches an ACL dictionary.

Args:
fqn: The fully qualified label to match.
dct: The ACL dictionary.

Returns:
True if the label matches the ACL dictionary.
"""

# Labels with workspace names ("@workspace//pkg:target") are not supported.
# For now, default external dependency ACLs to True to enable rollout features for all
# external users. See https://github.com/bazelbuild/rules_android/issues/68
# Note that this only affects Bazel builds with OSS rules_android.
if fqn.startswith("@") and not fqn.startswith("@//") and not fqn.startswith("@@//"):
if fqn.startswith("@") and not fqn.startswith("@//") and not fqn.startswith("@@//"): # buildifier: disable=canonical-repository
return True

# "@//" is the same as the main workspace. It's not completely accurate to treat these as
Expand All @@ -317,7 +327,7 @@ def matches(fqn, dct):
fqn = fqn[1:]

# "@@//" refers to the canonical name of the main repository.
if fqn.startswith("@@//"):
if fqn.startswith("@@//"): # buildifier: disable=canonical-repository
fqn = fqn[2:]

if not fqn.startswith("//"):
Expand Down
Loading