Delete android_sandboxed_sdk. One more change to follow to delete the tool + providers. PiperOrigin-RevId: 943551886 Change-Id: I33a3803de2ac3b27951ec81df1cb8c29c1b277b9
diff --git a/android/rules.bzl b/android/rules.bzl index af06e80..8a09c0e 100644 --- a/android/rules.bzl +++ b/android/rules.bzl
@@ -53,18 +53,7 @@ "//rules/android_local_test:rule.bzl", _android_local_test = "android_local_test", ) -load( - "//rules/android_sandboxed_sdk:android_sandboxed_sdk.bzl", - _android_sandboxed_sdk = "android_sandboxed_sdk", -) -load( - "//rules/android_sandboxed_sdk:android_sandboxed_sdk_bundle.bzl", - _android_sandboxed_sdk_bundle = "android_sandboxed_sdk_bundle", -) -load( - "//rules/android_sandboxed_sdk:asar_import.bzl", - _asar_import = "asar_import", -) + load( "//rules/android_sdk_repository:rule.bzl", _android_sdk_repository = "android_sdk_repository", @@ -78,12 +67,11 @@ android_binary = _android_binary android_library = _android_library android_local_test = _android_local_test -android_sandboxed_sdk = _android_sandboxed_sdk -android_sandboxed_sdk_bundle = _android_sandboxed_sdk_bundle + android_sdk = _android_sdk android_sdk_repository = _android_sdk_repository android_tools_defaults_jar = _android_tools_defaults_jar -asar_import = _asar_import + instrumented_app_info_aspect = _instrumented_app_info_aspect StarlarkApkInfo = _StarlarkApkInfo ApkInfo = _ApkInfo
diff --git a/rules/BUILD b/rules/BUILD index 4cb95be..295c065 100644 --- a/rules/BUILD +++ b/rules/BUILD
@@ -45,7 +45,6 @@ "processing_pipeline.bzl", "proguard.bzl", "resources.bzl", - "sandboxed_sdk_toolbox.bzl", "utils.bzl", ], visibility = ["//:__subpackages__"], @@ -123,7 +122,6 @@ "//rules/android_binary:bzl", "//rules/android_library:bzl", "//rules/android_local_test:bzl", - "//rules/android_sandboxed_sdk:bzl", "//rules/android_sdk_repository:bzl", "//rules/flags:bzl", "@bazel_skylib//lib:collections",
diff --git a/rules/acls.bzl b/rules/acls.bzl index 40ac6e6..ddab3bd 100644 --- a/rules/acls.bzl +++ b/rules/acls.bzl
@@ -34,7 +34,6 @@ load("//rules/acls:aar_import_propagate_native_libs.bzl", "AAR_IMPORT_PROPAGATE_NATIVE_LIBS_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_application_with_sandboxed_sdks_allowlist.bzl", "ANDROID_APPLICATION_WITH_SANDBOXED_SDKS_ALLOWLIST") 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") @@ -43,7 +42,6 @@ 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_resource_shrinking_in_optimizer_rollout.bzl", "RESOURCE_SHRINKING_IN_OPTIMIZER_FALLBACK", "RESOURCE_SHRINKING_IN_OPTIMIZER_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_feature_splits_dogfood.bzl", "ANDROID_FEATURE_SPLITS_DOGFOOD") load("//rules/acls:android_instrumentation_test_manifest_check_rollout.bzl", "ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_FALLBACK", "ANDROID_INSTRUMENTATION_TEST_MANIFEST_CHECK_ROLLOUT") @@ -92,18 +90,12 @@ def _in_aar_import_exports_r_java(fqn): return matches(fqn, AAR_IMPORT_EXPORTS_R_JAVA_DICT) -def _in_android_application_with_sandboxed_sdks_allowlist_dict(fqn): - return matches(fqn, ANDROID_APPLICATION_WITH_SANDBOXED_SDKS_ALLOWLIST_DICT) - def _in_android_archive_dogfood(fqn): return matches(fqn, ANDROID_ARCHIVE_DOGFOOD_DICT) def _in_android_archive_excluded_deps_denylist(fqn): return matches(fqn, ANDROID_ARCHIVE_EXCLUDED_DEPS_DENYLIST_DICT) -def _in_android_binary_with_sandboxed_sdks_allowlist(fqn): - return matches(fqn, ANDROID_BINARY_WITH_SANDBOXED_SDKS_ALLOWLIST_DICT) - def _in_android_feature_splits_dogfood(fqn): return matches(fqn, ANDROID_FEATURE_SPLITS_DOGFOOD_DICT) @@ -249,10 +241,10 @@ 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) AAR_IMPORT_EXPORTS_R_JAVA_DICT = make_dict(AAR_IMPORT_EXPORTS_R_JAVA) -ANDROID_APPLICATION_WITH_SANDBOXED_SDKS_ALLOWLIST_DICT = make_dict(ANDROID_APPLICATION_WITH_SANDBOXED_SDKS_ALLOWLIST) + ANDROID_ARCHIVE_DOGFOOD_DICT = make_dict(ANDROID_ARCHIVE_DOGFOOD) ANDROID_ARCHIVE_EXCLUDED_DEPS_DENYLIST_DICT = make_dict(ANDROID_ARCHIVE_EXCLUDED_DEPS_DENYLIST) -ANDROID_BINARY_WITH_SANDBOXED_SDKS_ALLOWLIST_DICT = make_dict(ANDROID_BINARY_WITH_SANDBOXED_SDKS_ALLOWLIST) + ANDROID_FEATURE_SPLITS_DOGFOOD_DICT = make_dict(ANDROID_FEATURE_SPLITS_DOGFOOD) 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) @@ -366,10 +358,8 @@ in_aar_import_explicit_exports_manifest = _in_aar_import_explicit_exports_manifest, in_aar_import_exports_r_java = _in_aar_import_exports_r_java, in_b122039567 = _in_b122039567, - in_android_application_with_sandboxed_sdks_allowlist_dict = _in_android_application_with_sandboxed_sdks_allowlist_dict, in_android_archive_dogfood = _in_android_archive_dogfood, in_android_archive_excluded_deps_denylist = _in_android_archive_excluded_deps_denylist, - in_android_binary_with_sandboxed_sdks_allowlist = _in_android_binary_with_sandboxed_sdks_allowlist, in_android_feature_splits_dogfood = _in_android_feature_splits_dogfood, 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,
diff --git a/rules/android_application/BUILD b/rules/android_application/BUILD index 0805370..16c4850 100644 --- a/rules/android_application/BUILD +++ b/rules/android_application/BUILD
@@ -25,7 +25,6 @@ deps = [ "//rules:android_platforms_transition_bzl", "//rules:common_bzl", - "//rules/android_sandboxed_sdk:bzl", "//rules/flags:bzl", "@rules_java//java/common", ],
diff --git a/rules/android_application/android_application_rule.bzl b/rules/android_application/android_application_rule.bzl index 4e5f6e4..deefd3f 100644 --- a/rules/android_application/android_application_rule.bzl +++ b/rules/android_application/android_application_rule.bzl
@@ -15,13 +15,11 @@ load( "//providers:providers.bzl", - "AndroidArchivedSandboxedSdkInfo", "AndroidBundleInfo", "AndroidFeatureModuleInfo", "AndroidIdeInfo", "AndroidOptimizationInfo", "AndroidPreDexJarInfo", - "AndroidSandboxedSdkBundleInfo", "ApkInfo", "ArtProfileInfo", "ProguardMappingInfo", @@ -31,7 +29,6 @@ "//rules:aapt.bzl", _aapt = "aapt", ) -load("//rules:acls.bzl", _acls = "acls") load("//rules:android_platforms_transition.bzl", "android_platforms_transition") load( "//rules:bundletool.bzl", @@ -50,10 +47,6 @@ _java = "java", ) load( - "//rules:sandboxed_sdk_toolbox.bzl", - _sandboxed_sdk_toolbox = "sandboxed_sdk_toolbox", -) -load( "//rules:utils.bzl", "ANDROID_SDK_TOOLCHAIN_TYPE", "get_android_sdk", @@ -263,40 +256,6 @@ return manifest -def _generate_runtime_enabled_sdk_config(ctx, base_proto_apk): - module_configs = [ - 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 - ] - if not (sdk_archives or module_configs): - return None - - debug_key = ctx.file._sandboxed_sdks_debug_key - manifest_xml_tree = ctx.actions.declare_file(ctx.label.name + "/manifest_tree_dump.txt") - _aapt.dump_manifest_xml_tree( - ctx, - out = manifest_xml_tree, - apk = base_proto_apk, - aapt = get_android_toolchain(ctx).aapt2.files_to_run, - ) - - config = ctx.actions.declare_file("%s/runtime-enabled-sdk-config.pb" % ctx.label.name) - _sandboxed_sdk_toolbox.generate_runtime_enabled_sdk_config( - ctx, - output = config, - manifest_xml_tree = manifest_xml_tree, - sdk_module_configs = module_configs, - sdk_archives = sdk_archives, - debug_key = debug_key, - sandboxed_sdk_toolbox = get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run, - host_javabase = _common.get_host_javabase(ctx), - ) - return config - def _validate_manifest_values(manifest_values): if "applicationId" not in manifest_values: _log.error("missing required applicationId in manifest_values") @@ -325,8 +284,6 @@ ctx, out = base_module, proto_apk = base_proto_apk, - # RuntimeEnabledSdkConfig should only be added to the base module. - runtime_enabled_sdk_config = _generate_runtime_enabled_sdk_config(ctx, base_proto_apk), bundletool_module_builder = get_android_toolchain(ctx).bundletool_module_builder.files_to_run, ) @@ -477,18 +434,10 @@ feature_modules = attrs.pop("feature_modules", []) or [] bundle_config = attrs.pop("bundle_config", None) bundle_config_file = attrs.pop("bundle_config_file", None) - sdk_archives = attrs.pop("sdk_archives", []) or [] - sdk_bundles = attrs.pop("sdk_bundles", []) or [] - uses_sandboxed_sdks = sdk_archives or sdk_bundles - if (uses_sandboxed_sdks and - not _acls.in_android_application_with_sandboxed_sdks_allowlist_dict(fqn)): - fail("%s is not allowed to use sdk_archives or sdk_bundles." % fqn) - uses_bundle_features = ( feature_modules or bool(bundle_config) or - bool(bundle_config_file) or - uses_sandboxed_sdks + bool(bundle_config_file) ) # Simply fall back to android_binary if no bundle features are used. @@ -532,8 +481,6 @@ testonly = attrs.get("testonly"), transitive_configs = attrs.get("transitive_configs", []), feature_modules = feature_modules, - sdk_archives = sdk_archives, - sdk_bundles = sdk_bundles, manifest_values = attrs.get("manifest_values"), visibility = attrs.get("visibility", None), tags = attrs.get("tags", []),
diff --git a/rules/android_application/attrs.bzl b/rules/android_application/attrs.bzl index b7b7199..42116be 100644 --- a/rules/android_application/attrs.bzl +++ b/rules/android_application/attrs.bzl
@@ -13,11 +13,6 @@ # limitations under the License. """Attributes for android_application.""" -load( - "//providers:providers.bzl", - "AndroidArchivedSandboxedSdkInfo", - "AndroidSandboxedSdkBundleInfo", -) load("//rules:android_split_transition.bzl", "android_split_transition") load( "//rules:attrs.bzl", @@ -57,16 +52,6 @@ ), custom_package = attr.string(), feature_modules = attr.label_list(allow_files = False), - sdk_archives = attr.label_list( - providers = [ - [AndroidArchivedSandboxedSdkInfo], - ], - ), - sdk_bundles = attr.label_list( - providers = [ - [AndroidSandboxedSdkBundleInfo], - ], - ), _bundle_deploy = attr.label( allow_single_file = True, default = ":bundle_deploy.sh_template", @@ -96,10 +81,6 @@ cfg = "exec", default = Label("//tools/jdk:current_java_runtime"), ), - _sandboxed_sdks_debug_key = attr.label( - allow_single_file = True, - default = Label("//tools/android:debug_keystore"), - ), ), _attrs.ANDROID_SDK, )
diff --git a/rules/android_sandboxed_sdk/BUILD b/rules/android_sandboxed_sdk/BUILD deleted file mode 100644 index bc82c71..0000000 --- a/rules/android_sandboxed_sdk/BUILD +++ /dev/null
@@ -1,25 +0,0 @@ -# Android Sandboxed SDK rules. - -load("@bazel_skylib//:bzl_library.bzl", "bzl_library") - -licenses(["notice"]) - -exports_files([ - "android_sandboxed_sdk.bzl", - "android_sandboxed_sdk_bundle.bzl", -]) - -filegroup( - name = "all_files", - srcs = glob(["**"]), -) - -bzl_library( - name = "bzl", - srcs = glob(["*.bzl"]), - visibility = ["//:__subpackages__"], - deps = [ - "//rules:common_bzl", - "//rules/android_binary:bzl", - ], -)
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 deleted file mode 100644 index a1f6c6f..0000000 --- a/rules/android_sandboxed_sdk/android_binary_with_sandboxed_sdks_macro.bzl +++ /dev/null
@@ -1,539 +0,0 @@ -# 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. -# 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. -"""Bazel rule for defining an Android binary that depends on sandboxed SDKs.""" - -load("//providers:providers.bzl", "AndroidArchivedSandboxedSdkInfo", "AndroidSandboxedSdkApkInfo", "AndroidSandboxedSdkBundleInfo", "ApkInfo") -load( - "//rules:aapt.bzl", - _aapt = "aapt", -) -load("//rules:acls.bzl", "acls") -load("//rules:bundletool.bzl", _bundletool = "bundletool") -load("//rules:common.bzl", _common = "common") -load("//rules:java.bzl", _java = "java") -load( - "//rules:sandboxed_sdk_toolbox.bzl", - _sandboxed_sdk_toolbox = "sandboxed_sdk_toolbox", -) -load( - "//rules:utils.bzl", - _get_android_toolchain = "get_android_toolchain", - _utils = "utils", -) -load("//rules:visibility.bzl", "PROJECT_VISIBILITY") - -visibility(PROJECT_VISIBILITY) - -def _gen_sdk_dependencies_manifest_impl(ctx): - manifest = ctx.actions.declare_file(ctx.label.name + "_sdk_dep_manifest.xml") - module_configs = [ - 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), - ) - - return [ - DefaultInfo( - files = depset([manifest]), - ), - ] - -_gen_sdk_dependencies_manifest = rule( - attrs = dict( - package = attr.string(), - sdk_bundles = attr.label_list( - providers = [ - [AndroidSandboxedSdkBundleInfo], - ], - ), - sdk_archives = attr.label_list( - providers = [ - [AndroidArchivedSandboxedSdkInfo], - ], - ), - debug_key = attr.label( - allow_single_file = True, - default = Label("//tools/android:debug_keystore"), - ), - _host_javabase = attr.label( - cfg = "exec", - default = Label("//tools/jdk:current_java_runtime"), - ), - ), - executable = False, - implementation = _gen_sdk_dependencies_manifest_impl, - toolchains = [ - "//toolchains/android:toolchain_type", - "@bazel_tools//tools/jdk:toolchain_type", - ], -) - -def _gen_sdk_dependencies_table_asset_impl(ctx): - runtime_enabled_sdk_metadata = ctx.actions.declare_file( - "%s/RuntimeEnabledSdkTable.xml" % ctx.attr.assets_dir, - ) - module_configs = [ - 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_runtime_enabled_sdk_table( - ctx, - output = runtime_enabled_sdk_metadata, - sdk_archives = sdk_archives, - sdk_module_configs = module_configs, - sandboxed_sdk_toolbox = _get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run, - host_javabase = _common.get_host_javabase(ctx), - ) - - return [ - DefaultInfo( - files = depset([runtime_enabled_sdk_metadata]), - ), - ] - -_gen_sdk_dependencies_table_asset = rule( - attrs = dict( - assets_dir = attr.string(), - sdk_archives = attr.label_list( - providers = [ - [AndroidArchivedSandboxedSdkInfo], - ], - ), - sdk_bundles = attr.label_list( - providers = [ - [AndroidSandboxedSdkBundleInfo], - ], - ), - _host_javabase = attr.label( - cfg = "exec", - default = Label("//tools/jdk:current_java_runtime"), - ), - ), - executable = False, - implementation = _gen_sdk_dependencies_table_asset_impl, - toolchains = [ - "//toolchains/android:toolchain_type", - "@bazel_tools//tools/jdk:toolchain_type", - ], -) - -def _get_sandboxed_sdk_apks(ctx): - sdk_apks = [] - for idx, sdk_archive in enumerate(ctx.attr.sdk_archives): - 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_archive = sdk_archive[AndroidArchivedSandboxedSdkInfo].asar, - 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_bundle_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 = sdk_bundle_target[AndroidSandboxedSdkBundleInfo].asb, - 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) - return sdk_apks - -def _get_runtime_enabled_config(ctx, manifest_xml_tree): - app_apk_info = ctx.attr.internal_android_binary[ApkInfo] - module_configs = [ - 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 - ] - - debug_key = _utils.only(app_apk_info.signing_keys) - config = ctx.actions.declare_file("%s/runtime-enabled-sdk-config.pb" % ctx.label.name) - _sandboxed_sdk_toolbox.generate_runtime_enabled_sdk_config( - ctx, - output = config, - manifest_xml_tree = manifest_xml_tree, - sdk_module_configs = module_configs, - sdk_archives = sdk_archives, - debug_key = debug_key, - sandboxed_sdk_toolbox = _get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run, - host_javabase = _common.get_host_javabase(ctx), - ) - return config - -def _get_split_sdk_apk( - ctx, - output_dir_name, - output_apk_name, - runtime_enabled_sdk_config, - manifest_xml_tree, - sdk_archive_asar = None, - sdk_bundle = None, - sdk_module_config = None): - sdk_split_properties = ctx.actions.declare_file("%s/%s.pb.json" % ( - output_dir_name, - output_apk_name, - )) - _sandboxed_sdk_toolbox.generate_sdk_split_properties( - ctx, - output = sdk_split_properties, - sdk_archive = sdk_archive_asar, - sdk_module_config = sdk_module_config, - runtime_enabled_sdk_config = runtime_enabled_sdk_config, - manifest_xml_tree = manifest_xml_tree, - sandboxed_sdk_toolbox = _get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run, - host_javabase = _common.get_host_javabase(ctx), - ) - - split = ctx.actions.declare_file("%s/%s.apk" % ( - output_dir_name, - output_apk_name, - )) - _bundletool.build_sdk_apks_for_app( - ctx, - out = split, - aapt2 = _get_android_toolchain(ctx).aapt2.files_to_run, - sdk_archive = sdk_archive_asar, - sdk_bundle = sdk_bundle, - sdk_split_properties_inherited_from_app = sdk_split_properties, - debug_key = ctx.file.debug_key, - bundletool = _get_android_toolchain(ctx).bundletool.files_to_run, - host_javabase = _common.get_host_javabase(ctx), - ) - return split - -def _get_all_split_sdk_apks(ctx): - manifest_xml_tree = ctx.actions.declare_file(ctx.label.name + "/manifest_tree_dump.txt") - _aapt.dump_manifest_xml_tree( - ctx, - out = manifest_xml_tree, - apk = ctx.attr.internal_android_binary[ApkInfo].unsigned_apk, - aapt = _get_android_toolchain(ctx).aapt2.files_to_run, - ) - runtime_enabled_sdk_config = _get_runtime_enabled_config(ctx, manifest_xml_tree) - sdk_splits = [] - for idx, sdk_archive_info in enumerate(ctx.attr.sdk_archives): - sdk_archive = sdk_archive_info[AndroidArchivedSandboxedSdkInfo].asar - sdk_splits.append(_get_split_sdk_apk( - ctx, - output_dir_name = "%s/sdk_archive_splits" % ctx.label.name, - output_apk_name = idx, - manifest_xml_tree = manifest_xml_tree, - runtime_enabled_sdk_config = runtime_enabled_sdk_config, - sdk_archive_asar = sdk_archive, - )) - for idx, sdk_bundle_target in enumerate(ctx.attr.sdk_bundles): - sdk_bundle_info = sdk_bundle_target[AndroidSandboxedSdkBundleInfo] - sdk_splits.append(_get_split_sdk_apk( - ctx, - output_dir_name = "%s/sdk_bundle_splits" % ctx.label.name, - output_apk_name = idx, - manifest_xml_tree = manifest_xml_tree, - runtime_enabled_sdk_config = runtime_enabled_sdk_config, - sdk_bundle = sdk_bundle_info.asb, - sdk_module_config = sdk_bundle_info.sdk_info.sdk_module_config, - )) - return sdk_splits - -def _android_binary_with_sandboxed_sdks_impl(ctx): - app_apk = ctx.attr.internal_android_binary[ApkInfo].signed_apk - adb = _get_android_toolchain(ctx).adb.files_to_run.executable - substitutions = { - "%adb%": adb.short_path, - "%app_apk%": app_apk.short_path, - } - install_script = ctx.actions.declare_file("%s_install_script.sh" % ctx.label.name) - template = None - sdk_apks = [] - sdk_splits = [] - - if ctx.attr.use_compat_splits: - sdk_splits.extend(_get_all_split_sdk_apks(ctx)) - substitutions["%sdk_splits%"] = ",".join([split.short_path for split in sdk_splits]) - template = ctx.file._install_splits_script_template - else: - sdk_apks.extend(_get_sandboxed_sdk_apks(ctx)) - substitutions["%sdk_apks%"] = ",".join([apk.short_path for apk in sdk_apks]) - template = ctx.file._install_apks_script_template - - ctx.actions.expand_template( - template = template, - output = install_script, - substitutions = substitutions, - is_executable = True, - ) - - return [ - AndroidSandboxedSdkApkInfo( - app_apk_info = ctx.attr.internal_android_binary[ApkInfo], - sandboxed_sdk_apks = sdk_apks, - sandboxed_sdk_splits = sdk_splits, - ), - DefaultInfo( - executable = install_script, - files = depset([app_apk] + sdk_splits + sdk_apks), - runfiles = ctx.runfiles([ - adb, - app_apk, - ] + sdk_apks + sdk_splits), - ), - ] - -def _get_extra_dependency_for_sandboxed_apks( - name, - app_package, - sdk_archives, - sdk_bundles, - testonly, - tags, - transitive_configs, - visibility, - _android_library): - # Generate a manifest that lists all the SDK dependencies with <uses-sdk-library> tags. - sdk_dependencies_manifest_name = "%s_sdk_dependencies_manifest" % name - _gen_sdk_dependencies_manifest( - name = sdk_dependencies_manifest_name, - package = "%s.internalsdkdependencies" % app_package, - sdk_bundles = sdk_bundles, - sdk_archives = sdk_archives, - testonly = testonly, - tags = tags, - visibility = visibility, - ) - - # Use the manifest in a normal android_library. This will later be added as a dependency to the - # binary, so the manifest is merged with the app's. - sdk_dependencies_lib_name = "%s_sdk_dependencies_lib" % name - _android_library( - name = sdk_dependencies_lib_name, - exports_manifest = 1, - manifest = ":%s" % sdk_dependencies_manifest_name, - testonly = testonly, - tags = tags, - transitive_configs = transitive_configs, - visibility = visibility, - ) - - return ":%s" % sdk_dependencies_lib_name - -def _get_extra_dependency_for_split_apks( - name, - app_package, - sdk_archives, - sdk_bundles, - testonly, - tags, - transitive_configs, - visibility, - _android_library): - assets_dir = "%s/assets" % name - runtime_enabled_sdk_metadata_asset = "%s_runtime_enabled_sdk_metadata" % name - _gen_sdk_dependencies_table_asset( - name = runtime_enabled_sdk_metadata_asset, - assets_dir = assets_dir, - sdk_archives = sdk_archives, - sdk_bundles = sdk_bundles, - testonly = testonly, - tags = tags, - visibility = visibility, - ) - - manifest_name = "%s_manifest" % runtime_enabled_sdk_metadata_asset - native.genrule( - name = manifest_name, - outs = [name + "/RuntimeEnabledSdkMetadata/AndroidManifest.xml"], - cmd = """cat > $@ <<EOF -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="{package}"> -</manifest> -EOF -""".format(package = "%s.internalsdkmetadata" % app_package), - ) - - # Use the manifest in a normal android_library. This will later be added as a dependency to the - # binary, so the runtime_enabled_sdk_metadata asset is present in the main app APK. - runtime_enabled_sdk_metadata_lib_name = "%s_runtime_enabled_sdk_metadata_lib" % name - _android_library( - name = runtime_enabled_sdk_metadata_lib_name, - assets = [":%s" % runtime_enabled_sdk_metadata_asset], - assets_dir = assets_dir, - manifest = ":%s" % manifest_name, - testonly = testonly, - tags = tags, - transitive_configs = transitive_configs, - visibility = visibility, - ) - return ":%s" % runtime_enabled_sdk_metadata_lib_name - -_android_binary_with_sandboxed_sdks = rule( - attrs = dict( - internal_android_binary = attr.label( - providers = [ - [ApkInfo], - ], - ), - debug_key = attr.label( - allow_single_file = True, - default = Label("//tools/android:debug_keystore"), - ), - sdk_bundles = attr.label_list( - providers = [ - [AndroidSandboxedSdkBundleInfo], - ], - ), - sdk_archives = attr.label_list( - providers = [ - [AndroidArchivedSandboxedSdkInfo], - ], - ), - use_compat_splits = attr.bool(default = False), - _install_apks_script_template = attr.label( - allow_single_file = True, - default = ":install_apks_script.sh_template", - ), - _install_splits_script_template = attr.label( - allow_single_file = True, - default = ":install_splits_script.sh_template", - ), - _host_javabase = attr.label( - cfg = "exec", - default = Label("//tools/jdk:current_java_runtime"), - ), - ), - executable = True, - implementation = _android_binary_with_sandboxed_sdks_impl, - toolchains = [ - "//toolchains/android:toolchain_type", - "@bazel_tools//tools/jdk:toolchain_type", - ], -) - -def android_binary_with_sandboxed_sdks_macro( - _android_binary, - _android_library, - **attrs): - """android_binary_with_sandboxed_sdks. - - Args: - _android_binary: The android_binary rule to use. - _android_library: The android_library rule to use. - **attrs: android_binary attributes. - """ - - name = attrs.pop("name", None) - fully_qualified_name = "//%s:%s" % (native.package_name(), name) - if (not acls.in_android_binary_with_sandboxed_sdks_allowlist(fully_qualified_name)): - fail("%s is not allowed to use the android_binary_with_sandboxed_sdks macro." % - fully_qualified_name) - - app_package = _java.resolve_package_from_label( - Label(fully_qualified_name), - getattr(attrs, "custom_package", None), - ) - sdk_bundles = attrs.pop("sdk_bundles", []) - sdk_archives = attrs.pop("sdk_archives", []) - debug_keystore = getattr(attrs, "debug_keystore", None) - testonly = attrs.get("testonly", False) - tags = attrs.get("tags", []) - transitive_configs = attrs.get("transitive_configs", []) - visibility = attrs.get("visibility", None) - - use_compat_splits = attrs.pop("use_compat_splits", False) - - deps = attrs.pop("deps", []) - if use_compat_splits: - deps.append( - _get_extra_dependency_for_split_apks( - name = name, - app_package = app_package, - sdk_archives = sdk_archives, - sdk_bundles = sdk_bundles, - testonly = testonly, - tags = tags, - transitive_configs = transitive_configs, - visibility = visibility, - _android_library = _android_library, - ), - ) - else: - deps.append( - _get_extra_dependency_for_sandboxed_apks( - name = name, - app_package = app_package, - sdk_archives = sdk_archives, - sdk_bundles = sdk_bundles, - testonly = testonly, - tags = tags, - transitive_configs = transitive_configs, - visibility = visibility, - _android_library = _android_library, - ), - ) - - # Generate the android_binary as normal, passing the extra flags. - bin_label = Label("%s_app_bin" % fully_qualified_name) - _android_binary( - name = bin_label.name, - deps = deps, - **attrs - ) - - # This final rule will call Bundletool to generate the SDK APKs and provide the install script. - _android_binary_with_sandboxed_sdks( - name = name, - sdk_bundles = sdk_bundles, - sdk_archives = sdk_archives, - debug_key = debug_keystore, - use_compat_splits = use_compat_splits, - internal_android_binary = bin_label, - testonly = testonly, - tags = tags, - visibility = visibility, - )
diff --git a/rules/android_sandboxed_sdk/android_sandboxed_sdk.bzl b/rules/android_sandboxed_sdk/android_sandboxed_sdk.bzl deleted file mode 100644 index 3ab7abb..0000000 --- a/rules/android_sandboxed_sdk/android_sandboxed_sdk.bzl +++ /dev/null
@@ -1,71 +0,0 @@ -# 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. -# 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. -"""android_sandboxed_sdk rule. - -This file exists to inject the correct version of android_binary. -""" - -load("//rules:visibility.bzl", "PROJECT_VISIBILITY") -load("//rules/android_binary:rule.bzl", _android_binary_macro = "android_binary_macro") -load(":android_sandboxed_sdk_macro.bzl", _android_sandboxed_sdk_macro = "android_sandboxed_sdk_macro") - -visibility(PROJECT_VISIBILITY) - -def android_sandboxed_sdk( - name, - sdk_modules_config, - deps, - min_sdk_version, - target_sdk_version = 34, - visibility = None, - testonly = None, - tags = [], - custom_package = None, - proguard_specs = []): - """Rule to build an Android Sandboxed SDK. - - A sandboxed SDK is a collection of libraries that can run independently in the Privacy Sandbox - or in a separate split APK of an app. See: - https://developer.android.com/design-for-safety/privacy-sandbox. - - Args: - name: Unique name of this target. - sdk_modules_config: Module config for this SDK. For full definition see - https://github.com/google/bundletool/blob/master/src/main/proto/sdk_modules_config.proto - deps: Set of android libraries that make up this SDK. - min_sdk_version: Min SDK version for the SDK. - target_sdk_version: Target SDK version for the SDK. - visibility: A list of targets allowed to depend on this rule. - testonly: Whether this library is only for testing. - tags: A list of string tags passed to generated targets. - custom_package: 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. You can specify - a different package but this is highly discouraged since it can introduce classpath - conflicts with other libraries that will only be detected at runtime. - proguard_specs: Proguard specs to use for the SDK. If specified, will also include an implicitly generated spec. - """ - - _android_sandboxed_sdk_macro( - name = name, - sdk_modules_config = sdk_modules_config, - deps = deps, - min_sdk_version = min_sdk_version, - target_sdk_version = target_sdk_version, - visibility = visibility, - testonly = testonly, - tags = tags, - custom_package = custom_package, - proguard_specs = proguard_specs, - android_binary = _android_binary_macro, - )
diff --git a/rules/android_sandboxed_sdk/android_sandboxed_sdk_bundle.bzl b/rules/android_sandboxed_sdk/android_sandboxed_sdk_bundle.bzl deleted file mode 100644 index 3c35b2b..0000000 --- a/rules/android_sandboxed_sdk/android_sandboxed_sdk_bundle.bzl +++ /dev/null
@@ -1,107 +0,0 @@ -# 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. -# 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. -"""Rule for creating an Android Sandboxed SDK Bundle (ASB).""" - -load("//providers:providers.bzl", "AndroidSandboxedSdkBundleInfo", "AndroidSandboxedSdkInfo") -load( - "//rules:aapt.bzl", - _aapt = "aapt", -) -load( - "//rules:bundletool.bzl", - _bundletool = "bundletool", -) -load( - "//rules:common.bzl", - _common = "common", -) -load( - "//rules:utils.bzl", - _get_android_toolchain = "get_android_toolchain", -) -load("//rules:visibility.bzl", "PROJECT_VISIBILITY") - -visibility(PROJECT_VISIBILITY) - -_ATTRS = dict( - sdk = attr.label( - providers = [ - [AndroidSandboxedSdkInfo], - ], - ), - _host_javabase = attr.label( - cfg = "exec", - default = Label("//tools/jdk:current_java_runtime"), - ), -) - -def _impl(ctx): - host_javabase = _common.get_host_javabase(ctx) - - # Convert internal APK to proto resources. - internal_proto_apk = ctx.actions.declare_file(ctx.label.name + "_internal_proto_apk") - _aapt.convert( - ctx, - out = internal_proto_apk, - input = ctx.attr.sdk[AndroidSandboxedSdkInfo].internal_apk_info.unsigned_apk, - to_proto = True, - aapt = _get_android_toolchain(ctx).aapt2.files_to_run, - ) - - # Invoke module builder to create a base.zip that bundletool accepts. - module_zip = ctx.actions.declare_file(ctx.label.name + "_module.zip") - _bundletool.build_sdk_module( - ctx, - out = module_zip, - internal_apk = internal_proto_apk, - bundletool_module_builder = - _get_android_toolchain(ctx).bundletool_module_builder.files_to_run, - host_javabase = host_javabase, - ) - - # Invoke bundletool and create the bundle. - _bundletool.build_sdk_bundle( - ctx, - out = ctx.outputs.asb, - module = module_zip, - sdk_api_descriptors = ctx.attr.sdk[AndroidSandboxedSdkInfo].sdk_api_descriptors, - sdk_modules_config = ctx.attr.sdk[AndroidSandboxedSdkInfo].sdk_module_config, - bundletool = _get_android_toolchain(ctx).bundletool.files_to_run, - host_javabase = host_javabase, - ) - - return [ - AndroidSandboxedSdkBundleInfo( - asb = ctx.outputs.asb, - sdk_info = ctx.attr.sdk[AndroidSandboxedSdkInfo], - ), - ] - -android_sandboxed_sdk_bundle = rule( - attrs = _ATTRS, - executable = False, - implementation = _impl, - provides = [ - AndroidSandboxedSdkBundleInfo, - ], - outputs = { - "asb": "%{name}.asb", - }, - toolchains = [ - "//toolchains/android:toolchain_type", - "//toolchains/android_sdk:toolchain_type", - "@bazel_tools//tools/jdk:toolchain_type", - ], - fragments = ["android"], -)
diff --git a/rules/android_sandboxed_sdk/android_sandboxed_sdk_macro.bzl b/rules/android_sandboxed_sdk/android_sandboxed_sdk_macro.bzl deleted file mode 100644 index 9a38eee..0000000 --- a/rules/android_sandboxed_sdk/android_sandboxed_sdk_macro.bzl +++ /dev/null
@@ -1,214 +0,0 @@ -# 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. -# 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. -"""Bazel rule for defining an Android Sandboxed SDK.""" - -load("//providers:providers.bzl", "AndroidSandboxedSdkInfo", "ApkInfo") -load( - "//rules:common.bzl", - _common = "common", -) -load("//rules:java.bzl", _java = "java") -load( - "//rules:sandboxed_sdk_toolbox.bzl", - _sandboxed_sdk_toolbox = "sandboxed_sdk_toolbox", -) -load( - "//rules:utils.bzl", - _get_android_toolchain = "get_android_toolchain", -) -load("//rules:visibility.bzl", "PROJECT_VISIBILITY") - -visibility(PROJECT_VISIBILITY) - -_ATTRS = dict( - java_package_name = attr.string(), - sdk_modules_config = attr.label( - allow_single_file = [".pb.json"], - ), - internal_android_binary = attr.label(), - sdk_deploy_jar = attr.label( - allow_single_file = [".jar"], - ), - _host_javabase = attr.label( - cfg = "exec", - default = Label("//tools/jdk:current_java_runtime"), - ), -) - -def _impl(ctx): - validation = ctx.actions.declare_file(ctx.label.name + "_validation") - _sandboxed_sdk_toolbox.validate_modules_config( - ctx, - output = validation, - sdk_module_config = ctx.file.sdk_modules_config, - java_package_name = ctx.attr.java_package_name, - sandboxed_sdk_toolbox = _get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run, - host_javabase = _common.get_host_javabase(ctx), - ) - sdk_api_descriptors = ctx.actions.declare_file(ctx.label.name + "_sdk_api_descriptors.jar") - _sandboxed_sdk_toolbox.extract_api_descriptors( - ctx, - output = sdk_api_descriptors, - sdk_deploy_jar = ctx.file.sdk_deploy_jar, - sandboxed_sdk_toolbox = _get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run, - host_javabase = _common.get_host_javabase(ctx), - ) - return [ - DefaultInfo( - files = depset([sdk_api_descriptors]), - ), - AndroidSandboxedSdkInfo( - internal_apk_info = ctx.attr.internal_android_binary[ApkInfo], - sdk_module_config = ctx.file.sdk_modules_config, - sdk_api_descriptors = sdk_api_descriptors, - ), - OutputGroupInfo(_validation = depset([validation])), - ] - -_android_sandboxed_sdk = rule( - attrs = _ATTRS, - executable = False, - implementation = _impl, - provides = [ - AndroidSandboxedSdkInfo, - ], - toolchains = [ - "//toolchains/android:toolchain_type", - "@bazel_tools//tools/jdk:toolchain_type", - ], -) - -def _android_sandboxed_sdk_generate_proguard_specs_impl(ctx): - proguard_specs = ctx.actions.declare_file(ctx.label.name + "_proguard_specs.pgcfg") - _sandboxed_sdk_toolbox.generate_sdk_proguard_specs( - ctx, - output = proguard_specs, - sdk_module_config = ctx.file.sdk_modules_config, - sandboxed_sdk_toolbox = _get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run, - host_javabase = _common.get_host_javabase(ctx), - ) - return [ - DefaultInfo( - files = depset([proguard_specs]), - ), - ] - -_android_sandboxed_sdk_generate_proguard_specs = rule( - attrs = dict( - sdk_modules_config = attr.label( - allow_single_file = [".pb.json"], - ), - _host_javabase = attr.label( - cfg = "exec", - default = Label("//tools/jdk:current_java_runtime"), - ), - ), - executable = False, - implementation = _android_sandboxed_sdk_generate_proguard_specs_impl, - toolchains = [ - "//toolchains/android:toolchain_type", - "@bazel_tools//tools/jdk:toolchain_type", - ], -) - -def android_sandboxed_sdk_macro( - name, - sdk_modules_config, - deps, - min_sdk_version, - target_sdk_version = 34, - visibility = None, - testonly = None, - tags = [], - custom_package = None, - proguard_specs = [], - android_binary = None): - """Macro for an Android Sandboxed SDK. - - Args: - name: Unique name of this target. - sdk_modules_config: Module config for this SDK. - deps: Set of android libraries that make up this SDK. - min_sdk_version: Min SDK version for the SDK. - target_sdk_version: Target SDK version for the SDK. - visibility: A list of targets allowed to depend on this rule. - testonly: Whether this library is only for testing. - tags: A list of string tags passed to generated targets. - custom_package: Java package for resources. This needs to be the same as the package set in - the sdk_modules_config. - proguard_specs: Proguard specs to use for the SDK. - android_binary: android_binary rule used to create the intermediate SDK APK. - """ - fully_qualified_name = "//%s:%s" % (native.package_name(), name) - package = _java.resolve_package_from_label(Label(fully_qualified_name), custom_package) - - # Sandboxed SDK treated as shared library and also could include native code. - # Shared libraries with native code must support both 32 and 64 bit architectures. - # To allow installation on device, generated manifest should have mutliArch=true - manifest_label = Label("%s_gen_manifest" % fully_qualified_name) - native.genrule( - name = manifest_label.name, - outs = [name + "/AndroidManifest.xml"], - cmd = """cat > $@ <<EOF -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="{package}"> - <uses-sdk android:minSdkVersion="{min_sdk_version}" android:targetSdkVersion="{target_sdk_version}" /> - <application android:multiArch="true" /> -</manifest> -EOF -""".format( - package = package, - min_sdk_version = min_sdk_version, - target_sdk_version = target_sdk_version, - ), - ) - - bin_fqn = "%s_bin" % fully_qualified_name - bin_label = Label(bin_fqn) - - result_proguard_specs = [] - if proguard_specs: - result_proguard_specs.extend(proguard_specs) - generated_proguard_spec_label = Label("%s_gen_proguard_specs" % fully_qualified_name) - _android_sandboxed_sdk_generate_proguard_specs( - name = generated_proguard_spec_label.name, - sdk_modules_config = sdk_modules_config, - ) - result_proguard_specs.append(generated_proguard_spec_label) - - android_binary( - name = bin_label.name, - manifest = str(manifest_label), - generate_art_profile = False, - deps = deps, - testonly = testonly, - tags = tags, - use_r_package = True, - shrink_resources = 0, - proguard_specs = result_proguard_specs, - custom_package = custom_package, - ) - - sdk_deploy_jar = Label("%s_deploy.jar" % bin_fqn) - _android_sandboxed_sdk( - name = name, - java_package_name = package, - sdk_modules_config = sdk_modules_config, - visibility = visibility, - testonly = testonly, - tags = tags, - internal_android_binary = bin_label, - sdk_deploy_jar = sdk_deploy_jar, - )
diff --git a/rules/android_sandboxed_sdk/asar_import.bzl b/rules/android_sandboxed_sdk/asar_import.bzl deleted file mode 100644 index b053753..0000000 --- a/rules/android_sandboxed_sdk/asar_import.bzl +++ /dev/null
@@ -1,71 +0,0 @@ -# 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. -# 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. -"""Rule for importing an Android Sandboxed SDK archive for further processing.""" - -load("//providers:providers.bzl", "AndroidArchivedSandboxedSdkInfo") -load( - "//rules:attrs.bzl", - _attrs = "attrs", -) -load( - "//rules:common.bzl", - _common = "common", -) -load( - "//rules:sandboxed_sdk_toolbox.bzl", - _sandboxed_sdk_toolbox = "sandboxed_sdk_toolbox", -) -load( - "//rules:utils.bzl", - _get_android_toolchain = "get_android_toolchain", -) -load("//rules:visibility.bzl", "PROJECT_VISIBILITY") - -visibility(PROJECT_VISIBILITY) - -def _impl(ctx): - sdk_api_descriptors = ctx.actions.declare_file(ctx.label.name + "_sdk_api_descriptors.jar") - _sandboxed_sdk_toolbox.extract_api_descriptors_from_asar( - ctx, - output = sdk_api_descriptors, - asar = ctx.file.asar, - sandboxed_sdk_toolbox = _get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run, - host_javabase = _common.get_host_javabase(ctx), - ) - return [ - AndroidArchivedSandboxedSdkInfo( - asar = ctx.file.asar, - sdk_api_descriptors = sdk_api_descriptors, - ), - ] - -asar_import = rule( - attrs = _attrs.add( - dict( - asar = attr.label( - allow_single_file = [".asar"], - ), - ), - _attrs.JAVA_RUNTIME, - ), - executable = False, - implementation = _impl, - provides = [ - AndroidArchivedSandboxedSdkInfo, - ], - toolchains = [ - "//toolchains/android:toolchain_type", - "@bazel_tools//tools/jdk:toolchain_type", - ], -)
diff --git a/rules/bundletool.bzl b/rules/bundletool.bzl index 20562e0..f6c5cbc 100644 --- a/rules/bundletool.bzl +++ b/rules/bundletool.bzl
@@ -403,14 +403,10 @@ ctx, out = None, proto_apk = None, - runtime_enabled_sdk_config = None, bundletool_module_builder = None): inputs = [proto_apk] args = ctx.actions.args() args.add("--internal_apk_path", proto_apk) - if runtime_enabled_sdk_config: - args.add("--runtime_enabled_sdk_config_path", runtime_enabled_sdk_config) - inputs.append(runtime_enabled_sdk_config) args.add("--output_module_path", out) ctx.actions.run(
diff --git a/rules/rules.bzl b/rules/rules.bzl index af06e80..8a09c0e 100644 --- a/rules/rules.bzl +++ b/rules/rules.bzl
@@ -53,18 +53,7 @@ "//rules/android_local_test:rule.bzl", _android_local_test = "android_local_test", ) -load( - "//rules/android_sandboxed_sdk:android_sandboxed_sdk.bzl", - _android_sandboxed_sdk = "android_sandboxed_sdk", -) -load( - "//rules/android_sandboxed_sdk:android_sandboxed_sdk_bundle.bzl", - _android_sandboxed_sdk_bundle = "android_sandboxed_sdk_bundle", -) -load( - "//rules/android_sandboxed_sdk:asar_import.bzl", - _asar_import = "asar_import", -) + load( "//rules/android_sdk_repository:rule.bzl", _android_sdk_repository = "android_sdk_repository", @@ -78,12 +67,11 @@ android_binary = _android_binary android_library = _android_library android_local_test = _android_local_test -android_sandboxed_sdk = _android_sandboxed_sdk -android_sandboxed_sdk_bundle = _android_sandboxed_sdk_bundle + android_sdk = _android_sdk android_sdk_repository = _android_sdk_repository android_tools_defaults_jar = _android_tools_defaults_jar -asar_import = _asar_import + instrumented_app_info_aspect = _instrumented_app_info_aspect StarlarkApkInfo = _StarlarkApkInfo ApkInfo = _ApkInfo
diff --git a/rules/sandboxed_sdk_toolbox.bzl b/rules/sandboxed_sdk_toolbox.bzl deleted file mode 100644 index 560844a..0000000 --- a/rules/sandboxed_sdk_toolbox.bzl +++ /dev/null
@@ -1,377 +0,0 @@ -# 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. -# 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. -"""Bazel SandboxedSdkToolbox commands.""" - -load("//rules:visibility.bzl", "PROJECT_VISIBILITY") -load(":java.bzl", _java = "java") - -visibility(PROJECT_VISIBILITY) - -def _extract_api_descriptors( - ctx, - output = None, - sdk_deploy_jar = None, - sandboxed_sdk_toolbox = None, - host_javabase = None): - """Extracts API descriptors from a sandboxed SDK classpath. - - The API descriptors can later be used to generate sources for communicating with this SDK. - - Args: - ctx: The context. - output: Output API descriptors jar file. - sdk_deploy_jar: The SDK classpath, with transitive dependencies. - sandboxed_sdk_toolbox: Toolbox executable files. - host_javabase: Javabase used to run the toolbox. - """ - args = ctx.actions.args() - args.add("extract-api-descriptors") - args.add("--sdk-deploy-jar", sdk_deploy_jar) - args.add("--output-sdk-api-descriptors", output) - _java.run( - ctx = ctx, - host_javabase = host_javabase, - executable = sandboxed_sdk_toolbox, - arguments = [args], - inputs = [sdk_deploy_jar], - outputs = [output], - mnemonic = "ExtractApiDescriptors", - progress_message = "Extract SDK API descriptors %s" % output.short_path, - ) - -def _extract_api_descriptors_from_asar( - ctx, - output = None, - asar = None, - sandboxed_sdk_toolbox = None, - host_javabase = None): - """Extracts API descriptors from a sandboxed SDK archive. - - The API descriptors can later be used to generate sources for communicating with this SDK. - - Args: - ctx: The context. - output: Output API descriptors jar file. - asar: The sandboxed sdk archive. - sandboxed_sdk_toolbox: Toolbox executable files. - host_javabase: Javabase used to run the toolbox. - """ - args = ctx.actions.args() - args.add("extract-api-descriptors-from-asar") - args.add("--asar", asar) - args.add("--output-sdk-api-descriptors", output) - _java.run( - ctx = ctx, - host_javabase = host_javabase, - executable = sandboxed_sdk_toolbox, - arguments = [args], - inputs = [asar], - outputs = [output], - mnemonic = "ExtractApiDescriptorsFromAsar", - progress_message = "Extract SDK API descriptors from ASAR %s" % output.short_path, - ) - -def _generate_client_sources( - ctx, - output_kotlin_dir = None, - output_java_dir = None, - sdk_api_descriptors = None, - aidl_compiler = None, - framework_aidl = None, - sandboxed_sdk_toolbox = None, - host_javabase = None): - """Generate Kotlin and Java sources for SDK communication. - - Args: - ctx: The context. - output_kotlin_dir: Directory for Kotlin source tree. It depends on the Java sources. - output_java_dir: Directory for Java source tree. Doesn't depend on Kotlin sources. - sdk_api_descriptors: SDK API descriptor jar. - aidl_compiler: Executable files for the AOSP AIDL compiler. - framework_aidl: Framework.aidl file used to compile AIDL sources. - sandboxed_sdk_toolbox: Toolbox executable files. - host_javabase: Javabase used to run the toolbox. - """ - args = ctx.actions.args() - args.add("generate-client-sources") - args.add("--sdk-api-descriptors", sdk_api_descriptors) - args.add("--aidl-compiler", aidl_compiler) - args.add("--framework-aidl", framework_aidl) - args.add("--output-kotlin-dir", output_kotlin_dir.path) - args.add("--output-java-dir", output_java_dir.path) - _java.run( - ctx = ctx, - host_javabase = host_javabase, - executable = sandboxed_sdk_toolbox, - arguments = [args], - inputs = [ - sdk_api_descriptors, - aidl_compiler, - framework_aidl, - ], - outputs = [output_kotlin_dir, output_java_dir], - mnemonic = "GenClientSources", - progress_message = "Generate client sources for %s" % output_kotlin_dir.short_path, - ) - -def _generate_runtime_enabled_sdk_config( - ctx, - output = None, - manifest_xml_tree = None, - sdk_module_configs = None, - sdk_archives = None, - debug_key = None, - sandboxed_sdk_toolbox = None, - host_javabase = None): - inputs = [debug_key, manifest_xml_tree] - args = ctx.actions.args() - args.add("generate-runtime-enabled-sdk-config") - args.add("--manifest-xml-tree", manifest_xml_tree) - 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") - args.add("--output-config", output) - _java.run( - ctx = ctx, - host_javabase = host_javabase, - executable = sandboxed_sdk_toolbox, - arguments = [args], - inputs = inputs, - outputs = [output], - mnemonic = "GenRuntimeEnabledSdkConfig", - progress_message = "Generate RuntimeEnabledSdkConfig proto message %s" % output.short_path, - ) - -def _generate_runtime_enabled_sdk_table( - ctx, - output = None, - sdk_archives = None, - sdk_module_configs = None, - sandboxed_sdk_toolbox = None, - host_javabase = None): - """Generates a XML file with metadata expected by the SDK Runtime library. - - This will be used to load sandboxed SDKs in compatibility mode on devices without the sandbox. - - Args: - ctx: The context. - output: Output XML file. - sdk_archives: List of SDK archives, as ASAR files. They will also be listed as dependencies. - sdk_module_configs: List of SDK Module config JSON files with SDK packages and versions. - sandboxed_sdk_toolbox: Toolbox executable files. - host_javabase: Javabase used to run the toolbox. - """ - inputs = [] - args = ctx.actions.args() - args.add("generate-runtime-enabled-sdk-table") - 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("--output-table", output) - _java.run( - ctx = ctx, - host_javabase = host_javabase, - executable = sandboxed_sdk_toolbox, - arguments = [args], - inputs = inputs, - outputs = [output], - mnemonic = "GenRuntimeEnabledSdkTable", - progress_message = "Generate SDK dependencies XML metadata for app %s" % output.short_path, - ) - -def _generate_sdk_dependencies_manifest( - ctx, - output = None, - manifest_package = None, - sdk_module_configs = None, - sdk_archives = None, - debug_key = None, - sandboxed_sdk_toolbox = None, - host_javabase = None): - """Generates a manifest that lists all sandboxed SDK dependencies. - - The generated manifest will contain <uses-sdk-library> tags for each SDK. This is required for - loading the SDK in the Privacy Sandbox. - - Args: - ctx: The context. - 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. - 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) - 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") - args.add("--output-manifest", output) - _java.run( - ctx = ctx, - host_javabase = host_javabase, - executable = sandboxed_sdk_toolbox, - arguments = [args], - inputs = inputs, - outputs = [output], - mnemonic = "GenSdkDepManifest", - progress_message = "Generate SDK dependencies manifest %s" % output.short_path, - ) - -def _generate_sdk_proguard_specs( - ctx, - output = None, - sdk_module_config = None, - sandboxed_sdk_toolbox = None, - host_javabase = None): - """Generates Proguard specs for an SDK. - - Args: - ctx: The context. - output: File. The output generated proguard spec. - sdk_module_config: SDK Module config JSON file from an SDK bundle. - sandboxed_sdk_toolbox: Toolbox executable files. - host_javabase: Javabase used to run the toolbox. - """ - args = ctx.actions.args() - args.add("generate-sdk-proguard-specs") - args.add("--sdk-modules-config", sdk_module_config) - args.add("--output", output) - _java.run( - ctx = ctx, - host_javabase = host_javabase, - executable = sandboxed_sdk_toolbox, - arguments = [args], - inputs = [sdk_module_config], - outputs = [output], - mnemonic = "GenerateSdkProguardSpecs", - progress_message = "Generating Proguard specs for SDK %s" % output.short_path, - ) - -def _generate_sdk_split_properties( - ctx, - output = None, - sdk_archive = None, - sdk_module_config = None, - runtime_enabled_sdk_config = None, - manifest_xml_tree = None, - sandboxed_sdk_toolbox = None, - host_javabase = None): - """Generates the SdkSplitPropertiesInheritiedFromApp proto message. - - This message is used by Bundletool to create an app split that contains the sandboxed SDK. - This is the deployment format of sandboxed SDKs on devices that don't have the Privacy Sandbox. - - Args: - ctx: The context. - output: File where the final manifest will be written. - sdk_archive: SDK archive as an ASAR file. Exactly one of sdk_archive or sdk_module_config - must be set. - sdk_module_config: SDK Module config JSON file form an SDK bundle. Exactly one of sdk_archive - or sdk_module_config must be set. - runtime_enabled_sdk_config: A RuntimeEnabledSdkConfig file with all the SDKs targeted by the - host app, including the target SDK. - manifest_xml_tree: A file with the AAPT2's xmltree dump of the host app manifest. - This will be used to read the app id, version code and minSdkVersion. - sandboxed_sdk_toolbox: Toolbox executable files. - host_javabase: Javabase used to run the toolbox. - """ - if (bool(sdk_archive) == bool(sdk_module_config)): - fail("Exactly one of sdk_archive or sdk_module_config must be set in %s" % ctx.label.name) - inputs = [runtime_enabled_sdk_config, manifest_xml_tree] - args = ctx.actions.args() - args.add("generate-sdk-split-properties") - args.add("--runtime-enabled-sdk-config", runtime_enabled_sdk_config) - args.add("--manifest-xml-tree", manifest_xml_tree) - if sdk_module_config: - args.add("--sdk-modules-config", sdk_module_config) - inputs.append(sdk_module_config) - if sdk_archive: - args.add("--sdk-archive", sdk_archive) - inputs.append(sdk_archive) - args.add("--output-properties", output) - _java.run( - ctx = ctx, - host_javabase = host_javabase, - executable = sandboxed_sdk_toolbox, - arguments = [args], - inputs = inputs, - outputs = [output], - mnemonic = "GenSdkSplitProperties", - progress_message = "Generate SDK split properties %s" % output.short_path, - ) - -def _validate_modules_config( - ctx, - output = None, - sdk_module_config = None, - java_package_name = None, - sandboxed_sdk_toolbox = None, - host_javabase = None): - """Validates an SDK modules config file and ensures it has a valid package name. - - Args: - ctx: The context. - output: The output file. It will only be created if the validation succeeds. - sdk_module_config: SDK Module config JSON file form an SDK bundle. - java_package_name: The java package name to use for the SDK. - sandboxed_sdk_toolbox: Toolbox executable files. - host_javabase: Javabase used to run the toolbox. - """ - args = ctx.actions.args() - args.add("validate-modules-config") - args.add("--sdk-modules-config", sdk_module_config) - args.add("--java-package-name", java_package_name) - args.add("--output", output) - _java.run( - ctx = ctx, - host_javabase = host_javabase, - executable = sandboxed_sdk_toolbox, - arguments = [args], - inputs = [sdk_module_config], - outputs = [output], - mnemonic = "ValidateModulesConfig", - progress_message = "Validating SDK modules config %s" % output.short_path, - ) - -sandboxed_sdk_toolbox = struct( - extract_api_descriptors = _extract_api_descriptors, - extract_api_descriptors_from_asar = _extract_api_descriptors_from_asar, - generate_client_sources = _generate_client_sources, - generate_runtime_enabled_sdk_config = _generate_runtime_enabled_sdk_config, - generate_runtime_enabled_sdk_table = _generate_runtime_enabled_sdk_table, - generate_sdk_dependencies_manifest = _generate_sdk_dependencies_manifest, - generate_sdk_proguard_specs = _generate_sdk_proguard_specs, - generate_sdk_split_properties = _generate_sdk_split_properties, - validate_modules_config = _validate_modules_config, -)
diff --git a/toolchains/android/toolchain.bzl b/toolchains/android/toolchain.bzl index 8789dbd..ce8b61c 100644 --- a/toolchains/android/toolchain.bzl +++ b/toolchains/android/toolchain.bzl
@@ -250,12 +250,7 @@ allow_files = True, default = "//rules:robolectric_properties_template.txt", ), - sandboxed_sdk_toolbox = attr.label( - allow_single_file = True, - cfg = "exec", - default = "//src/tools/java/com/google/devtools/build/android/sandboxedsdktoolbox:sandboxed_sdk_toolbox_deploy.jar", - executable = True, - ), + shuffle_jars = attr.label( cfg = "exec", default = Label("//tools/android:shuffle_jars"),