1# Copyright 2023 The Bazel Authors. All rights reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Rule for importing an Android Sandboxed SDK archive for further processing.""" 16 17load( 18 "//rules:attrs.bzl", 19 _attrs = "attrs", 20) 21load( 22 "//rules:common.bzl", 23 _common = "common", 24) 25load( 26 "//rules:sandboxed_sdk_toolbox.bzl", 27 _sandboxed_sdk_toolbox = "sandboxed_sdk_toolbox", 28) 29load( 30 "//rules:utils.bzl", 31 _get_android_toolchain = "get_android_toolchain", 32) 33load(":providers.bzl", "AndroidArchivedSandboxedSdkInfo") 34 35def _impl(ctx): 36 sdk_api_descriptors = ctx.actions.declare_file(ctx.label.name + "_sdk_api_descriptors.jar") 37 _sandboxed_sdk_toolbox.extract_api_descriptors_from_asar( 38 ctx, 39 output = sdk_api_descriptors, 40 asar = ctx.file.asar, 41 sandboxed_sdk_toolbox = _get_android_toolchain(ctx).sandboxed_sdk_toolbox.files_to_run, 42 host_javabase = _common.get_host_javabase(ctx), 43 ) 44 return [ 45 AndroidArchivedSandboxedSdkInfo( 46 asar = ctx.file.asar, 47 sdk_api_descriptors = sdk_api_descriptors, 48 ), 49 ] 50 51asar_import = rule( 52 attrs = _attrs.add( 53 dict( 54 asar = attr.label( 55 allow_single_file = [".asar"], 56 ), 57 ), 58 _attrs.JAVA_RUNTIME, 59 ), 60 executable = False, 61 implementation = _impl, 62 provides = [ 63 AndroidArchivedSandboxedSdkInfo, 64 ], 65 toolchains = [ 66 "//toolchains/android:toolchain_type", 67 "@bazel_tools//tools/jdk:toolchain_type", 68 ], 69) 70