aboutsummaryrefslogtreecommitdiff
path: root/rules
diff options
context:
space:
mode:
Diffstat (limited to 'rules')
-rw-r--r--rules/BUILD1
-rw-r--r--rules/aar_import/impl.bzl2
-rw-r--r--rules/acls.bzl58
-rw-r--r--rules/acls/min_sdk_floors.bzl (renamed from rules/acls/enforce_min_sdk_floor_rollout.bzl)20
-rw-r--r--rules/android_application/android_application_rule.bzl4
-rw-r--r--rules/android_binary_internal/attrs.bzl4
-rw-r--r--rules/android_binary_internal/impl.bzl68
-rw-r--r--rules/android_binary_internal/r8.bzl1
-rw-r--r--rules/android_library/impl.bzl2
-rw-r--r--rules/android_library/rule.bzl6
-rw-r--r--rules/android_local_test/impl.bzl6
-rw-r--r--rules/android_neverlink_aspect.bzl4
-rw-r--r--rules/android_sandboxed_sdk/android_binary_with_sandboxed_sdks_macro.bzl70
-rw-r--r--rules/android_sdk_repository/helper.bzl45
-rw-r--r--rules/attrs.bzl6
-rw-r--r--rules/bundletool.bzl72
-rw-r--r--rules/busybox.bzl5
-rw-r--r--rules/dex.bzl16
-rw-r--r--rules/dex_desugar_aspect.bzl9
-rw-r--r--rules/instrumented_app_info_aspect.bzl26
-rw-r--r--rules/native_deps.bzl27
-rw-r--r--rules/proguard.bzl48
-rw-r--r--rules/resources.bzl19
-rw-r--r--rules/sandboxed_sdk_toolbox.bzl14
24 files changed, 336 insertions, 197 deletions
diff --git a/rules/BUILD b/rules/BUILD
index 467072b..d907612 100644
--- a/rules/BUILD
+++ b/rules/BUILD
@@ -33,6 +33,7 @@ bzl_library(
"common.bzl",
"data_binding.bzl",
"idl.bzl",
+ "instrumented_app_info_aspect.bzl",
"intellij.bzl",
"java.bzl",
"migration_tag_DONOTUSE.bzl",
diff --git a/rules/aar_import/impl.bzl b/rules/aar_import/impl.bzl
index 0b149bb..c80d618 100644
--- a/rules/aar_import/impl.bzl
+++ b/rules/aar_import/impl.bzl
@@ -475,7 +475,7 @@ def impl(ctx):
manifest_ctx = _resources.bump_min_sdk(
ctx,
manifest = android_manifest,
- floor = _resources.DEPOT_MIN_SDK_FLOOR if _acls.in_enforce_min_sdk_floor_rollout(str(ctx.label)) else 0,
+ floor = _acls.get_min_sdk_floor(str(ctx.label)),
enforce_min_sdk_floor_tool = _get_android_toolchain(ctx).enforce_min_sdk_floor_tool.files_to_run,
)
diff --git a/rules/acls.bzl b/rules/acls.bzl
index 858ef07..edef667 100644
--- a/rules/acls.bzl
+++ b/rules/acls.bzl
@@ -33,56 +33,62 @@ load("//rules/acls:aar_import_exports_r_java.bzl", "AAR_IMPORT_EXPORTS_R_JAVA")
load("//rules/acls:aar_propagate_resources.bzl", "AAR_PROPAGATE_RESOURCES_FALLBACK", "AAR_PROPAGATE_RESOURCES_ROLLOUT")
load("//rules/acls:ait_install_snapshots.bzl", "APP_INSTALLATION_SNAPSHOT", "APP_INSTALLATION_SNAPSHOT_FALLBACK")
load("//rules/acls:allow_resource_conflicts.bzl", "ALLOW_RESOURCE_CONFLICTS")
+load("//rules/acls:android_apk_to_bundle_features_lockdown.bzl", "ANDROID_APK_TO_BUNDLE_FEATURES")
load("//rules/acls:android_archive_dogfood.bzl", "ANDROID_ARCHIVE_DOGFOOD")
load("//rules/acls:android_archive_duplicate_class_allowlist.bzl", "ANDROID_ARCHIVE_DUPLICATE_CLASS_ALLOWLIST")
load("//rules/acls:android_archive_excluded_deps_denylist.bzl", "ANDROID_ARCHIVE_EXCLUDED_DEPS_DENYLIST")
load("//rules/acls:android_archive_exposed_package_allowlist.bzl", "ANDROID_ARCHIVE_EXPOSED_PACKAGE_ALLOWLIST")
-load("//rules/acls:android_test_lockdown.bzl", "ANDROID_TEST_LOCKDOWN_GENERATOR_FUNCTIONS", "ANDROID_TEST_LOCKDOWN_TARGETS")
-load("//rules/acls:android_device_plugin_rollout.bzl", "ANDROID_DEVICE_PLUGIN_FALLBACK", "ANDROID_DEVICE_PLUGIN_ROLLOUT")
-load("//rules/acls:android_instrumentation_binary_starlark_resources.bzl", "ANDROID_INSTRUMENTATION_BINARY_STARLARK_RESOURCES_FALLBACK", "ANDROID_INSTRUMENTATION_BINARY_STARLARK_RESOURCES_ROLLOUT")
+load("//rules/acls:android_binary_min_sdk_version_attribute.bzl", "ANDROID_BINARY_MIN_SDK_VERSION_ATTRIBUTE_ALLOWLIST")
+load("//rules/acls:android_binary_raw_access_to_resource_paths_allowlist.bzl", "ANDROID_BINARY_RAW_ACCESS_TO_RESOURCE_PATHS_ALLOWLIST")
+load("//rules/acls:android_binary_resource_name_obfuscation_opt_out_allowlist.bzl", "ANDROID_BINARY_RESOURCE_NAME_OBFUSCATION_OPT_OUT_ALLOWLIST")
+load("//rules/acls:android_binary_starlark_dex_desugar_proguard.bzl", "ANDROID_BINARY_STARLARK_DEX_DESUGAR_PROGUARD_FALLBACK", "ANDROID_BINARY_STARLARK_DEX_DESUGAR_PROGUARD_ROLLOUT")
load("//rules/acls:android_binary_starlark_javac.bzl", "ANDROID_BINARY_STARLARK_JAVAC_FALLBACK", "ANDROID_BINARY_STARLARK_JAVAC_ROLLOUT")
load("//rules/acls:android_binary_starlark_split_transition.bzl", "ANDROID_BINARY_STARLARK_SPLIT_TRANSITION_FALLBACK", "ANDROID_BINARY_STARLARK_SPLIT_TRANSITION_ROLLOUT")
load("//rules/acls:android_binary_with_sandboxed_sdks_allowlist.bzl", "ANDROID_BINARY_WITH_SANDBOXED_SDKS_ALLOWLIST")
+load("//rules/acls:android_build_stamping_rollout.bzl", "ANDROID_BUILD_STAMPING_FALLBACK", "ANDROID_BUILD_STAMPING_ROLLOUT")
+load("//rules/acls:android_device_plugin_rollout.bzl", "ANDROID_DEVICE_PLUGIN_FALLBACK", "ANDROID_DEVICE_PLUGIN_ROLLOUT")
load("//rules/acls:android_feature_splits_dogfood.bzl", "ANDROID_FEATURE_SPLITS_DOGFOOD")
+load("//rules/acls:android_instrumentation_binary_starlark_resources.bzl", "ANDROID_INSTRUMENTATION_BINARY_STARLARK_RESOURCES_FALLBACK", "ANDROID_INSTRUMENTATION_BINARY_STARLARK_RESOURCES_ROLLOUT")
+load("//rules/acls:android_instrumentation_test_manifest_check_rollout.bzl", "ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_FALLBACK", "ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_ROLLOUT")
+load("//rules/acls:android_instrumentation_test_prebuilt_test_apk.bzl", "ANDROID_INSTRUMENTATION_TEST_PREBUILT_TEST_APK_FALLBACK", "ANDROID_INSTRUMENTATION_TEST_PREBUILT_TEST_APK_ROLLOUT")
load("//rules/acls:android_library_resources_without_srcs.bzl", "ANDROID_LIBRARY_RESOURCES_WITHOUT_SRCS", "ANDROID_LIBRARY_RESOURCES_WITHOUT_SRCS_GENERATOR_FUNCTIONS")
load("//rules/acls:android_library_starlark_resource_outputs.bzl", "ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_FALLBACK", "ANDROID_LIBRARY_STARLARK_RESOURCE_OUTPUTS_ROLLOUT")
load("//rules/acls:android_library_use_aosp_aidl_compiler.bzl", "ANDROID_LIBRARY_USE_AOSP_AIDL_COMPILER_ALLOWLIST")
load("//rules/acls:android_lint_checks_rollout.bzl", "ANDROID_LINT_CHECKS_FALLBACK", "ANDROID_LINT_CHECKS_ROLLOUT")
load("//rules/acls:android_lint_rollout.bzl", "ANDROID_LINT_FALLBACK", "ANDROID_LINT_ROLLOUT")
-load("//rules/acls:lint_registry_rollout.bzl", "LINT_REGISTRY_FALLBACK", "LINT_REGISTRY_ROLLOUT")
-load("//rules/acls:android_build_stamping_rollout.bzl", "ANDROID_BUILD_STAMPING_FALLBACK", "ANDROID_BUILD_STAMPING_ROLLOUT")
+load("//rules/acls:android_local_test_jdk_sts_rollout.bzl", "ANDROID_LOCAL_TEST_JDK_STS_FALLBACK", "ANDROID_LOCAL_TEST_JDK_STS_ROLLOUT")
+load("//rules/acls:android_test_lockdown.bzl", "ANDROID_TEST_LOCKDOWN_GENERATOR_FUNCTIONS", "ANDROID_TEST_LOCKDOWN_TARGETS")
+load("//rules/acls:android_test_platform_rollout.bzl", "ANDROID_TEST_PLATFORM_FALLBACK", "ANDROID_TEST_PLATFORM_ROLLOUT")
load("//rules/acls:b122039567.bzl", "B122039567")
load("//rules/acls:b123854163.bzl", "B123854163")
+load("//rules/acls:baseline_profiles_optimizer_integration.bzl", "BASELINE_PROFILES_OPTIMIZER_INTEGRATION")
+load("//rules/acls:baseline_profiles_rollout.bzl", "BASELINE_PROFILES_ROLLOUT")
load("//rules/acls:databinding.bzl", "DATABINDING_ALLOWED", "DATABINDING_DISALLOWED")
load("//rules/acls:dex2oat_opts.bzl", "CAN_USE_DEX2OAT_OPTIONS")
load("//rules/acls:fix_export_exporting_rollout.bzl", "FIX_EXPORT_EXPORTING_FALLBACK", "FIX_EXPORT_EXPORTING_ROLLOUT")
load("//rules/acls:fix_resource_transitivity_rollout.bzl", "FIX_RESOURCE_TRANSITIVITY_FALLBACK", "FIX_RESOURCE_TRANSITIVITY_ROLLOUT")
load("//rules/acls:host_dex2oat_rollout.bzl", "AIT_USE_HOST_DEX2OAT_ROLLOUT", "AIT_USE_HOST_DEX2OAT_ROLLOUT_FALLBACK")
load("//rules/acls:install_apps_in_data.bzl", "INSTALL_APPS_IN_DATA")
+load("//rules/acls:lint_registry_rollout.bzl", "LINT_REGISTRY_FALLBACK", "LINT_REGISTRY_ROLLOUT")
load("//rules/acls:local_test_multi_proto.bzl", "LOCAL_TEST_MULTI_PROTO_PKG")
load("//rules/acls:local_test_rollout.bzl", "LOCAL_TEST_FALLBACK", "LOCAL_TEST_ROLLOUT")
load("//rules/acls:local_test_starlark_resources.bzl", "LOCAL_TEST_STARLARK_RESOURCES_FALLBACK", "LOCAL_TEST_STARLARK_RESOURCES_ROLLOUT")
-load("//rules/acls:android_test_platform_rollout.bzl", "ANDROID_TEST_PLATFORM_FALLBACK", "ANDROID_TEST_PLATFORM_ROLLOUT")
-load("//rules/acls:test_to_instrument_test_rollout.bzl", "TEST_TO_INSTRUMENT_TEST_FALLBACK", "TEST_TO_INSTRUMENT_TEST_ROLLOUT")
+load("//rules/acls:min_sdk_floors.bzl", "MIN_SDK_FLOORS")
load(
"//rules/acls:partial_jetification_targets.bzl",
"PARTIAL_JETIFICATION_TARGETS_FALLBACK",
"PARTIAL_JETIFICATION_TARGETS_ROLLOUT",
)
-load("//rules/acls:android_instrumentation_test_manifest_check_rollout.bzl", "ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_FALLBACK", "ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_ROLLOUT")
-load("//rules/acls:android_instrumentation_test_prebuilt_test_apk.bzl", "ANDROID_INSTRUMENTATION_TEST_PREBUILT_TEST_APK_FALLBACK", "ANDROID_INSTRUMENTATION_TEST_PREBUILT_TEST_APK_ROLLOUT")
-load("//rules/acls:baseline_profiles_rollout.bzl", "BASELINE_PROFILES_ROLLOUT")
-load("//rules/acls:baseline_profiles_optimizer_integration.bzl", "BASELINE_PROFILES_OPTIMIZER_INTEGRATION")
-load("//rules/acls:enforce_min_sdk_floor_rollout.bzl", "ENFORCE_MIN_SDK_FLOOR_FALLBACK", "ENFORCE_MIN_SDK_FLOOR_ROLLOUT")
-load("//rules/acls:android_apk_to_bundle_features_lockdown.bzl", "ANDROID_APK_TO_BUNDLE_FEATURES")
-load("//rules/acls:android_local_test_jdk_sts_rollout.bzl", "ANDROID_LOCAL_TEST_JDK_STS_FALLBACK", "ANDROID_LOCAL_TEST_JDK_STS_ROLLOUT")
-load("//rules/acls:shared_library_resource_linking.bzl", "SHARED_LIBRARY_RESOURCE_LINKING_ALLOWLIST")
-load("//rules/acls:android_binary_starlark_dex_desugar_proguard.bzl", "ANDROID_BINARY_STARLARK_DEX_DESUGAR_PROGUARD_FALLBACK", "ANDROID_BINARY_STARLARK_DEX_DESUGAR_PROGUARD_ROLLOUT")
-load("//rules/acls:android_binary_min_sdk_version_attribute.bzl", "ANDROID_BINARY_MIN_SDK_VERSION_ATTRIBUTE_ALLOWLIST")
-load("//rules/acls:android_binary_raw_access_to_resource_paths_allowlist.bzl", "ANDROID_BINARY_RAW_ACCESS_TO_RESOURCE_PATHS_ALLOWLIST")
-load("//rules/acls:android_binary_resource_name_obfuscation_opt_out_allowlist.bzl", "ANDROID_BINARY_RESOURCE_NAME_OBFUSCATION_OPT_OUT_ALLOWLIST")
load("//rules/acls:proguard_apply_mapping.bzl", "ALLOW_PROGUARD_APPLY_MAPPING")
load("//rules/acls:r8.bzl", "USE_R8")
+load("//rules/acls:shared_library_resource_linking.bzl", "SHARED_LIBRARY_RESOURCE_LINKING_ALLOWLIST")
+load("//rules/acls:test_to_instrument_test_rollout.bzl", "TEST_TO_INSTRUMENT_TEST_FALLBACK", "TEST_TO_INSTRUMENT_TEST_ROLLOUT")
+
+def _get_min_sdk_floor(fqn):
+ for minsdk, package_dict in MIN_SDK_FLOORS_DICT.items():
+ if matches(fqn, package_dict):
+ return minsdk
+ fail("No matching min_sdk_floor for %s" % fqn)
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)
@@ -213,9 +219,6 @@ def _in_baseline_profiles_rollout(fqn):
def _in_baseline_profiles_optimizer_integration(fqn):
return matches(fqn, BASELINE_PROFILES_OPTIMIZER_INTEGRATION)
-def _in_enforce_min_sdk_floor_rollout(fqn):
- return not matches(fqn, ENFORCE_MIN_SDK_FLOOR_FALLBACK_DICT) and matches(fqn, ENFORCE_MIN_SDK_FLOOR_ROLLOUT_DICT)
-
def _in_android_apk_to_bundle_features(fqn):
return matches(fqn, ANDROID_APK_TO_BUNDLE_FEATURES_DICT)
@@ -250,6 +253,12 @@ def make_dict(lst):
"""Do not use this method outside of acls directory."""
return {t: True for t in lst}
+def make_min_sdk_dict(dict_of_lists):
+ res = {}
+ for k in dict_of_lists.keys():
+ res[k] = make_dict(dict_of_lists[k])
+ return res
+
AAR_IMPORT_DEPS_CHECKER_FALLBACK_DICT = make_dict(AAR_IMPORT_DEPS_CHECKER_FALLBACK)
AAR_IMPORT_DEPS_CHECKER_ROLLOUT_DICT = make_dict(AAR_IMPORT_DEPS_CHECKER_ROLLOUT)
AAR_IMPORT_EXPLICIT_EXPORTS_MANIFEST_DICT = make_dict(AAR_IMPORT_EXPLICIT_EXPORTS_MANIFEST)
@@ -313,8 +322,7 @@ ANDROID_INSTRUMENTATION_TEST_PREBUILT_TEST_APK_ROLLOUT_DICT = make_dict(ANDROID_
ANDROID_INSTRUMENTATION_TEST_PREBUILT_TEST_APK_FALLBACK_DICT = make_dict(ANDROID_INSTRUMENTATION_TEST_PREBUILT_TEST_APK_FALLBACK)
BASELINE_PROFILES_ROLLOUT_DICT = make_dict(BASELINE_PROFILES_ROLLOUT)
BASELINE_PROFILES_OPTIMIZER_INTEGRATION_DICT = make_dict(BASELINE_PROFILES_OPTIMIZER_INTEGRATION)
-ENFORCE_MIN_SDK_FLOOR_ROLLOUT_DICT = make_dict(ENFORCE_MIN_SDK_FLOOR_ROLLOUT)
-ENFORCE_MIN_SDK_FLOOR_FALLBACK_DICT = make_dict(ENFORCE_MIN_SDK_FLOOR_FALLBACK)
+MIN_SDK_FLOORS_DICT = make_min_sdk_dict(MIN_SDK_FLOORS)
ANDROID_APK_TO_BUNDLE_FEATURES_DICT = make_dict(ANDROID_APK_TO_BUNDLE_FEATURES)
ANDROID_LIBRARY_USE_AOSP_AIDL_COMPILER_ALLOWLIST_DICT = make_dict(ANDROID_LIBRARY_USE_AOSP_AIDL_COMPILER_ALLOWLIST)
ANDROID_LOCAL_TEST_JDK_STS_FALLBACK_DICT = make_dict(ANDROID_LOCAL_TEST_JDK_STS_FALLBACK)
@@ -371,6 +379,7 @@ def matches(fqn, dct):
acls = struct(
get_android_archive_duplicate_class_allowlist = _get_android_archive_duplicate_class_allowlist,
get_android_archive_exposed_package_allowlist = _get_android_archive_exposed_package_allowlist,
+ get_min_sdk_floor = _get_min_sdk_floor,
in_aar_import_deps_checker = _in_aar_import_deps_checker,
in_aar_import_explicit_exports_manifest = _in_aar_import_explicit_exports_manifest,
in_aar_import_exports_r_java = _in_aar_import_exports_r_java,
@@ -412,7 +421,6 @@ acls = struct(
in_android_instrumentation_test_prebuilt_test_apk = _in_android_instrumentation_test_prebuilt_test_apk,
in_baseline_profiles_rollout = _in_baseline_profiles_rollout,
in_baseline_profiles_optimizer_integration = _in_baseline_profiles_optimizer_integration,
- in_enforce_min_sdk_floor_rollout = _in_enforce_min_sdk_floor_rollout,
in_android_apk_to_bundle_features = _in_android_apk_to_bundle_features,
in_android_local_test_jdk_sts_rollout = _in_android_local_test_jdk_sts_rollout,
in_shared_library_resource_linking_allowlist = _in_shared_library_resource_linking_allowlist,
diff --git a/rules/acls/enforce_min_sdk_floor_rollout.bzl b/rules/acls/min_sdk_floors.bzl
index 94643eb..4dfe044 100644
--- a/rules/acls/enforce_min_sdk_floor_rollout.bzl
+++ b/rules/acls/min_sdk_floors.bzl
@@ -1,4 +1,4 @@
-# Copyright 2022 The Bazel Authors. All rights reserved.
+# Copyright 2023 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.
@@ -12,11 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-"""Rollout list for enabling enforce min SDK floor."""
+"""Mapping of minSdkVersion floors to packages.
-ENFORCE_MIN_SDK_FLOOR_ROLLOUT = [
- "//:__subpackages__",
-]
+Starlark dictionaries maintain insertion order. It is expected that the union of all lists will
+cover the entire depot.
+"""
-ENFORCE_MIN_SDK_FLOOR_FALLBACK = [
-]
+MIN_SDK_FLOORS = {
+ 19: [
+ "//:__subpackages__",
+ ],
+ 14: [
+ "//:__subpackages__",
+ ],
+}
diff --git a/rules/android_application/android_application_rule.bzl b/rules/android_application/android_application_rule.bzl
index a2c9b70..d7c15c2 100644
--- a/rules/android_application/android_application_rule.bzl
+++ b/rules/android_application/android_application_rule.bzl
@@ -261,8 +261,8 @@ def _impl(ctx):
ctx,
out = module,
proto_apk = proto_apk,
- unzip = get_android_toolchain(ctx).unzip_tool.files_to_run,
- zip = get_android_toolchain(ctx).zip_tool.files_to_run,
+ bundletool_module_builder =
+ get_android_toolchain(ctx).bundletool_module_builder.files_to_run,
)
metadata = dict()
diff --git a/rules/android_binary_internal/attrs.bzl b/rules/android_binary_internal/attrs.bzl
index 9a2df04..e09f3e1 100644
--- a/rules/android_binary_internal/attrs.bzl
+++ b/rules/android_binary_internal/attrs.bzl
@@ -14,16 +14,17 @@
"""Attributes."""
+load("//rules:android_neverlink_aspect.bzl", "android_neverlink_aspect")
load(
"//rules:attrs.bzl",
_attrs = "attrs",
)
+load("//rules:dex_desugar_aspect.bzl", "dex_desugar_aspect")
load(
"//rules:native_deps.bzl",
"split_config_aspect",
)
load("//rules:providers.bzl", "StarlarkApkInfo")
-load("//rules:dex_desugar_aspect.bzl", "dex_desugar_aspect")
def make_deps(allow_rules, providers, aspects):
return attr.label_list(
@@ -51,6 +52,7 @@ DEPS_PROVIDERS = [
DEPS_ASPECTS = [
dex_desugar_aspect,
+ android_neverlink_aspect,
]
ATTRS = _attrs.replace(
diff --git a/rules/android_binary_internal/impl.bzl b/rules/android_binary_internal/impl.bzl
index a1e42df..0c156de 100644
--- a/rules/android_binary_internal/impl.bzl
+++ b/rules/android_binary_internal/impl.bzl
@@ -31,7 +31,7 @@ load(
"ProviderInfo",
"processing_pipeline",
)
-load("//rules:proguard.bzl", "proguard", proguard_testing = "testing")
+load("//rules:proguard.bzl", "proguard")
load("//rules:providers.bzl", "StarlarkAndroidDexInfo", "StarlarkApkInfo")
load("//rules:resources.bzl", _resources = "resources")
load(
@@ -53,7 +53,7 @@ def _process_manifest(ctx, **unused_ctxs):
ctx,
manifest = ctx.file.manifest,
manifest_values = ctx.attr.manifest_values,
- floor = _resources.DEPOT_MIN_SDK_FLOOR if (_is_test_binary(ctx) and acls.in_enforce_min_sdk_floor_rollout(str(ctx.label))) else 0,
+ floor = acls.get_min_sdk_floor(str(ctx.label)) if _is_test_binary(ctx) else 0,
enforce_min_sdk_floor_tool = get_android_toolchain(ctx).enforce_min_sdk_floor_tool.files_to_run,
)
@@ -109,7 +109,7 @@ def _validate_manifest(ctx, packaged_resources_ctx, **unused_ctxs):
manifest_validation_ctx = _resources.validate_min_sdk(
ctx,
manifest = packaged_resources_ctx.processed_manifest,
- floor = _resources.DEPOT_MIN_SDK_FLOOR if acls.in_enforce_min_sdk_floor_rollout(str(ctx.label)) else 0,
+ floor = acls.get_min_sdk_floor(str(ctx.label)),
enforce_min_sdk_floor_tool = get_android_toolchain(ctx).enforce_min_sdk_floor_tool.files_to_run,
)
@@ -260,7 +260,7 @@ def _process_dex(ctx, stamp_ctx, packaged_resources_ctx, jvm_ctx, proto_ctx, dep
main_dex_classes = get_android_sdk(ctx).main_dex_classes,
main_dex_list_opts = ctx.attr.main_dex_list_opts,
main_dex_proguard_spec = packaged_resources_ctx.main_dex_proguard_config,
- proguard_specs = list(ctx.attr.main_dex_proguard_specs),
+ proguard_specs = list(ctx.files.main_dex_proguard_specs),
shrinked_android_jar = get_android_sdk(ctx).shrinked_android_jar,
main_dex_list_creator = get_android_sdk(ctx).main_dex_list_creator,
legacy_main_dex_list_generator =
@@ -389,11 +389,16 @@ def _process_dex(ctx, stamp_ctx, packaged_resources_ctx, jvm_ctx, proto_ctx, dep
dex_info = AndroidDexInfo(
deploy_jar = deploy_jar,
+ filtered_deploy_jar = deploy_ctx.filtered_deploy_jar,
final_classes_dex_zip = final_classes_dex_zip,
final_proguard_output_map = final_proguard_output_map,
- java_resource_jar = deploy_jar,
+ java_resource_jar = binary_jar if ctx.fragments.android.get_java_resources_from_optimized_jar else deploy_jar,
)
providers.append(dex_info)
+ providers.append(AndroidPreDexJarInfo(binary_jar))
+
+ if postprocessing_output_map:
+ providers.append(ProguardMappingInfo(postprocessing_output_map))
return ProviderInfo(
name = "dex_ctx",
@@ -405,7 +410,7 @@ def _process_dex(ctx, stamp_ctx, packaged_resources_ctx, jvm_ctx, proto_ctx, dep
)
def _process_deploy_jar(ctx, stamp_ctx, packaged_resources_ctx, jvm_ctx, build_info_ctx, proto_ctx, **_unused_ctxs):
- deploy_jar, desugar_dict = None, {}
+ deploy_jar, filtered_deploy_jar, desugar_dict = None, None, {}
if acls.in_android_binary_starlark_dex_desugar_proguard(str(ctx.label)):
java_toolchain = common.get_java_toolchain(ctx)
@@ -456,7 +461,9 @@ def _process_deploy_jar(ctx, stamp_ctx, packaged_resources_ctx, jvm_ctx, build_i
if _is_instrumentation(ctx):
filtered_deploy_jar = ctx.actions.declare_file(ctx.label.name + "_migrated_filtered.jar")
- filter_jar = ctx.attr.instruments[AndroidPreDexJarInfo].pre_dex_jar
+
+ # TODO(b/303286042): Use AndroidPreDexInfo.pre_dex_jar to be the filter_jar
+ filter_jar = ctx.attr.instruments[ApkInfo].deploy_jar
common.filter_zip_exclude(
ctx,
output = filtered_deploy_jar,
@@ -474,6 +481,7 @@ def _process_deploy_jar(ctx, stamp_ctx, packaged_resources_ctx, jvm_ctx, build_i
value = struct(
deploy_jar = deploy_jar,
desugar_dict = desugar_dict,
+ filtered_deploy_jar = filtered_deploy_jar,
providers = [],
),
)
@@ -639,7 +647,7 @@ def _process_optimize(ctx, deploy_ctx, packaged_resources_ctx, bp_ctx, **_unused
)
# Validate attributes and lockdown lists
- if ctx.file.proguard_apply_mapping and not acls.in_allow_proguard_apply_mapping(ctx.label):
+ if ctx.file.proguard_apply_mapping and not acls.in_allow_proguard_apply_mapping(str(ctx.label)):
fail("proguard_apply_mapping is not supported")
if ctx.file.proguard_apply_mapping and not ctx.files.proguard_specs:
fail("proguard_apply_mapping can only be used when proguard_specs is set")
@@ -650,7 +658,6 @@ def _process_optimize(ctx, deploy_ctx, packaged_resources_ctx, bp_ctx, **_unused
proguard_specs_for_manifest = [packaged_resources_ctx.resource_minsdk_proguard_config] if packaged_resources_ctx.resource_minsdk_proguard_config else [],
)
has_proguard_specs = bool(proguard_specs)
- proguard_output = struct()
is_resource_shrinking_enabled = _resources.is_resource_shrinking_enabled(
ctx.attr.shrink_resources,
@@ -684,8 +691,11 @@ def _process_optimize(ctx, deploy_ctx, packaged_resources_ctx, bp_ctx, **_unused
proguard_seeds = ctx.actions.declare_file(ctx.label.name + "_migrated_proguard.seeds")
proguard_usage = ctx.actions.declare_file(ctx.label.name + "_migrated_proguard.usage")
- startup_profile = bp_ctx.baseline_profile_output.startup_profile if bp_ctx.baseline_profile_output else None
- baseline_profile = bp_ctx.baseline_profile_output.baseline_profile if bp_ctx.baseline_profile_output else None
+ startup_profile = None
+ baseline_profile = None
+ if acls.in_baseline_profiles_optimizer_integration(str(ctx.label)) and bp_ctx.baseline_profile_output:
+ startup_profile = bp_ctx.baseline_profile_output.startup_profile
+ baseline_profile = bp_ctx.baseline_profile_output.baseline_profile
proguard_output = proguard.apply_proguard(
ctx,
@@ -702,20 +712,6 @@ def _process_optimize(ctx, deploy_ctx, packaged_resources_ctx, bp_ctx, **_unused
proguard_tool = get_android_sdk(ctx).proguard,
)
- providers = []
- if proguard_output:
- providers.append(proguard_testing.ProguardOutputInfo(
- input_jar = deploy_ctx.deploy_jar,
- output_jar = proguard_output.output_jar,
- mapping = proguard_output.mapping,
- seeds = proguard_output.seeds,
- usage = proguard_output.usage,
- library_jar = proguard_output.library_jar,
- config = proguard_output.config,
- baseline_profile_rewritten = proguard_output.baseline_profile_rewritten,
- startup_profile_rewritten = proguard_output.startup_profile_rewritten,
- ))
-
use_resource_shrinking = is_resource_shrinking_enabled and has_proguard_specs
shrunk_resource_output = None
if use_resource_shrinking:
@@ -730,7 +726,6 @@ def _process_optimize(ctx, deploy_ctx, packaged_resources_ctx, bp_ctx, **_unused
busybox = get_android_toolchain(ctx).android_resources_busybox.files_to_run,
host_javabase = common.get_host_javabase(ctx),
)
- providers.append(shrunk_resource_output)
optimized_resource_output = _resources.optimize(
ctx,
@@ -741,7 +736,26 @@ def _process_optimize(ctx, deploy_ctx, packaged_resources_ctx, bp_ctx, **_unused
busybox = get_android_toolchain(ctx).android_resources_busybox.files_to_run,
host_javabase = common.get_host_javabase(ctx),
)
- providers.append(optimized_resource_output)
+
+ providers = []
+ providers.append(
+ AndroidOptimizationInfo(
+ optimized_jar = proguard_output.output_jar,
+ mapping = proguard_output.mapping,
+ seeds = proguard_output.seeds,
+ library_jar = proguard_output.library_jar,
+ config = proguard_output.config,
+ proto_mapping = proguard_output.proto_mapping,
+ rewritten_startup_profile = proguard_output.startup_profile_rewritten,
+ rewriten_merged_baseline_profile = proguard_output.baseline_profile_rewritten,
+ optimized_resource_apk = optimized_resource_output.resources_apk,
+ shrunk_resource_apk = shrunk_resource_output.resources_apk if shrunk_resource_output else None,
+ shrunk_resource_zip = shrunk_resource_output.resources_zip if shrunk_resource_output else None,
+ resource_shrinker_log = shrunk_resource_output.shrinker_log if shrunk_resource_output else None,
+ resource_optimization_config = shrunk_resource_output.optimization_config if shrunk_resource_output else None,
+ resource_path_shortening_map = optimized_resource_output.path_shortening_map,
+ ),
+ )
return ProviderInfo(
name = "optimize_ctx",
diff --git a/rules/android_binary_internal/r8.bzl b/rules/android_binary_internal/r8.bzl
index 90c91c3..0ace549 100644
--- a/rules/android_binary_internal/r8.bzl
+++ b/rules/android_binary_internal/r8.bzl
@@ -92,6 +92,7 @@ def process_r8(ctx, jvm_ctx, packaged_resources_ctx, build_info_ctx, **_unused_c
inputs = [android_jar, deploy_jar] + proguard_specs,
outputs = [dexes_zip],
mnemonic = "AndroidR8",
+ jvm_flags = ["-Xmx8G"],
progress_message = "R8 Optimizing, Desugaring, and Dexing %{label}",
)
diff --git a/rules/android_library/impl.bzl b/rules/android_library/impl.bzl
index 5fd5af5..6ccc5a5 100644
--- a/rules/android_library/impl.bzl
+++ b/rules/android_library/impl.bzl
@@ -133,7 +133,7 @@ def _process_manifest(ctx, **unused_ctxs):
manifest_ctx = _resources.bump_min_sdk(
ctx,
manifest = ctx.file.manifest,
- floor = _resources.DEPOT_MIN_SDK_FLOOR if acls.in_enforce_min_sdk_floor_rollout(str(ctx.label)) else 0,
+ floor = acls.get_min_sdk_floor(str(ctx.label)),
enforce_min_sdk_floor_tool = get_android_toolchain(ctx).enforce_min_sdk_floor_tool.files_to_run,
)
diff --git a/rules/android_library/rule.bzl b/rules/android_library/rule.bzl
index e36bdd3..cd7af67 100644
--- a/rules/android_library/rule.bzl
+++ b/rules/android_library/rule.bzl
@@ -140,7 +140,8 @@ def make_rule(
attrs = _ATTRS,
implementation = _impl,
outputs = _outputs,
- additional_toolchains = []):
+ additional_toolchains = [],
+ additional_providers = []):
"""Makes the rule.
Args:
@@ -148,6 +149,7 @@ def make_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).
+ additional_providers: A list. Additional providers passed to pass to rule(providers).
Returns:
A rule.
@@ -167,7 +169,7 @@ def make_rule(
AndroidLibraryResourceClassJarProvider,
AndroidNativeLibsInfo,
JavaInfo,
- ],
+ ] + additional_providers,
outputs = outputs,
toolchains = [
"//toolchains/android:toolchain_type",
diff --git a/rules/android_local_test/impl.bzl b/rules/android_local_test/impl.bzl
index 1606e18..3a6221f 100644
--- a/rules/android_local_test/impl.bzl
+++ b/rules/android_local_test/impl.bzl
@@ -61,7 +61,7 @@ def _process_manifest(ctx, java_package, **_unused_sub_ctxs):
manifest_values = resources.process_manifest_values(
ctx,
ctx.attr.manifest_values,
- resources.DEPOT_MIN_SDK_FLOOR,
+ acls.get_min_sdk_floor(str(ctx.label)),
)
if ctx.file.manifest == None:
# No manifest provided, generate one
@@ -70,7 +70,7 @@ def _process_manifest(ctx, java_package, **_unused_sub_ctxs):
ctx,
out_manifest = manifest,
java_package = java_package,
- min_sdk_version = manifest_values.get("minSdkVersion", 16), # minsdk supported by robolectric framework
+ min_sdk_version = int(manifest_values.get("minSdkVersion", 16)), # minsdk supported by robolectric framework
)
manifest_ctx = struct(processed_manifest = manifest, processed_manifest_values = manifest_values)
else:
@@ -78,7 +78,7 @@ def _process_manifest(ctx, java_package, **_unused_sub_ctxs):
ctx,
manifest = ctx.file.manifest,
manifest_values = ctx.attr.manifest_values,
- floor = resources.DEPOT_MIN_SDK_FLOOR if acls.in_enforce_min_sdk_floor_rollout(str(ctx.label)) else 0,
+ floor = acls.get_min_sdk_floor(str(ctx.label)),
enforce_min_sdk_floor_tool = get_android_toolchain(ctx).enforce_min_sdk_floor_tool.files_to_run,
)
diff --git a/rules/android_neverlink_aspect.bzl b/rules/android_neverlink_aspect.bzl
index 1dab304..672bd3a 100644
--- a/rules/android_neverlink_aspect.bzl
+++ b/rules/android_neverlink_aspect.bzl
@@ -18,6 +18,7 @@ Used for determining the -libraryjars argument for Proguard. The compile-time cl
unsufficient here as those are ijars.
"""
+load("//rules:acls.bzl", "acls")
load(
"//rules:utils.bzl",
"utils",
@@ -33,6 +34,9 @@ StarlarkAndroidNeverlinkInfo = provider(
_ATTRS = ["deps", "exports", "runtime_deps", "binary_under_test", "$instrumentation_test_runner"]
def _android_neverlink_aspect_impl(target, ctx):
+ if not acls.in_android_binary_starlark_dex_desugar_proguard(str(ctx.label)):
+ return []
+
# Only run on Android targets
if "android" not in getattr(ctx.rule.attr, "constraints", "") and not ctx.rule.kind.startswith("android_"):
return []
diff --git a/rules/android_sandboxed_sdk/android_binary_with_sandboxed_sdks_macro.bzl b/rules/android_sandboxed_sdk/android_binary_with_sandboxed_sdks_macro.bzl
index 95b8b80..1499e98 100644
--- a/rules/android_sandboxed_sdk/android_binary_with_sandboxed_sdks_macro.bzl
+++ b/rules/android_sandboxed_sdk/android_binary_with_sandboxed_sdks_macro.bzl
@@ -14,19 +14,20 @@
"""Bazel rule for defining an Android binary that depends on sandboxed SDKs."""
-load(":providers.bzl", "AndroidSandboxedSdkBundleInfo")
load("//rules:acls.bzl", "acls")
load("//rules:bundletool.bzl", _bundletool = "bundletool")
load("//rules:common.bzl", _common = "common")
-load(
- "//rules:utils.bzl",
- _get_android_toolchain = "get_android_toolchain",
-)
load("//rules:java.bzl", _java = "java")
load(
"//rules:sandboxed_sdk_toolbox.bzl",
_sandboxed_sdk_toolbox = "sandboxed_sdk_toolbox",
)
+load(
+ "//rules:utils.bzl",
+ "utils",
+ _get_android_toolchain = "get_android_toolchain",
+)
+load(":providers.bzl", "AndroidArchivedSandboxedSdkInfo", "AndroidSandboxedSdkBundleInfo")
def _gen_sdk_dependencies_manifest_impl(ctx):
manifest = ctx.actions.declare_file(ctx.label.name + "_sdk_dep_manifest.xml")
@@ -34,12 +35,17 @@ def _gen_sdk_dependencies_manifest_impl(ctx):
bundle[AndroidSandboxedSdkBundleInfo].sdk_info.sdk_module_config
for bundle in ctx.attr.sdk_bundles
]
+ sdk_archives = [
+ archive[AndroidArchivedSandboxedSdkInfo].asar
+ for archive in ctx.attr.sdk_archives
+ ]
_sandboxed_sdk_toolbox.generate_sdk_dependencies_manifest(
ctx,
output = manifest,
manifest_package = ctx.attr.package,
sdk_module_configs = module_configs,
+ sdk_archives = sdk_archives,
debug_key = ctx.file.debug_key,
sandboxed_sdk_toolbox = _get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run,
host_javabase = _common.get_host_javabase(ctx),
@@ -59,6 +65,11 @@ _gen_sdk_dependencies_manifest = rule(
[AndroidSandboxedSdkBundleInfo],
],
),
+ sdk_archives = attr.label_list(
+ providers = [
+ [AndroidArchivedSandboxedSdkInfo],
+ ],
+ ),
debug_key = attr.label(
allow_single_file = True,
default = Label("//tools/android:debug_keystore"),
@@ -78,8 +89,34 @@ _gen_sdk_dependencies_manifest = rule(
def _android_binary_with_sandboxed_sdks_impl(ctx):
sdk_apks = []
+ for idx, sdk_archive in enumerate(ctx.attr.sdk_archives):
+ # Bundletool is rejecting ASARs when creating APKs, but since the formats are similar enough
+ # for this command we can just rename the file.
+ # TODO b/294970460) -- Remove this extra copy once Bundletool is updated with ASAR support
+ # in build_sdk_apks. Their work is being tracked in b/228176834.
+ renamed_sdk_archive = ctx.actions.declare_file("%s/renamed_sdk_archive/%s.asb" % (
+ ctx.label.name,
+ idx,
+ ))
+ utils.copy_file(ctx, sdk_archive[AndroidArchivedSandboxedSdkInfo].asar, renamed_sdk_archive)
+
+ apk_out = ctx.actions.declare_file("%s/sdk_archive_dep_apks/%s.apk" % (
+ ctx.label.name,
+ idx,
+ ))
+ _bundletool.build_sdk_apks(
+ ctx,
+ out = apk_out,
+ aapt2 = _get_android_toolchain(ctx).aapt2.files_to_run,
+ sdk_bundle = renamed_sdk_archive,
+ debug_key = ctx.file.debug_key,
+ bundletool = _get_android_toolchain(ctx).bundletool.files_to_run,
+ host_javabase = _common.get_host_javabase(ctx),
+ )
+ sdk_apks.append(apk_out)
+
for idx, sdk_bundle_target in enumerate(ctx.attr.sdk_bundles):
- apk_out = ctx.actions.declare_file("%s/sdk_dep_apks/%s.apk" % (
+ apk_out = ctx.actions.declare_file("%s/sdk_bundle_dep_apks/%s.apk" % (
ctx.label.name,
idx,
))
@@ -137,6 +174,11 @@ _android_binary_with_sandboxed_sdks = rule(
[AndroidSandboxedSdkBundleInfo],
],
),
+ sdk_archives = attr.label_list(
+ providers = [
+ [AndroidArchivedSandboxedSdkInfo],
+ ],
+ ),
_install_script_template = attr.label(
allow_single_file = True,
default = ":install_script.sh_template",
@@ -150,6 +192,7 @@ _android_binary_with_sandboxed_sdks = rule(
implementation = _android_binary_with_sandboxed_sdks_impl,
toolchains = [
"//toolchains/android:toolchain_type",
+ "@bazel_tools//tools/jdk:toolchain_type",
],
)
@@ -171,7 +214,8 @@ def android_binary_with_sandboxed_sdks_macro(
fail("%s is not allowed to use the android_binary_with_sandboxed_sdks macro." %
fully_qualified_name)
- sdk_bundles = attrs.pop("sdk_bundles", None)
+ sdk_bundles = attrs.pop("sdk_bundles", [])
+ sdk_archives = attrs.pop("sdk_archives", [])
debug_keystore = getattr(attrs, "debug_keystore", None)
bin_package = _java.resolve_package_from_label(
@@ -185,6 +229,10 @@ def android_binary_with_sandboxed_sdks_macro(
name = sdk_dependencies_manifest_name,
package = "%s.internalsdkdependencies" % bin_package,
sdk_bundles = sdk_bundles,
+ sdk_archives = sdk_archives,
+ testonly = attrs.get("testonly", False),
+ tags = attrs.get("tags", []),
+ visibility = attrs.get("visibility", None),
)
# Use the manifest in a normal android_library. This will later be added as a dependency to the
@@ -194,6 +242,10 @@ def android_binary_with_sandboxed_sdks_macro(
name = sdk_dependencies_lib_name,
exports_manifest = 1,
manifest = ":%s" % sdk_dependencies_manifest_name,
+ testonly = attrs.get("testonly", False),
+ tags = attrs.get("tags", []),
+ transitive_configs = attrs.get("transitive_configs", []),
+ visibility = attrs.get("visibility", None),
)
deps = attrs.pop("deps", [])
deps.append(":%s" % sdk_dependencies_lib_name)
@@ -210,6 +262,10 @@ def android_binary_with_sandboxed_sdks_macro(
_android_binary_with_sandboxed_sdks(
name = name,
sdk_bundles = sdk_bundles,
+ sdk_archives = sdk_archives,
debug_key = debug_keystore,
internal_android_binary = bin_label,
+ testonly = attrs.get("testonly", False),
+ tags = attrs.get("tags", []),
+ visibility = attrs.get("visibility", None),
)
diff --git a/rules/android_sdk_repository/helper.bzl b/rules/android_sdk_repository/helper.bzl
index 43f715f..3a2eba4 100644
--- a/rules/android_sdk_repository/helper.bzl
+++ b/rules/android_sdk_repository/helper.bzl
@@ -235,6 +235,8 @@ def create_android_sdk_rules(
],
)
+ create_dummy_sdk_toolchain()
+
native.alias(
name = "org_apache_http_legacy",
actual = ":org_apache_http_legacy-%d" % default_api_level,
@@ -504,4 +506,45 @@ def create_system_images_filegroups(system_image_dirs):
native.filegroup(
name = "%s_qemu2_extra" % name,
srcs = [],
- )
+ ) # buildifier: disable=unnamed-macro
+
+# This is a dummy sdk toolchain that matches any platform. It will
+# fail if actually resolved to and used.
+# buildifier: disable=unnamed-macro
+def create_dummy_sdk_toolchain():
+ "Create a dummy SDK for fallback builds"
+
+ native.toolchain(
+ name = "sdk-dummy-toolchain",
+ toolchain = ":sdk-dummy",
+ toolchain_type = "@bazel_tools//tools/android:sdk_toolchain_type",
+ )
+
+ native.filegroup(name = "jar-filegroup", srcs = ["dummy.jar"])
+
+ native.genrule(
+ name = "genrule",
+ srcs = [],
+ outs = ["empty.sh"],
+ cmd = "echo '' >> \"$@\"",
+ executable = 1,
+ )
+
+ native.sh_binary(name = "empty-binary", srcs = [":genrule"])
+
+ native.android_sdk(
+ name = "sdk-dummy",
+ aapt = ":empty-binary",
+ adb = ":empty-binary",
+ aidl = ":empty-binary",
+ android_jar = ":jar-filegroup",
+ apksigner = ":empty-binary",
+ dx = ":empty-binary",
+ framework_aidl = "dummy.jar",
+ main_dex_classes = "dummy.jar",
+ main_dex_list_creator = ":empty-binary",
+ proguard = ":empty-binary",
+ shrinked_android_jar = "dummy.jar",
+ tags = ["__ANDROID_RULES_MIGRATION__"],
+ zipalign = ":empty-binary",
+ )
diff --git a/rules/attrs.bzl b/rules/attrs.bzl
index 6a03d2d..a72fd4f 100644
--- a/rules/attrs.bzl
+++ b/rules/attrs.bzl
@@ -267,6 +267,12 @@ ANDROID_SDK_ATTRS = dict(
mandatory = True,
),
build_tools_version = attr.string(),
+ dexdump = attr.label(
+ allow_files = True,
+ cfg = "exec",
+ executable = True,
+ mandatory = False,
+ ),
dx = attr.label(
allow_files = True,
cfg = "exec",
diff --git a/rules/bundletool.bzl b/rules/bundletool.bzl
index b0651ec..a933211 100644
--- a/rules/bundletool.bzl
+++ b/rules/bundletool.bzl
@@ -322,71 +322,17 @@ def _proto_apk_to_module(
ctx,
out = None,
proto_apk = None,
- zip = None,
- unzip = None):
- # TODO(timpeut): migrate this to Bundletool module builder.
- ctx.actions.run_shell(
- command = """
-set -e
-
-IN_DIR=$(mktemp -d)
-OUT_DIR=$(mktemp -d)
-CUR_PWD=$(pwd)
-UNZIP=%s
-ZIP=%s
-INPUT=%s
-OUTPUT=%s
-
-"${UNZIP}" -qq "${INPUT}" -d "${IN_DIR}"
-cd "${IN_DIR}"
-
-if [ -f resources.pb ]; then
- mv resources.pb "${OUT_DIR}/"
-fi
-
-if [ -f AndroidManifest.xml ]; then
- mkdir "${OUT_DIR}/manifest"
- mv AndroidManifest.xml "${OUT_DIR}/manifest/"
-fi
-
-NUM_DEX=`ls -1 *.dex 2>/dev/null | wc -l`
-if [ $NUM_DEX != 0 ]; then
- mkdir "${OUT_DIR}/dex"
- mv *.dex "${OUT_DIR}/dex/"
-fi
-
-if [ -d res ]; then
- mv res "${OUT_DIR}/res"
-fi
-
-if [ -d assets ]; then
- mv assets "${OUT_DIR}/"
-fi
-
-if [ -d lib ]; then
- mv lib "${OUT_DIR}/"
-fi
-
-UNKNOWN=`ls -1 * 2>/dev/null | wc -l`
-if [ $UNKNOWN != 0 ]; then
- mkdir "${OUT_DIR}/root"
- mv * "${OUT_DIR}/root/"
-fi
-
-cd "${OUT_DIR}"
-"${CUR_PWD}/${ZIP}" "${CUR_PWD}/${OUTPUT}" -Drq0 .
-""" % (
- unzip.executable.path,
- zip.executable.path,
- proto_apk.path,
- out.path,
- ),
- tools = [zip, unzip],
- arguments = [],
+ bundletool_module_builder = None):
+ args = ctx.actions.args()
+ args.add("--internal_apk_path", proto_apk)
+ args.add("--output_module_path", out)
+ ctx.actions.run(
inputs = [proto_apk],
outputs = [out],
- mnemonic = "Rebundle",
- progress_message = "Rebundle to %s" % out.short_path,
+ executable = bundletool_module_builder,
+ arguments = [args],
+ mnemonic = "BuildAppModule",
+ progress_message = "Building AAB zip module %s" % out.short_path,
toolchain = ANDROID_TOOLCHAIN_TYPE,
)
diff --git a/rules/busybox.bzl b/rules/busybox.bzl
index ce36d52..bcbb880 100644
--- a/rules/busybox.bzl
+++ b/rules/busybox.bzl
@@ -1150,8 +1150,8 @@ def _optimize(
host_javabase: Target. The host javabase.
"""
- output_files = []
- input_files = []
+ output_files = [out_apk]
+ input_files = [in_apk]
args = ctx.actions.args()
args.use_param_file("@%s")
@@ -1168,7 +1168,6 @@ def _optimize(
args.add("--resources-config-path", resource_optimization_config)
input_files.append(resource_optimization_config)
args.add("-o", out_apk)
- output_files.append(out_apk)
args.add(in_apk)
_java.run(
diff --git a/rules/dex.bzl b/rules/dex.bzl
index 4ab7704..a3e2620 100644
--- a/rules/dex.bzl
+++ b/rules/dex.bzl
@@ -50,12 +50,7 @@ def _process_incremental_dexing(
incremental_dexopts = _filter_dexopts(dexopts, ctx.fragments.android.get_dexopts_supported_in_incremental_dexing)
inclusion_filter_jar = proguarded_jar
if not proguarded_jar:
- dex_archives_list = info.dex_archives_dict.get("".join(incremental_dexopts), depset()).to_list()
- dex_archives = _to_dexed_classpath(
- dex_archives_dict = {d.jar: d.dex for d in dex_archives_list},
- classpath = _filter(java_info.transitive_runtime_jars.to_list(), excludes = _get_library_r_jars(deps)),
- runtime_jars = runtime_jars,
- )
+ dex_archives = []
for jar in runtime_jars:
dex_archive = _get_dx_artifact(ctx, jar.basename + ".dex.zip")
_dex(
@@ -68,6 +63,11 @@ def _process_incremental_dexing(
toolchain_type = toolchain_type,
)
dex_archives.append(dex_archive)
+ dex_archives += _to_dexed_classpath(
+ dex_archives_dict = {d.jar: d.dex for d in info.dex_archives_dict.get("".join(incremental_dexopts), depset()).to_list()},
+ classpath = _filter(java_info.transitive_runtime_jars.to_list(), excludes = _get_library_r_jars(deps)),
+ runtime_jars = runtime_jars,
+ )
else:
java_resource_jar = ctx.actions.declare_file(ctx.label.name + "_files/java_resources.jar")
if ctx.fragments.android.incremental_dexing_shards_after_proguard > 1:
@@ -332,7 +332,7 @@ def _shard_dexes(
outputs = [output],
inputs = inputs,
arguments = [args],
- mnemonic = "ShardsForMultiDex",
+ mnemonic = "ShardForMultidex",
progress_message = "Assembling dex files for " + ctx.label.name,
use_default_shell_env = True,
toolchain = toolchain_type,
@@ -396,6 +396,8 @@ def _dex(
dex_exec: File. The executable dex builder file.
"""
args = ctx.actions.args()
+ args.use_param_file("@%s", use_always = True) # Required for workers.
+ args.set_param_file_format("multiline")
args.add("--input_jar", input)
args.add("--output_zip", output)
diff --git a/rules/dex_desugar_aspect.bzl b/rules/dex_desugar_aspect.bzl
index 9d692d3..066ad1a 100644
--- a/rules/dex_desugar_aspect.bzl
+++ b/rules/dex_desugar_aspect.bzl
@@ -14,7 +14,7 @@
"""Aspect that transitively build .dex archives and desugar jars."""
-load(":utils.bzl", _utils = "utils")
+load(":utils.bzl", _get_android_sdk = "get_android_sdk", _utils = "utils")
load(":dex.bzl", _dex = "dex")
load(":desugar.bzl", _desugar = "desugar")
load(":providers.bzl", "StarlarkAndroidDexInfo")
@@ -193,8 +193,10 @@ def _get_boot_classpath(target, ctx):
compilation_info = target[JavaInfo].compilation_info
if compilation_info and compilation_info.boot_classpath:
return compilation_info.boot_classpath
- if ctx.attr._android_sdk and ctx.attr._android_sdk[AndroidSdkInfo].android_jar:
- return [ctx.attr._android_sdk[AndroidSdkInfo].android_jar]
+
+ android_jar = _get_android_sdk(ctx).android_jar
+ if android_jar:
+ return [android_jar]
# This shouldn't ever be reached, but if it is, we should be clear about the error.
fail("No compilation info or android jar!")
@@ -249,5 +251,6 @@ dex_desugar_aspect = aspect(
_attrs.ANDROID_SDK,
),
fragments = ["android"],
+ toolchains = ["//toolchains/android_sdk:toolchain_type"],
required_aspect_providers = [[JavaInfo]],
)
diff --git a/rules/instrumented_app_info_aspect.bzl b/rules/instrumented_app_info_aspect.bzl
new file mode 100644
index 0000000..0d457c6
--- /dev/null
+++ b/rules/instrumented_app_info_aspect.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.
+
+"""This aspect is used to collect providers from an instrumented android_binary."""
+
+load("//rules:providers.bzl", "InstrumentedAppInfo")
+
+def _impl(unused_target, ctx):
+ if hasattr(ctx.rule.attr, "instruments") and ctx.rule.attr.instruments and AndroidIdeInfo in ctx.rule.attr.instruments:
+ return [InstrumentedAppInfo(android_ide_info = ctx.rule.attr.instruments[AndroidIdeInfo])]
+ return []
+
+instrumented_app_info_aspect = aspect(
+ implementation = _impl,
+)
diff --git a/rules/native_deps.bzl b/rules/native_deps.bzl
index d503389..1500c47 100644
--- a/rules/native_deps.bzl
+++ b/rules/native_deps.bzl
@@ -179,7 +179,7 @@ def _filter_unique_shared_libs(linked_libs, cc_info):
"Each library in the transitive closure must have a " +
"unique basename to avoid name collisions when packaged into " +
"an apk, but two libraries have the basename '" + basename +
- "': " + artifact + " and " + old_artifact + (
+ "': " + str(artifact) + " and " + str(old_artifact) + (
" (the library already seen by this target)" if old_artifact in linked_libs else ""
),
)
@@ -237,8 +237,16 @@ def _is_shared_library(lib_artifact):
return True
return False
-def _get_build_info(ctx):
- return cc_common.get_build_info(ctx)
+def _is_stamping_enabled(ctx):
+ if ctx.configuration.is_tool_configuration():
+ return 0
+ return getattr(ctx.attr, "stamp", 0)
+
+def _get_build_info(ctx, cc_toolchain):
+ if _is_stamping_enabled(ctx):
+ return cc_toolchain.build_info_files().non_redacted_build_info_files.to_list()
+ else:
+ return cc_toolchain.build_info_files().redacted_build_info_files.to_list()
def _get_shared_native_deps_path(
linker_inputs,
@@ -294,14 +302,19 @@ def _link_native_deps_if_present(ctx, cc_info, cc_toolchain, build_config, actua
build_config.bin_dir,
)
- link_opts = cc_info.linking_context.user_link_flags
+ linker_inputs = cc_info.linking_context.linker_inputs.to_list()
+
+ link_opts = []
+ for linker_input in linker_inputs:
+ for flag in linker_input.user_link_flags:
+ link_opts.append(flag)
linkstamps = []
- for input in cc_info.linking_context.linker_inputs.to_list():
- linkstamps.extend(input.linkstamps)
+ for linker_input in linker_inputs:
+ linkstamps.extend(linker_input.linkstamps)
linkstamps_dict = {linkstamp: None for linkstamp in linkstamps}
- build_info_artifacts = _get_build_info(ctx) if linkstamps_dict else []
+ build_info_artifacts = _get_build_info(ctx, cc_toolchain) if linkstamps_dict else []
requested_features = ["static_linking_mode", "native_deps_link"]
requested_features.extend(ctx.features)
if not "legacy_whole_archive" in ctx.disabled_features:
diff --git a/rules/proguard.bzl b/rules/proguard.bzl
index d5caabb..9599658 100644
--- a/rules/proguard.bzl
+++ b/rules/proguard.bzl
@@ -30,23 +30,6 @@ _ProguardSpecContextInfo = provider(
),
)
-_ProguardOutputInfo = provider(
- doc = "Temporary provider to hold all proguard outputs. Will be replaced by a native " +
- "provider. Useful for testing.",
- fields = dict(
- input_jar = "The input program jar, unoptimized",
- output_jar = "The optimized output jar",
- mapping = "Output proguard map",
- proto_mapping = "Output proto mapping",
- seeds = "Output seeds",
- usage = "Output usage",
- library_jar = "Merged library jar",
- config = "Output config",
- baseline_profile_rewritten = "Optimized baseline profile",
- startup_profile_rewritten = "Optimized startup profile",
- ),
-)
-
def _validate_proguard_spec(
ctx,
out_validated_proguard_spec,
@@ -369,20 +352,32 @@ def _apply_proguard(
proguard_tool: FilesToRun. The proguard executable.
Returns:
- A struct of proguard outputs, corresponding to the fields in ProguardOutputInfo.
+ A struct of proguard outputs.
"""
if not proguard_specs:
+ outputs = _get_proguard_output(
+ ctx,
+ proguard_output_jar = proguard_output_jar,
+ proguard_seeds = None,
+ proguard_usage = None,
+ proguard_output_map = proguard_output_map,
+ combined_library_jar = None,
+ startup_profile_rewritten = None,
+ baseline_profile_rewritten = None,
+ )
+
# Fail at execution time if these artifacts are requested, to avoid issue where outputs are
# declared without having any proguard specs. This can happen if specs is a select() that
# resolves to an empty list.
_fail_action(
ctx,
- proguard_output_jar,
- proguard_output_map,
+ outputs.output_jar,
+ outputs.mapping,
+ outputs.config,
proguard_seeds,
proguard_usage,
)
- return None
+ return outputs
library_jar_list = [get_android_sdk(ctx).android_jar]
if ctx.fragments.android.desugar_java8:
@@ -416,11 +411,19 @@ def _get_proguard_output(
startup_profile_rewritten,
baseline_profile_rewritten):
"""Helper method to get a struct of all proguard outputs."""
+
+ # Proto Output Map is currently empty from ProGuard.
+ proguard_output_proto_map = None
+ if proguard_output_map:
+ proguard_output_proto_map = _get_proguard_temp_artifact(ctx, "_proguard.pbmap")
+ ctx.actions.write(proguard_output_proto_map, content = "")
+
config_output = _get_proguard_temp_artifact(ctx, "_proguard.config")
return struct(
output_jar = proguard_output_jar,
mapping = proguard_output_map,
+ proto_mapping = proguard_output_proto_map,
seeds = proguard_seeds,
usage = proguard_usage,
library_jar = combined_library_jar,
@@ -575,7 +578,7 @@ def _create_optimization_actions(
proguard_specs,
proguard_mapping,
i,
- "_ACTION_%s_OF_%s_" % (j, bytecode_optimization_pass_actions),
+ "_ACTION_%s_OF_%s" % (j, bytecode_optimization_pass_actions),
mnemonic,
last_stage_output,
optimizer_target,
@@ -678,5 +681,4 @@ testing = struct(
collect_transitive_proguard_specs = _collect_transitive_proguard_specs,
optimization_action = _optimization_action,
ProguardSpecContextInfo = _ProguardSpecContextInfo,
- ProguardOutputInfo = _ProguardOutputInfo,
)
diff --git a/rules/resources.bzl b/rules/resources.bzl
index 3f745b9..2ceecc0 100644
--- a/rules/resources.bzl
+++ b/rules/resources.bzl
@@ -32,9 +32,6 @@ load(
_log = "log",
)
-# Depot-wide min SDK floor
-_DEPOT_MIN_SDK_FLOOR = 14
-
_RESOURCE_FOLDER_TYPES = [
"anim",
"animator",
@@ -195,12 +192,12 @@ def _generate_dummy_manifest(
ctx,
out_manifest = None,
java_package = None,
- min_sdk_version = _DEPOT_MIN_SDK_FLOOR):
+ min_sdk_version = 0):
content = """<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="%s">""" % (java_package or "com.default")
- min_sdk_version = max(min_sdk_version, _DEPOT_MIN_SDK_FLOOR)
+ min_sdk_version = max(min_sdk_version, acls.get_min_sdk_floor(str(ctx.label)))
content = content + """
<uses-sdk android:minSdkVersion="%s" />""" % min_sdk_version
@@ -1080,7 +1077,7 @@ def _validate_resources(resource_files = None):
if res_type not in _RESOURCE_FOLDER_TYPES:
fail(_INCORRECT_RESOURCE_LAYOUT_ERROR % resource_file)
-def _process_manifest_values(ctx, manifest_values, min_sdk_floor = _DEPOT_MIN_SDK_FLOOR):
+def _process_manifest_values(ctx, manifest_values, min_sdk_floor):
expanded_manifest_values = utils.expand_make_vars(ctx, manifest_values)
if _MIN_SDK_VERSION in expanded_manifest_values and min_sdk_floor > 0:
expanded_manifest_values[_MIN_SDK_VERSION] = str(
@@ -1092,7 +1089,7 @@ def _bump_min_sdk(
ctx,
manifest = None,
manifest_values = None,
- floor = _DEPOT_MIN_SDK_FLOOR,
+ floor = None,
enforce_min_sdk_floor_tool = None):
"""Bumps the min SDK attribute of AndroidManifest to the floor.
@@ -1109,6 +1106,9 @@ def _bump_min_sdk(
"""
manifest_ctx = {}
+ if floor == None:
+ fail("Missing required `floor` in bump_min_sdk")
+
if manifest_values != None:
manifest_ctx[_PROCESSED_MANIFEST_VALUES] = _process_manifest_values(
ctx,
@@ -1453,7 +1453,7 @@ def _process_starlark(
ctx,
out_manifest = generated_manifest,
java_package = java_package if java_package else ctx.label.package.replace("/", "."),
- min_sdk_version = _DEPOT_MIN_SDK_FLOOR,
+ min_sdk_version = acls.get_min_sdk_floor(str(ctx.label)),
)
r_txt = ctx.actions.declare_file(
"_migrated/" + ctx.label.name + "_symbols/R.txt",
@@ -2101,9 +2101,6 @@ resources = struct(
validate_min_sdk = _validate_min_sdk,
shrink = _shrink,
optimize = _optimize,
-
- # Exposed for android_library, aar_import, and android_binary
- DEPOT_MIN_SDK_FLOOR = _DEPOT_MIN_SDK_FLOOR,
)
testing = struct(
diff --git a/rules/sandboxed_sdk_toolbox.bzl b/rules/sandboxed_sdk_toolbox.bzl
index 1c1a5dd..933212d 100644
--- a/rules/sandboxed_sdk_toolbox.bzl
+++ b/rules/sandboxed_sdk_toolbox.bzl
@@ -128,6 +128,7 @@ def _generate_sdk_dependencies_manifest(
output = None,
manifest_package = None,
sdk_module_configs = None,
+ sdk_archives = None,
debug_key = None,
sandboxed_sdk_toolbox = None,
host_javabase = None):
@@ -141,14 +142,21 @@ def _generate_sdk_dependencies_manifest(
output: File where the final manifest will be written.
manifest_package: The package used in the manifest.
sdk_module_configs: List of SDK Module config JSON files with SDK packages and versions.
- debug_key: Keystore that will later be used to sign the SDK APKs. It's expected to be a
+ sdk_archives: List of SDK archives, as ASAR files. They will also be listed as dependencies.
+ debug_key: Debug keystore that will later be used to sign the SDK APKs.
sandboxed_sdk_toolbox: Toolbox executable files.
host_javabase: Javabase used to run the toolbox.
"""
+ inputs = [debug_key]
args = ctx.actions.args()
args.add("generate-sdk-dependencies-manifest")
args.add("--manifest-package", manifest_package)
- args.add("--sdk-module-configs", ",".join([config.path for config in sdk_module_configs]))
+ if sdk_module_configs:
+ args.add("--sdk-module-configs", ",".join([config.path for config in sdk_module_configs]))
+ inputs.extend(sdk_module_configs)
+ if sdk_archives:
+ args.add("--sdk-archives", ",".join([archive.path for archive in sdk_archives]))
+ inputs.extend(sdk_archives)
args.add("--debug-keystore", debug_key)
args.add("--debug-keystore-pass", "android")
args.add("--debug-keystore-alias", "androiddebugkey")
@@ -158,7 +166,7 @@ def _generate_sdk_dependencies_manifest(
host_javabase = host_javabase,
executable = sandboxed_sdk_toolbox,
arguments = [args],
- inputs = sdk_module_configs + [debug_key],
+ inputs = inputs,
outputs = [output],
mnemonic = "GenSdkDepManifest",
progress_message = "Generate SDK dependencies manifest %s" % output.short_path,