diff --git a/rules/BUILD b/rules/BUILD index 93a9ef53b..f5dba6b57 100644 --- a/rules/BUILD +++ b/rules/BUILD @@ -112,3 +112,9 @@ bzl_library( "//rules/flags:bzl", ], ) + +bzl_library( + name = "min_sdk_version_bzl", + srcs = ["min_sdk_version.bzl"], + visibility = ["//:__subpackages__"], +) diff --git a/rules/aar_import/impl.bzl b/rules/aar_import/impl.bzl index c80d6182d..bfe0daeb1 100644 --- a/rules/aar_import/impl.bzl +++ b/rules/aar_import/impl.bzl @@ -475,7 +475,6 @@ def impl(ctx): manifest_ctx = _resources.bump_min_sdk( ctx, manifest = android_manifest, - 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 14256d5bf..6399cb017 100644 --- a/rules/acls.bzl +++ b/rules/acls.bzl @@ -65,7 +65,6 @@ load("//rules/acls:dex2oat_opts.bzl", "CAN_USE_DEX2OAT_OPTIONS") 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:min_sdk_floors.bzl", "MIN_SDK_FLOORS") load( "//rules/acls:partial_jetification_targets.bzl", "PARTIAL_JETIFICATION_TARGETS_FALLBACK", @@ -76,12 +75,6 @@ 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) @@ -272,7 +265,6 @@ ANDROID_INSTRUMENTATION_TEST_PREBUILT_TEST_APK_FALLBACK_DICT = make_dict(ANDROID BASELINE_PROFILES_ROLLOUT_DICT = make_dict(BASELINE_PROFILES_ROLLOUT) BASELINE_PROFILES_OPTIMIZER_INTEGRATION_DICT = make_dict(BASELINE_PROFILES_OPTIMIZER_INTEGRATION) BASELINE_PROFILES_OPTIMIZER_INTEGRATION_FALLBACK_DICT = make_dict(BASELINE_PROFILES_OPTIMIZER_INTEGRATION_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) DATABINDING_ALLOWED_DICT = make_dict(DATABINDING_ALLOWED) @@ -337,7 +329,6 @@ 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, diff --git a/rules/android_binary_internal/impl.bzl b/rules/android_binary_internal/impl.bzl index b9e9d629b..8880d2252 100644 --- a/rules/android_binary_internal/impl.bzl +++ b/rules/android_binary_internal/impl.bzl @@ -54,7 +54,6 @@ def _process_manifest(ctx, **unused_ctxs): ctx, manifest = ctx.file.manifest, manifest_values = ctx.attr.manifest_values, - 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, ) @@ -113,7 +112,6 @@ def _validate_manifest(ctx, packaged_resources_ctx, **unused_ctxs): min_sdk_validation_output = _resources.validate_min_sdk( ctx, manifest = packaged_resources_ctx.processed_manifest, - 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, ) if min_sdk_validation_output: diff --git a/rules/android_library/impl.bzl b/rules/android_library/impl.bzl index d28806777..7a817a966 100644 --- a/rules/android_library/impl.bzl +++ b/rules/android_library/impl.bzl @@ -133,7 +133,6 @@ def _process_manifest(ctx, **unused_ctxs): manifest_ctx = _resources.bump_min_sdk( ctx, manifest = ctx.file.manifest, - 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_local_test/impl.bzl b/rules/android_local_test/impl.bzl index 7e324a74b..b2eeb06e0 100644 --- a/rules/android_local_test/impl.bzl +++ b/rules/android_local_test/impl.bzl @@ -14,7 +14,6 @@ """Bazel rule for Android local test.""" -load("//rules:acls.bzl", "acls") load("//rules:attrs.bzl", "attrs") load("//rules:common.bzl", "common") load("//rules:java.bzl", "java") @@ -49,7 +48,7 @@ DEFAULT_JIT_FLAGS = ["-XX:+TieredCompilation", "-XX:TieredStopAtLevel=1"] # the best across all P% layers from profiling. DEFAULT_GC_FLAGS = ["-Xmx8g"] -# disable class loading by default for faster classloading and consistent enviroment across +# disable class loading by default for faster classloading and consistent environment across # local and remote execution DEFAULT_VERIFY_FLAGS = ["-Xverify:none"] @@ -61,7 +60,6 @@ def _process_manifest(ctx, java_package, **_unused_sub_ctxs): manifest_values = resources.process_manifest_values( ctx, ctx.attr.manifest_values, - acls.get_min_sdk_floor(str(ctx.label)), ) if ctx.file.manifest == None: # No manifest provided, generate one @@ -78,7 +76,6 @@ def _process_manifest(ctx, java_package, **_unused_sub_ctxs): ctx, manifest = ctx.file.manifest, manifest_values = ctx.attr.manifest_values, - 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/min_sdk_version.bzl b/rules/min_sdk_version.bzl new file mode 100644 index 000000000..0bfa8c588 --- /dev/null +++ b/rules/min_sdk_version.bzl @@ -0,0 +1,26 @@ +# Copyright 2024 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. + +""" Module for handling minSdkVersion configuration. + +This module holds the current minimum minSdkVersion supported by the Android Rules. Additionally +it holds utilities for handling minSdkVersion propagation. + +""" + +_DEPOT_FLOOR = 19 + +min_sdk_version = struct( + DEPOT_FLOOR = _DEPOT_FLOOR, +) diff --git a/rules/resources.bzl b/rules/resources.bzl index 8a3962264..31f497bd3 100644 --- a/rules/resources.bzl +++ b/rules/resources.bzl @@ -15,6 +15,7 @@ """Bazel Android Resources.""" load("//rules:acls.bzl", "acls") +load("//rules:min_sdk_version.bzl", _min_sdk_version = "min_sdk_version") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load(":attrs.bzl", _attrs = "attrs") load(":busybox.bzl", _busybox = "busybox") @@ -199,7 +200,7 @@ def _generate_dummy_manifest( """ % (java_package or "com.default") - min_sdk_version = max(min_sdk_version, acls.get_min_sdk_floor(str(ctx.label))) + min_sdk_version = max(min_sdk_version, _min_sdk_version.DEPOT_FLOOR) content = content + """ """ % min_sdk_version @@ -1110,7 +1111,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): +def _process_manifest_values(ctx, manifest_values, min_sdk_floor = _min_sdk_version.DEPOT_FLOOR): expanded_manifest_values = utils.expand_make_vars(ctx, manifest_values) # We cannot bump non-integer minSdkVersion values. These are used for pre-release versions of Android. @@ -1124,7 +1125,7 @@ def _bump_min_sdk( ctx, manifest = None, manifest_values = None, - floor = None, + floor = _min_sdk_version.DEPOT_FLOOR, enforce_min_sdk_floor_tool = None): """Bumps the min SDK attribute of AndroidManifest to the floor. @@ -1237,8 +1238,8 @@ def _set_default_min_sdk( def _validate_min_sdk( ctx, manifest, - floor, - enforce_min_sdk_floor_tool): + floor = _min_sdk_version.DEPOT_FLOOR, + enforce_min_sdk_floor_tool = None): """Validates that the min SDK attribute of AndroidManifest is at least at the floor. Args: @@ -1528,7 +1529,7 @@ def _process_starlark( ctx, out_manifest = generated_manifest, java_package = java_package if java_package else ctx.label.package.replace("/", "."), - min_sdk_version = acls.get_min_sdk_floor(str(ctx.label)), + min_sdk_version = _min_sdk_version.DEPOT_FLOOR, ) r_txt = ctx.actions.declare_file( "_migrated/" + ctx.label.name + "_symbols/R.txt",