aboutsummaryrefslogtreecommitdiff
path: root/rules
diff options
context:
space:
mode:
Diffstat (limited to 'rules')
-rw-r--r--rules/BUILD2
-rw-r--r--rules/aar_import/impl.bzl5
-rw-r--r--rules/acls.bzl37
-rw-r--r--rules/acls/android_instrumentation_derived_test_class_rollout.bzl23
-rw-r--r--rules/acls/android_instrumentation_test_manifest_check_rollout.bzl (renamed from rules/acls/fix_application_id.bzl)11
-rw-r--r--rules/acls/android_library_starlark_resource_outputs.bzl26
-rw-r--r--rules/acls/lint_registry_rollout.bzl21
-rw-r--r--rules/android_application/android_feature_module_rule.bzl4
-rw-r--r--rules/android_library/attrs.bzl1
-rw-r--r--rules/android_library/rule.bzl21
-rw-r--r--rules/bundletool.bzl75
-rw-r--r--rules/busybox.bzl23
-rw-r--r--rules/data_binding.bzl26
-rw-r--r--rules/flags/flag_defs.bzl4
-rw-r--r--rules/java.bzl49
-rw-r--r--rules/resources.bzl20
-rw-r--r--rules/rules.bzl4
-rw-r--r--rules/utils.bzl9
18 files changed, 272 insertions, 89 deletions
diff --git a/rules/BUILD b/rules/BUILD
index d4c8d88..ac89362 100644
--- a/rules/BUILD
+++ b/rules/BUILD
@@ -8,5 +8,5 @@ exports_files([
alias(
name = "ResourceProcessorBusyBox",
actual = "@bazel_tools//tools/android:busybox",
- visibility = ["//visibility:public"],
+ visibility = ["//visibility:public"],
)
diff --git a/rules/aar_import/impl.bzl b/rules/aar_import/impl.bzl
index cec5a84..280060e 100644
--- a/rules/aar_import/impl.bzl
+++ b/rules/aar_import/impl.bzl
@@ -248,7 +248,10 @@ def _create_import_deps_check(
args = ctx.actions.args()
args.add_all(jars_to_check, before_each = "--input")
args.add_all(declared_deps, before_each = "--directdep")
- args.add_all(transitive_deps, before_each = "--classpath_entry")
+ args.add_all(
+ depset(order = "preorder", transitive = [declared_deps, transitive_deps]),
+ before_each = "--classpath_entry",
+ )
args.add_all(bootclasspath, before_each = "--bootclasspath_entry")
args.add("--checking_mode=error")
args.add("--jdeps_output", jdeps_output)
diff --git a/rules/acls.bzl b/rules/acls.bzl
index ea5032d..ffa1377 100644
--- a/rules/acls.bzl
+++ b/rules/acls.bzl
@@ -15,7 +15,7 @@
"""Access Control Lists.
To create a new list:
- 1. Create new .bzl file in this directory with a list of targets.
+ 1. Create new .bzl file in the acls directory with a list of targets.
2. Create matching method in this file.
3. Add matching method to struct.
@@ -42,13 +42,14 @@ load("@rules_android//rules/acls:android_instrumentation_binary_starlark_resourc
load("@rules_android//rules/acls:android_feature_splits_dogfood.bzl", "ANDROID_FEATURE_SPLITS_DOGFOOD")
load("@rules_android//rules/acls:android_library_implicit_exports.bzl", "ANDROID_LIBRARY_IMPLICIT_EXPORTS", "ANDROID_LIBRARY_IMPLICIT_EXPORTS_GENERATOR_FUNCTIONS")
load("@rules_android//rules/acls:android_library_resources_without_srcs.bzl", "ANDROID_LIBRARY_RESOURCES_WITHOUT_SRCS", "ANDROID_LIBRARY_RESOURCES_WITHOUT_SRCS_GENERATOR_FUNCTIONS")
+load("@rules_android//rules/acls:android_library_starlark_resource_outputs.bzl", "ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_FALLBACK", "ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_ROLLOUT")
load("@rules_android//rules/acls:android_lint_checks_rollout.bzl", "ANDROID_LINT_CHECKS_FALLBACK", "ANDROID_LINT_CHECKS_ROLLOUT")
load("@rules_android//rules/acls:android_lint_rollout.bzl", "ANDROID_LINT_FALLBACK", "ANDROID_LINT_ROLLOUT")
+load("@rules_android//rules/acls:lint_registry_rollout.bzl", "LINT_REGISTRY_FALLBACK", "LINT_REGISTRY_ROLLOUT")
load("@rules_android//rules/acls:android_build_stamping_rollout.bzl", "ANDROID_BUILD_STAMPING_FALLBACK", "ANDROID_BUILD_STAMPING_ROLLOUT")
load("@rules_android//rules/acls:b122039567.bzl", "B122039567")
load("@rules_android//rules/acls:b123854163.bzl", "B123854163")
load("@rules_android//rules/acls:dex2oat_opts.bzl", "CAN_USE_DEX2OAT_OPTIONS")
-load("@rules_android//rules/acls:fix_application_id.bzl", "FIX_APPLICATION_ID_FALLBACK", "FIX_APPLICATION_ID_ROLLOUT")
load("@rules_android//rules/acls:fix_export_exporting_rollout.bzl", "FIX_EXPORT_EXPORTING_FALLBACK", "FIX_EXPORT_EXPORTING_ROLLOUT")
load("@rules_android//rules/acls:fix_resource_transitivity_rollout.bzl", "FIX_RESOURCE_TRANSITIVITY_FALLBACK", "FIX_RESOURCE_TRANSITIVITY_ROLLOUT")
load("@rules_android//rules/acls:host_dex2oat_rollout.bzl", "AIT_USE_HOST_DEX2OAT_ROLLOUT", "AIT_USE_HOST_DEX2OAT_ROLLOUT_FALLBACK")
@@ -65,6 +66,8 @@ load(
"PARTIAL_JETIFICATION_TARGETS_ROLLOUT",
)
load("@rules_android//rules/acls:kt_android_library_rollout.bzl", "KT_ANDROID_LIBRARY_FALLBACK", "KT_ANDROID_LIBRARY_ROLLOUT")
+load("@rules_android//rules/acls:android_instrumentation_test_manifest_check_rollout.bzl", "ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_FALLBACK", "ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_ROLLOUT")
+load("@rules_android//rules/acls:android_instrumentation_derived_test_class_rollout.bzl", "ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_FALLBACK", "ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_ROLLOUT")
def _in_aar_import_deps_checker(fqn):
return not _matches(fqn, AAR_IMPORT_DEPS_CHECKER_FALLBACK_DICT) and _matches(fqn, AAR_IMPORT_DEPS_CHECKER_ROLLOUT_DICT)
@@ -102,6 +105,9 @@ def _in_android_lint_checks_rollout(fqn):
def _in_android_lint_rollout(fqn):
return not _matches(fqn, ANDROID_LINT_FALLBACK_DICT) and _matches(fqn, ANDROID_LINT_ROLLOUT_DICT)
+def _in_lint_registry_rollout(fqn):
+ return not _matches(fqn, LINT_REGISTRY_FALLBACK_DICT) and _matches(fqn, LINT_REGISTRY_ROLLOUT_DICT)
+
def _in_android_build_stamping_rollout(fqn):
return not _matches(fqn, ANDROID_BUILD_STAMPING_FALLBACK_DICT) and _matches(fqn, ANDROID_BUILD_STAMPING_ROLLOUT_DICT)
@@ -128,15 +134,15 @@ def _in_android_library_resources_without_srcs(fqn):
def _in_android_library_resources_without_srcs_generator_functions(gfn):
return gfn in ANDROID_LIBRARY_RESOURCES_WITHOUT_SRCS_GENERATOR_FUNCTIONS_DICT
+def _in_android_library_starlark_resource_outputs_rollout(fqn):
+ return not _matches(fqn, ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_FALLBACK_DICT) and _matches(fqn, ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_ROLLOUT_DICT)
+
def _in_app_installation_snapshot(fqn):
return not _matches(fqn, APP_INSTALLATION_SNAPSHOT_FALLBACK_DICT) and _matches(fqn, APP_INSTALLATION_SNAPSHOT_DICT)
def _in_dex2oat_opts(fqn):
return _matches(fqn, CAN_USE_DEX2OAT_OPTIONS_DICT)
-def _in_fix_application_id(fqn):
- return not _matches(fqn, FIX_APPLICATION_ID_FALLBACK_DICT) and _matches(fqn, FIX_APPLICATION_ID_ROLLOUT_DICT)
-
def _in_fix_export_exporting_rollout(fqn):
return not _matches(fqn, FIX_EXPORT_EXPORTING_FALLBACK_DICT) and _matches(fqn, FIX_EXPORT_EXPORTING_ROLLOUT_DICT)
@@ -176,6 +182,12 @@ def _in_partial_jetification_targets(fqn):
def _in_kt_android_library_rollout(fqn):
return not _matches(fqn, KT_ANDROID_LIBRARY_FALLBACK_DICT) and _matches(fqn, KT_ANDROID_LIBRARY_ROLLOUT_DICT)
+def _in_android_instrumentation_test_manifest_check_rollout(fqn):
+ return not _matches(fqn, ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_FALLBACK_DICT) and _matches(fqn, ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_ROLLOUT_DICT)
+
+def _in_android_instrumentation_test_derived_test_class_rollout(fqn):
+ return not _matches(fqn, ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_FALLBACK_DICT) and _matches(fqn, ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_ROLLOUT_DICT)
+
def _make_dict(lst):
"""Do not use this method outside of this file."""
return {t: True for t in lst}
@@ -199,10 +211,14 @@ ANDROID_LIBRARY_IMPLICIT_EXPORTS_DICT = _make_dict(ANDROID_LIBRARY_IMPLICIT_EXPO
ANDROID_LIBRARY_IMPLICIT_EXPORTS_GENERATOR_FUNCTIONS_DICT = _make_dict(ANDROID_LIBRARY_IMPLICIT_EXPORTS_GENERATOR_FUNCTIONS)
ANDROID_LIBRARY_RESOURCES_WITHOUT_SRCS_DICT = _make_dict(ANDROID_LIBRARY_RESOURCES_WITHOUT_SRCS)
ANDROID_LIBRARY_RESOURCES_WITHOUT_SRCS_GENERATOR_FUNCTIONS_DICT = _make_dict(ANDROID_LIBRARY_RESOURCES_WITHOUT_SRCS_GENERATOR_FUNCTIONS)
+ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_FALLBACK_DICT = _make_dict(ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_FALLBACK)
+ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_ROLLOUT_DICT = _make_dict(ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_ROLLOUT)
ANDROID_LINT_CHECKS_FALLBACK_DICT = _make_dict(ANDROID_LINT_CHECKS_FALLBACK)
ANDROID_LINT_CHECKS_ROLLOUT_DICT = _make_dict(ANDROID_LINT_CHECKS_ROLLOUT)
ANDROID_LINT_FALLBACK_DICT = _make_dict(ANDROID_LINT_FALLBACK)
ANDROID_LINT_ROLLOUT_DICT = _make_dict(ANDROID_LINT_ROLLOUT)
+LINT_REGISTRY_FALLBACK_DICT = _make_dict(LINT_REGISTRY_FALLBACK)
+LINT_REGISTRY_ROLLOUT_DICT = _make_dict(LINT_REGISTRY_ROLLOUT)
ANDROID_BUILD_STAMPING_ROLLOUT_DICT = _make_dict(ANDROID_BUILD_STAMPING_ROLLOUT)
ANDROID_BUILD_STAMPING_FALLBACK_DICT = _make_dict(ANDROID_BUILD_STAMPING_FALLBACK)
ANDROID_TEST_LOCKDOWN_GENERATOR_FUNCTIONS_DICT = _make_dict(ANDROID_TEST_LOCKDOWN_GENERATOR_FUNCTIONS)
@@ -212,8 +228,6 @@ APP_INSTALLATION_SNAPSHOT_FALLBACK_DICT = _make_dict(APP_INSTALLATION_SNAPSHOT_F
B122039567_DICT = _make_dict(B122039567)
B123854163_DICT = _make_dict(B123854163)
CAN_USE_DEX2OAT_OPTIONS_DICT = _make_dict(CAN_USE_DEX2OAT_OPTIONS)
-FIX_APPLICATION_ID_FALLBACK_DICT = _make_dict(FIX_APPLICATION_ID_FALLBACK)
-FIX_APPLICATION_ID_ROLLOUT_DICT = _make_dict(FIX_APPLICATION_ID_ROLLOUT)
FIX_RESOURCE_TRANSIVITY_FALLBACK_DICT = _make_dict(FIX_RESOURCE_TRANSITIVITY_FALLBACK)
FIX_RESOURCE_TRANSIVITY_ROLLOUT_DICT = _make_dict(FIX_RESOURCE_TRANSITIVITY_ROLLOUT)
FIX_EXPORT_EXPORTING_FALLBACK_DICT = _make_dict(FIX_EXPORT_EXPORTING_FALLBACK)
@@ -237,6 +251,10 @@ PARTIAL_JETIFICATION_TARGETS_ROLLOUT_DICT = _make_dict(PARTIAL_JETIFICATION_TARG
PARTIAL_JETIFICATION_TARGETS_FALLBACK_DICT = _make_dict(PARTIAL_JETIFICATION_TARGETS_FALLBACK)
KT_ANDROID_LIBRARY_ROLLOUT_DICT = _make_dict(KT_ANDROID_LIBRARY_ROLLOUT)
KT_ANDROID_LIBRARY_FALLBACK_DICT = _make_dict(KT_ANDROID_LIBRARY_FALLBACK)
+ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_ROLLOUT_DICT = _make_dict(ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_ROLLOUT)
+ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_FALLBACK_DICT = _make_dict(ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_FALLBACK)
+ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_ROLLOUT_DICT = _make_dict(ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_ROLLOUT)
+ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_FALLBACK_DICT = _make_dict(ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_FALLBACK)
def _matches(fqn, dct):
# Labels with workspace names ("@workspace//pkg:target") are not supported.
@@ -288,15 +306,16 @@ acls = struct(
in_android_feature_splits_dogfood = _in_android_feature_splits_dogfood,
in_android_library_implicit_exports = _in_android_library_implicit_exports,
in_android_library_implicit_exports_generator_functions = _in_android_library_implicit_exports_generator_functions,
+ in_android_library_starlark_resource_outputs_rollout = _in_android_library_starlark_resource_outputs_rollout,
in_android_library_resources_without_srcs = _in_android_library_resources_without_srcs,
in_android_library_resources_without_srcs_generator_functions = _in_android_library_resources_without_srcs_generator_functions,
in_android_lint_checks_rollout = _in_android_lint_checks_rollout,
in_android_lint_rollout = _in_android_lint_rollout,
+ in_lint_registry_rollout = _in_lint_registry_rollout,
in_android_build_stamping_rollout = _in_android_build_stamping_rollout,
in_android_test_lockdown_allowlist = _in_android_test_lockdown_allowlist,
in_app_installation_snapshot = _in_app_installation_snapshot,
in_dex2oat_opts = _in_dex2oat_opts,
- in_fix_application_id = _in_fix_application_id,
in_fix_export_exporting_rollout = _in_fix_export_exporting_rollout,
in_fix_resource_transivity_rollout = _in_fix_resource_transivity_rollout,
in_host_dex2oat_rollout = _in_host_dex2oat_rollout,
@@ -310,6 +329,8 @@ acls = struct(
in_allow_resource_conflicts = _in_allow_resource_conflicts,
in_partial_jetification_targets = _in_partial_jetification_targets,
in_kt_android_library_rollout = _in_kt_android_library_rollout,
+ in_android_instrumentation_test_manifest_check_rollout = _in_android_instrumentation_test_manifest_check_rollout,
+ in_android_instrumentation_test_derived_test_class_rollout = _in_android_instrumentation_test_derived_test_class_rollout,
)
# Visible for testing
diff --git a/rules/acls/android_instrumentation_derived_test_class_rollout.bzl b/rules/acls/android_instrumentation_derived_test_class_rollout.bzl
new file mode 100644
index 0000000..782beb8
--- /dev/null
+++ b/rules/acls/android_instrumentation_derived_test_class_rollout.bzl
@@ -0,0 +1,23 @@
+# Copyright 2021 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Rollout list for enabling test class derivation in android_instrumentation_test,"""
+
+ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_ROLLOUT = [
+ "//:__subpackages__",
+]
+
+ANDROID_INSTRUMENTATION_TEST_DERIVED_TEST_CLASS_FALLBACK = [
+ "//javatests/notinacl:__subpackages__",
+]
diff --git a/rules/acls/fix_application_id.bzl b/rules/acls/android_instrumentation_test_manifest_check_rollout.bzl
index 41c18b7..154f6bb 100644
--- a/rules/acls/fix_application_id.bzl
+++ b/rules/acls/android_instrumentation_test_manifest_check_rollout.bzl
@@ -12,16 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Allowlist for fixing the implicit application ID in manifest processing.
+"""Rollout list for enabling manifest validation in android_instrumentation_test."""
-See b/111923269 for context.
-"""
-
-# keep sorted
-FIX_APPLICATION_ID_ROLLOUT = [
+ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_ROLLOUT = [
"//:__subpackages__",
]
-# keep sorted
-FIX_APPLICATION_ID_FALLBACK = [
+ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_FALLBACK = [
]
diff --git a/rules/acls/android_library_starlark_resource_outputs.bzl b/rules/acls/android_library_starlark_resource_outputs.bzl
new file mode 100644
index 0000000..b798fa3
--- /dev/null
+++ b/rules/acls/android_library_starlark_resource_outputs.bzl
@@ -0,0 +1,26 @@
+# Copyright 2021 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Allow list for setting the resource outputs (.srcjar, R.txt, and _resources.jar) of android_library to
+those files generated by the Starlark resource processing pipeline and not the native resource
+processing pipeline. These resource-related predeclared outputs need to be re-pointed to the corresponding
+artifacts in the Starlark pipeline. See b/177261846."""
+
+# keep sorted
+ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_ROLLOUT = [
+ "//:__subpackages__",
+]
+
+ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_FALLBACK = [
+]
diff --git a/rules/acls/lint_registry_rollout.bzl b/rules/acls/lint_registry_rollout.bzl
new file mode 100644
index 0000000..3138f94
--- /dev/null
+++ b/rules/acls/lint_registry_rollout.bzl
@@ -0,0 +1,21 @@
+# Copyright 2021 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Allow list for the Android Lint Registry target."""
+
+# keep sorted
+LINT_REGISTRY_ROLLOUT = [
+]
+
+LINT_REGISTRY_FALLBACK = []
diff --git a/rules/android_application/android_feature_module_rule.bzl b/rules/android_application/android_feature_module_rule.bzl
index 87c57b5..3041656 100644
--- a/rules/android_application/android_feature_module_rule.bzl
+++ b/rules/android_application/android_feature_module_rule.bzl
@@ -121,6 +121,7 @@ def android_feature_module_macro(_android_binary, _android_library, **attrs):
tags = getattr(attrs, "tags", [])
transitive_configs = getattr(attrs, "transitive_configs", [])
visibility = getattr(attrs, "visibility", None)
+ testonly = getattr(attrs, "testonly", None)
# Create strings.xml containing split title
title_id = "split_" + str(hash(fqn)).replace("-", "N")
@@ -164,6 +165,7 @@ EOF
tags = tags,
transitive_configs = transitive_configs,
visibility = visibility,
+ testonly = testonly,
)
# Wrap any deps in an android_binary. Will be validated to ensure does not contain any dexes
@@ -178,6 +180,7 @@ EOF
"visibility": visibility,
"feature_flags": getattr(attrs, "feature_flags", None),
"$enable_manifest_merging": False,
+ "testonly": testonly,
}
_android_binary(**binary_attrs)
@@ -193,4 +196,5 @@ EOF
tags = tags,
transitive_configs = transitive_configs,
visibility = visibility,
+ testonly = testonly,
)
diff --git a/rules/android_library/attrs.bzl b/rules/android_library/attrs.bzl
index b71b466..8e38b01 100644
--- a/rules/android_library/attrs.bzl
+++ b/rules/android_library/attrs.bzl
@@ -66,6 +66,7 @@ ATTRS = _attrs.add(
_flags = attr.label(
default = "@rules_android//rules/flags",
),
+ _package_name = attr.string(), # for sending the package name to the outputs callback
),
_attrs.COMPILATION,
_attrs.DATA_CONTEXT,
diff --git a/rules/android_library/rule.bzl b/rules/android_library/rule.bzl
index f267b37..02cc1fc 100644
--- a/rules/android_library/rule.bzl
+++ b/rules/android_library/rule.bzl
@@ -14,6 +14,7 @@
"""android_library rule."""
+load("@rules_android//rules:acls.bzl", "acls")
load(":attrs.bzl", _ATTRS = "ATTRS")
load(":impl.bzl", _impl = "impl")
load(
@@ -21,7 +22,7 @@ load(
_attrs = "attrs",
)
-def _outputs(_defined_local_resources):
+def _outputs(name, _package_name, _defined_local_resources):
outputs = dict(
lib_jar = "lib%{name}.jar",
lib_src_jar = "lib%{name}-src.jar",
@@ -31,11 +32,16 @@ def _outputs(_defined_local_resources):
if _defined_local_resources:
# TODO(b/177261846): resource-related predeclared outputs need to be re-pointed at the
# corresponding artifacts in the Starlark pipeline.
+ label = "//" + _package_name + ":" + name
+ if acls.in_android_library_starlark_resource_outputs_rollout(label):
+ path_prefix = "_migrated/"
+ else:
+ path_prefix = ""
outputs.update(
dict(
- resources_src_jar = "_migrated/%{name}.srcjar",
- resources_txt = "_migrated/%{name}_symbols/R.txt",
- resources_jar = "_migrated/%{name}_resources.jar",
+ resources_src_jar = path_prefix + "%{name}.srcjar",
+ resources_txt = path_prefix + "%{name}_symbols/R.txt",
+ resources_jar = path_prefix + "%{name}_resources.jar",
),
)
@@ -51,6 +57,8 @@ def make_rule(
Args:
attrs: A dict. The attributes for the rule.
implementation: A function. The rule's implementation method.
+ outputs: A dict, function, or None. The rule's outputs.
+ additional_toolchains: A list. Additional toolchains passed to pass to rule(toolchains).
Returns:
A rule.
@@ -122,6 +130,11 @@ def attrs_metadata(attrs):
attrs["$defined_idl_import_root"] = _is_defined("idl_import_root", attrs)
attrs["$defined_idl_parcelables"] = _is_defined("idl_parcelables", attrs)
attrs["$defined_idl_srcs"] = _is_defined("idl_srcs", attrs)
+
+ # Required for ACLs check in _outputs(), since the callback can't access
+ # the native module.
+ attrs["$package_name"] = native.package_name()
+
return attrs
def android_library_macro(**attrs):
diff --git a/rules/bundletool.bzl b/rules/bundletool.bzl
index 07f5217..161882a 100644
--- a/rules/bundletool.bzl
+++ b/rules/bundletool.bzl
@@ -16,6 +16,16 @@
load(":java.bzl", _java = "java")
+_density_mapping = {
+ "ldpi": 120,
+ "mdpi": 160,
+ "hdpi": 240,
+ "xhdpi": 320,
+ "xxhdpi": 480,
+ "xxxhdpi": 640,
+ "tvdpi": 213,
+}
+
def _proto_apk_to_module(
ctx,
out = None,
@@ -72,7 +82,7 @@ if [ $UNKNOWN != 0 ]; then
fi
cd "${OUT_DIR}"
-"${CUR_PWD}/${ZIP}" "${CUR_PWD}/${OUTPUT}" -Drqq .
+"${CUR_PWD}/${ZIP}" "${CUR_PWD}/${OUTPUT}" -Drq0 .
""" % (
unzip.executable.path,
zip.executable.path,
@@ -182,8 +192,71 @@ echo "$contents" > %s
command = cmd,
)
+def _bundle_to_apks(
+ ctx,
+ out = None,
+ bundle = None,
+ universal = False,
+ device_spec = None,
+ keystore = None,
+ modules = None,
+ aapt2 = None,
+ bundletool = None,
+ host_javabase = None):
+ inputs = [bundle]
+ args = ctx.actions.args()
+ args.add("build-apks")
+ args.add("--output", out)
+ args.add("--bundle", bundle)
+ args.add("--aapt2", aapt2.executable.path)
+
+ if universal:
+ args.add("--mode=universal")
+
+ if keystore:
+ args.add("--ks", keystore.path)
+ args.add("--ks-pass", "pass:android")
+ args.add("--ks-key-alias", "AndroidDebugKey")
+ inputs.append(keystore)
+
+ if device_spec:
+ args.add("--device-spec", device_spec)
+ inputs.append(device_spec)
+
+ if modules:
+ args.add_joined("--modules", modules, join_with = ",")
+
+ _java.run(
+ ctx = ctx,
+ host_javabase = host_javabase,
+ executable = bundletool,
+ arguments = [args],
+ inputs = inputs,
+ outputs = [out],
+ tools = [aapt2],
+ mnemonic = "BundleToApks",
+ progress_message = "Converting bundle to .apks: %s" % out.short_path,
+ )
+
+def _build_device_json(
+ ctx,
+ out,
+ abis,
+ locales,
+ density,
+ sdk_version):
+ json_content = json.encode(struct(
+ supportedAbis = abis,
+ supportedLocales = locales,
+ screenDensity = _density_mapping[density],
+ sdkVersion = int(sdk_version),
+ ))
+ ctx.actions.write(out, json_content)
+
bundletool = struct(
build = _build,
+ build_device_json = _build_device_json,
+ bundle_to_apks = _bundle_to_apks,
extract_config = _extract_config,
extract_manifest = _extract_manifest,
proto_apk_to_module = _proto_apk_to_module,
diff --git a/rules/busybox.bzl b/rules/busybox.bzl
index f0d78ac..a92fe68 100644
--- a/rules/busybox.bzl
+++ b/rules/busybox.bzl
@@ -191,6 +191,7 @@ def _package(
resource_configs = None,
densities = [],
application_id = None,
+ package_id = None,
direct_resources_nodes = [],
transitive_resources_nodes = [],
transitive_manifests = [],
@@ -233,6 +234,11 @@ def _package(
densities: A list of strings. The list of screen densities to filter for when
building the apk.
application_id: An optional string. The applicationId set in manifest values.
+ package_id: An optional integer in [2,255]. This is the prefix byte for
+ all generated resource IDs, defaults to 0x7F (127). 1 is reserved by the
+ framework, and some builds are known to crash when given IDs > 127.
+ Shared libraries are also assigned monotonically increasing IDs in
+ [2,126], so care should be taken that there is room at the lower end.
direct_resources_nodes: Depset of ResourcesNodeInfo providers. The set of
ResourcesNodeInfo from direct dependencies.
transitive_resources_nodes: Depset of ResourcesNodeInfo providers. The set
@@ -356,6 +362,8 @@ def _package(
args.add_joined("--densities", _extract_filters(densities), join_with = ",")
if application_id:
args.add("--applicationId", application_id)
+ if package_id:
+ args.add("--packageId", package_id)
if additional_apks_to_link_against:
args.add_joined(
"--additionalApksToLinkAgainst",
@@ -372,7 +380,8 @@ def _package(
args.add("--versionName", version_name)
if version_code:
args.add("--versionCode", version_code)
- args.add("--packageForR", java_package)
+ if java_package:
+ args.add("--packageForR", java_package)
_java.run(
ctx = ctx,
@@ -792,7 +801,7 @@ def _merge_manifests(
fail("Unexpected manifest merge type: " + merge_type)
outputs = [out_file]
- directs = [manifest]
+ directs = [manifest] if manifest else []
transitives = [mergee_manifests]
# Args for busybox
@@ -800,7 +809,8 @@ def _merge_manifests(
args.use_param_file("@%s", use_always = True)
args.add("--tool", "MERGE_MANIFEST")
args.add("--")
- args.add("--manifest", manifest)
+ if manifest:
+ args.add("--manifest", manifest)
args.add_all(
"--mergeeManifests",
[mergee_manifests],
@@ -812,7 +822,8 @@ def _merge_manifests(
",".join(["%s:%s" % (_escape_mv(k), _escape_mv(v)) for k, v in manifest_values.items()]),
)
args.add("--mergeType", merge_type)
- args.add("--customPackage", java_package)
+ if java_package:
+ args.add("--customPackage", java_package)
args.add("--manifestOutput", out_file)
if out_log_file:
args.add("--log", out_log_file)
@@ -919,7 +930,8 @@ def _generate_binary_r(
args.add("--")
args.add("--primaryRTxt", r_txt)
args.add("--primaryManifest", manifest)
- args.add("--packageForR", package_for_r)
+ if package_for_r:
+ args.add("--packageForR", package_for_r)
args.add_all(
resources_nodes,
map_each = _make_generate_binay_r_flags,
@@ -933,6 +945,7 @@ def _generate_binary_r(
# TODO(b/154003916): support transitive "--library transitive_r_txt_path,transitive_manifest_path" flags
args.add("--classJarOutput", out_class_jar)
args.add("--targetLabel", str(ctx.label))
+ args.use_param_file("@%s")
_java.run(
ctx = ctx,
diff --git a/rules/data_binding.bzl b/rules/data_binding.bzl
index 70df90f..9243673 100644
--- a/rules/data_binding.bzl
+++ b/rules/data_binding.bzl
@@ -66,15 +66,27 @@ def _gen_sources(ctx, output_dir, java_package, deps, layout_info, data_binding_
args.add("-zipSourceOutput", "true")
args.add("-useAndroidX", "false")
- class_infos = []
- for info in deps:
- class_infos.extend(info.class_infos)
+ if deps:
+ if type(deps[0].class_infos) == "depset":
+ class_infos = depset(transitive = [info.class_infos for info in deps])
+ inputs = depset(direct = [layout_info], transitive = [class_infos])
+ elif type(deps[0].class_infos) == "list":
+ class_infos = []
+ for info in deps:
+ class_infos.extend(info.class_infos)
+ inputs = class_infos + [layout_info]
+ else:
+ fail("Expected list or depset. Got %s" % type(deps[0].class_infos))
+ else:
+ class_infos = []
+ inputs = [layout_info]
+
args.add_all(class_infos, before_each = "-dependencyClassInfoList")
ctx.actions.run(
executable = data_binding_exec,
arguments = ["GEN_BASE_CLASSES", args],
- inputs = class_infos + [layout_info],
+ inputs = inputs,
outputs = [class_info, srcjar],
mnemonic = "GenerateDataBindingBaseClasses",
progress_message = (
@@ -91,8 +103,8 @@ def _setup_dependent_lib_artifacts(ctx, output_dir, deps):
for info in deps:
# Yes, DataBinding requires depsets iterations.
for artifact in (info.transitive_br_files.to_list() +
- info.setter_stores +
- info.class_infos):
+ _utils.list_or_depset_to_list(info.setter_stores) +
+ _utils.list_or_depset_to_list(info.class_infos)):
# short_path might contain a parent directory reference if the
# databinding artifact is from an external repository (e.g. an aar
# from Maven). If that's the case, just remove the parent directory
@@ -208,7 +220,7 @@ def _process(
]
return struct(**db_info)
- output_dir = "_migrated/databinding/%s/" % ctx.label.name
+ output_dir = "databinding/%s/" % ctx.label.name
db_info[_JAVA_SRCS].append(_copy_annotation_file(
ctx,
diff --git a/rules/flags/flag_defs.bzl b/rules/flags/flag_defs.bzl
index 7b9a8d8..08eee2d 100644
--- a/rules/flags/flag_defs.bzl
+++ b/rules/flags/flag_defs.bzl
@@ -31,7 +31,7 @@ def define_flags():
flags.DEFINE_int(
name = "num_dex_shards",
- default = 16,
+ default = 32,
description = "Number of dex shards to use for mobile-install.",
)
@@ -64,7 +64,7 @@ def define_flags():
flags.DEFINE_bool(
name = "enable_splits",
- default = False,
+ default = True,
description = "Build and install split apks if the device supports them.",
)
diff --git a/rules/java.bzl b/rules/java.bzl
index 42470f0..2e2fc58 100644
--- a/rules/java.bzl
+++ b/rules/java.bzl
@@ -14,7 +14,6 @@
"""Bazel Java APIs for the Android rules."""
-load(":acls.bzl", "acls")
load(":path.bzl", _path = "path")
load(":utils.bzl", "log")
@@ -89,8 +88,7 @@ def _resolve_package(path):
def _resolve_package_from_label(
label,
- custom_package = None,
- fallback = True):
+ custom_package = None):
"""Resolves the Java package from a Label.
When no legal Java package can be resolved from the label, None will be
@@ -111,15 +109,7 @@ def _resolve_package_from_label(
[label.package] +
_path.split(label.name)[:-1],
)
- java_package = _resolve_package(label_path)
-
- if java_package != None: # "" is a valid result.
- return java_package
-
- if fallback:
- return label.package.replace("/", ".")
-
- return None
+ return _resolve_package(label_path)
def _root(path):
"""Determines the Java root from the given path.
@@ -169,29 +159,6 @@ def _invalid_java_package(custom_package, java_package):
(not custom_package and _check_for_invalid_java_package(java_package))
)
-def _set_default_applicationid(fqn, attrs):
- """Sets the manifest value applicationId to the package.
-
- If applicationId is missing from the manifest_values, set it
- to the package as a default value to avoid using library packages
- when merging manifests.
- """
- if not acls.in_fix_application_id(fqn):
- return attrs
- new_attrs = {}
- new_attrs.update(attrs)
- package_string = _resolve_package_from_label(Label(fqn), None)
-
- # TODO(timpeut): handle select()s
- mv_attr = attrs.get("manifest_values", None) or {}
- if type(mv_attr) == "dict" and "applicationId" not in mv_attr:
- manifest_values = {}
- manifest_values.update(mv_attr)
- manifest_values.update({"__INTERNAL_PKG_DO_NOT_USE__": package_string})
- new_attrs["manifest_values"] = manifest_values
-
- return new_attrs
-
# The Android specific Java compile.
def _compile_android(
ctx,
@@ -227,8 +194,8 @@ def _compile_android(
r_java: JavaInfo. The R.jar dependency. Optional.
deps: sequence of JavaInfo providers. A list of dependencies. Optional.
exports: sequence of JavaInfo providers. A list of exports. Optional.
- plugins: sequence of JavaInfo providers. A list of plugins. Optional.
- exported_plugins: sequence of JavaInfo providers. A list of exported
+ plugins: sequence of JavaPluginInfo providers. A list of plugins. Optional.
+ exported_plugins: sequence of JavaPluginInfo providers. A list of exported
plugins. Optional.
annotation_processor_additional_outputs: sequence of Files. A list of
files produced by an annotation processor.
@@ -327,8 +294,8 @@ def _compile(
Optional.
deps: sequence of JavaInfo providers. A list of dependencies. Optional.
exports: sequence of JavaInfo providers. A list of exports. Optional.
- plugins: sequence of JavaInfo providers. A list of plugins. Optional.
- exported_plugins: sequence of JavaInfo providers. A list of exported
+ plugins: sequence of JavaPluginInfo providers. A list of plugins. Optional.
+ exported_plugins: sequence of JavaPluginInfo providers. A list of exported
plugins. Optional.
annotation_processor_additional_outputs: sequence of Files. A list of
files produced by an annotation processor.
@@ -406,6 +373,9 @@ def _singlejar(
args.add("--sources")
args.add_all(inputs)
+ args.use_param_file("@%s")
+ args.set_param_file_format("multiline")
+
ctx.actions.run(
executable = java_toolchain[java_common.JavaToolchainInfo].single_jar,
arguments = [args],
@@ -469,7 +439,6 @@ java = struct(
resolve_package = _resolve_package,
resolve_package_from_label = _resolve_package_from_label,
root = _root,
- set_default_applicationid = _set_default_applicationid,
invalid_java_package = _invalid_java_package,
run = _run,
singlejar = _singlejar,
diff --git a/rules/resources.bzl b/rules/resources.bzl
index 9bebb87..2ad89c6 100644
--- a/rules/resources.bzl
+++ b/rules/resources.bzl
@@ -60,11 +60,6 @@ _ASSET_DEFINITION_ERROR = (
"both empty or non-empty."
)
-_JAVA_PACKAGE_MISSING_ERROR = (
- "In target %s, a java package is required when stamping " +
- "the manifest."
-)
-
_INCORRECT_RESOURCE_LAYOUT_ERROR = (
"'%s' is not in the expected resource directory structure of " +
"<resource directory>/{%s}/<file>" % (",").join(_RESOURCE_FOLDER_TYPES)
@@ -139,7 +134,7 @@ def _generate_dummy_manifest(
min_sdk_version = None):
content = """<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="%s">""" % java_package
+ package="%s">""" % (java_package or "com.default")
if min_sdk_version:
content = content + """
@@ -316,6 +311,7 @@ def _fix_databinding_compiled_resources(
ctx: The context.
out_compiled_resources: File. The modified compiled_resources output.
compiled_resources: File. The compiled_resources zip.
+ zip_tool: FilesToRunProvider. The zip tool executable or FilesToRunProvider
"""
ctx.actions.run_shell(
outputs = [out_compiled_resources],
@@ -420,6 +416,7 @@ def _package(
resource_files = [],
nocompress_extensions = [],
java_package = None,
+ package_id = None,
compilation_mode = _compilation_mode.FASTBUILD,
shrink_resources = None,
use_android_resource_shrinking = None,
@@ -460,6 +457,11 @@ def _package(
java_package: String. Java package for which java sources will be
generated. By default the package is inferred from the directory where
the BUILD file containing the rule is.
+ package_id: An optional integer in [2,255]. This is the prefix byte for
+ all generated resource IDs, defaults to 0x7F (127). 1 is reserved by the
+ framework, and some builds are known to crash when given IDs > 127.
+ Shared libraries are also assigned monotonically increasing IDs in
+ [2,126], so care should be taken that there is room at the lower end.
compilation_mode: String. A string that represents compilation mode. The
list of expected values are as follows: dbg, fastbuild, opt.
shrink_resources: Tristate. Whether resource shrinking is enabled by the rule.
@@ -579,7 +581,7 @@ def _package(
processed_resources = resource_files
data_binding_layout_info = None
if enable_data_binding:
- data_binding_layout_info = ctx.actions.declare_file("_migrated/databinding/" + ctx.label.name + "/layout-info.zip")
+ data_binding_layout_info = ctx.actions.declare_file("_migrated/" + ctx.label.name + "/layout-info.zip")
processed_resources, resources_dirname = _make_databinding_outputs(
ctx,
resource_files,
@@ -620,6 +622,7 @@ def _package(
out_main_dex_proguard_cfg = main_dex_proguard_cfg,
out_resource_files_zip = resource_files_zip,
application_id = manifest_values.get("applicationId", None),
+ package_id = package_id,
manifest = merged_manifest,
assets = assets,
assets_dir = assets_dir,
@@ -1092,9 +1095,6 @@ def _process_starlark(
if resource_files and not manifest:
_log.error(_MANIFEST_MISSING_ERROR % ctx.label)
- if stamp_manifest and not java_package:
- _log.error(_JAVA_PACKAGE_MISSING_ERROR % ctx.label)
-
direct_resources_nodes = []
transitive_resources_nodes = []
transitive_assets = []
diff --git a/rules/rules.bzl b/rules/rules.bzl
index 2a0a585..315fd4f 100644
--- a/rules/rules.bzl
+++ b/rules/rules.bzl
@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Skylark rules for building Android apps."""
+"""Starlark rules for building Android apps."""
load(
"//rules/aar_import:rule.bzl",
@@ -20,7 +20,7 @@ load(
)
load(
"//rules/android_application:android_application.bzl",
- _android_application = "android_application"
+ _android_application = "android_application",
)
load(
":android_binary.bzl",
diff --git a/rules/utils.bzl b/rules/utils.bzl
index 5bd764e..d796371 100644
--- a/rules/utils.bzl
+++ b/rules/utils.bzl
@@ -195,6 +195,14 @@ def _only(collection):
_error("Expected one element, has %s." % len(collection))
return _first(collection)
+def _list_or_depset_to_list(list_or_depset):
+ if type(list_or_depset) == "list":
+ return list_or_depset
+ elif type(list_or_depset) == "depset":
+ return list_or_depset.to_list()
+ else:
+ return _error("Expected a list or a depset. Got %s" % type(list_or_depset))
+
def _copy_file(ctx, src, dest):
if src.is_directory or dest.is_directory:
fail("Cannot use copy_file with directories")
@@ -444,6 +452,7 @@ utils = struct(
sanitize_string = _sanitize_string,
sanitize_java_package = _sanitize_java_package,
hex = _hex,
+ list_or_depset_to_list = _list_or_depset_to_list,
)
log = struct(