From 7fe8990d8761a928801d993f1a80f2d50c2be6d6 Mon Sep 17 00:00:00 2001 From: Ted Xie Date: Thu, 3 Aug 2023 10:53:42 -0700 Subject: [PATCH] Open-source mobile_install/{dependency_map,tools}.bzl Part of #12 PiperOrigin-RevId: 553527234 Change-Id: Idd51e592fb8dccdfefb9fe7ca57004f2d6fb0529 --- mobile_install/dependency_map.bzl | 63 +++++++++ mobile_install/tools.bzl | 204 ++++++++++++++++++++++++++++++ tools/android/BUILD | 12 ++ tools/jdk/BUILD | 12 ++ 4 files changed, 291 insertions(+) create mode 100644 mobile_install/dependency_map.bzl create mode 100644 mobile_install/tools.bzl diff --git a/mobile_install/dependency_map.bzl b/mobile_install/dependency_map.bzl new file mode 100644 index 000000000..2769a9007 --- /dev/null +++ b/mobile_install/dependency_map.bzl @@ -0,0 +1,63 @@ +# Copyright 2022 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 file keeps track of the locations of binaries for Mobile-Install.""" + +versioned_deps = struct( + mi_shell_app = struct( + head = "//tools/android:fail", + ), + android_kit = struct( + head = "//src/tools/ak", + ), + bootstraper = struct( + head = "//tools/android:fail", + ), + deploy = struct( + head = "//src/tools/mi/deployment:deploy_binary", + ), + deploy_info = struct( + head = "//src/tools/mi/deploy_info:deploy_info", + ), + forwarder = struct( + head = "//tools/android:fail", + ), + jar_tool = struct( + head = "@bazel_tools//tools/jdk:JavaBuilder_deploy.jar", + ), + make_sync = struct( + head = "//src/tools/mi/app_info:make_sync", + ), + merge_syncs = struct( + head = "//src/tools/mi/workspace:merge_syncs", + ), + pack_dexes = struct( + head = "//src/tools/mi/workspace:pack_dexes", + ), + pack_generic = struct( + head = "//src/tools/mi/workspace:pack_generic", + ), + res_v3_dummy_manifest = struct( + head = "//rules:res_v3_dummy_AndroidManifest.xml", + ), + res_v3_dummy_r_txt = struct( + head = "//rules:res_v3_dummy_R.txt", + ), + resource_extractor = struct( + head = "//src/tools/resource_extractor:main", + ), + sync_merger = struct( + head = "//src/tools/mi/app_info:sync_merger", + ), +) diff --git a/mobile_install/tools.bzl b/mobile_install/tools.bzl new file mode 100644 index 000000000..508677927 --- /dev/null +++ b/mobile_install/tools.bzl @@ -0,0 +1,204 @@ +# Copyright 2018 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. +"""Tools needed by the mobile-install aspect defined as aspect attributes.""" + +load(":dependency_map.bzl", "versioned_deps") + +TOOL_ATTRS = dict( + # Target Attrs + # This library should not be versioned. It needs to be built with the same + # config that is used to build the app. Android binds the application to a + # concrete achitecture during install time. If no libs are on the apk, it + # will select the most specific to the device is running. We want to use + # whatever the user builds as long as it is compatible. And since we push + # the native libs outside the apk to speed up transfer times, we need to + # use dummy libs. + _android_sdk = attr.label( + default = Label( + "@androidsdk//:sdk", + ), + allow_files = True, + cfg = "target", + ), + _flags = attr.label( + default = Label( + "//rules/flags", + ), + ), + _studio_deployer = attr.label( + default = "@androidsdk//:fail", # TODO(#119): Studio deployer jar to be released + allow_single_file = True, + cfg = "exec", + executable = True, + ), + _mi_shell_dummy_native_libs = attr.label( + default = Label( + "@androidsdk//:fail", # FIXME: Unused internally + ), + allow_single_file = True, + cfg = "target", + ), + _mi_shell_app = attr.label( + default = versioned_deps.mi_shell_app.head, + allow_files = True, + cfg = "target", + executable = True, + ), + _mi_java8_legacy_dex = attr.label( + default = Label("//tools/android:java8_legacy_dex"), + allow_single_file = True, + cfg = "target", + ), + + # Host Attrs + _aapt2 = attr.label( + default = Label( + "@androidsdk//:aapt2_binary", + ), + allow_single_file = True, + cfg = "exec", + executable = True, + ), + _android_test_runner = attr.label( + default = Label( + "@bazel_tools//tools/jdk:TestRunner_deploy.jar", + ), + allow_single_file = True, + cfg = "exec", + executable = True, + ), + _apk_signer = attr.label( + default = Label("@androidsdk//:apksigner"), + allow_files = True, + cfg = "exec", + executable = True, + ), + _desugar_java8 = attr.label( + default = Label("//tools/android:desugar_java8"), + allow_files = True, + cfg = "exec", + executable = True, + ), + _d8 = attr.label( + default = Label("@bazel_tools//src/tools/android/java/com/google/devtools/build/android/r8:r8"), + allow_files = True, + cfg = "exec", + executable = True, + ), + _host_java_runtime = attr.label( + default = Label("//tools/jdk:current_host_java_runtime"), + cfg = "exec", + ), + _java_jdk = attr.label( + default = Label("//tools/jdk:current_java_runtime"), + allow_files = True, + cfg = "exec", + ), + _resource_busybox = attr.label( + default = Label("@bazel_tools//src/tools/android/java/com/google/devtools/build/android:ResourceProcessorBusyBox_deploy.jar"), + allow_files = True, + cfg = "exec", + executable = True, + ), + _zipalign = attr.label( + default = Label( + "@androidsdk//:zipalign_binary", + ), + allow_single_file = True, + cfg = "exec", + executable = True, + ), + + + # Versioned Host Attrs + _android_kit = attr.label( + default = versioned_deps.android_kit.head, + allow_files = True, + cfg = "exec", + executable = True, + ), + _deploy = attr.label( + default = versioned_deps.deploy.head, + allow_files = True, + cfg = "exec", + executable = True, + ), + _deploy_info = attr.label( + default = versioned_deps.deploy_info.head, + allow_files = True, + cfg = "exec", + executable = True, + ), + _jar_tool = attr.label( + default = versioned_deps.jar_tool.head, + allow_files = True, + cfg = "exec", + executable = True, + ), + _make_sync = attr.label( + default = versioned_deps.make_sync.head, + allow_files = True, + cfg = "exec", + executable = True, + ), + _merge_syncs = attr.label( + default = versioned_deps.merge_syncs.head, + allow_files = True, + cfg = "exec", + executable = True, + ), + _mi_android_java_toolchain = attr.label( + default = Label("//tools/jdk:toolchain_android_only"), + ), + _mi_java_toolchain = attr.label( + cfg = "exec", + default = Label("//tools/jdk:toolchain"), + ), + _mi_host_javabase = attr.label( + default = Label("//tools/jdk:current_host_java_runtime"), + ), + _pack_dexes = attr.label( + default = versioned_deps.pack_dexes.head, + allow_files = True, + cfg = "exec", + executable = True, + ), + _pack_generic = attr.label( + default = versioned_deps.pack_generic.head, + allow_files = True, + cfg = "exec", + executable = True, + ), + _res_v3_dummy_manifest = attr.label( + allow_single_file = True, + default = versioned_deps.res_v3_dummy_manifest.head, + ), + _res_v3_dummy_r_txt = attr.label( + allow_single_file = True, + default = versioned_deps.res_v3_dummy_r_txt.head, + ), + _resource_extractor = attr.label( + allow_single_file = True, + cfg = "exec", + default = versioned_deps.resource_extractor.head, + executable = True, + ), + _sync_merger = attr.label( + default = versioned_deps.sync_merger.head, + allow_files = True, + cfg = "exec", + executable = True, + ), + +) diff --git a/tools/android/BUILD b/tools/android/BUILD index 7a85b590e..376cb7f70 100644 --- a/tools/android/BUILD +++ b/tools/android/BUILD @@ -40,3 +40,15 @@ java_plugin( "@bazel_tools//src/tools/android/java/com/google/devtools/build/android:all_android_tools", ], ) + +alias( + name = "java8_legacy_dex", + actual = "@bazel_tools//tools/android:java8_legacy_dex", + visibility = ["//visibility:public"], +) + +alias( + name = "desugar_java8", + actual = "@bazel_tools//tools/android:desugar_java8", + visibility = ["//visibility:public"], +) diff --git a/tools/jdk/BUILD b/tools/jdk/BUILD index d83484bda..5c4095566 100644 --- a/tools/jdk/BUILD +++ b/tools/jdk/BUILD @@ -10,8 +10,20 @@ default_java_toolchain( visibility = ["//visibility:public"], ) +alias( + name = "toolchain", + actual = "@bazel_tools//tools/jdk:toolchain", + visibility = ["//visibility:public"], +) + alias( name = "current_java_runtime", actual = "@bazel_tools//tools/jdk:current_java_runtime", visibility = ["//visibility:public"], ) + +alias( + name = "current_host_java_runtime", + actual = "@bazel_tools//tools/jdk:current_host_java_runtime", + visibility = ["//visibility:public"], +)