Skip to content

Commit

Permalink
Traverse toolchain edges rather than the _toolchain attr in dex_desug…
Browse files Browse the repository at this point in the history
…ar_aspect

PiperOrigin-RevId: 682426965
Change-Id: Ibbdd5023134b9788c7a6a58577b2fb5325dff6dd
  • Loading branch information
nreid260 authored and copybara-github committed Oct 4, 2024
1 parent adb64f8 commit e90b26d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
1 change: 1 addition & 0 deletions rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ bzl_library(
"baseline_profiles.bzl",
"dex.bzl",
"dex_desugar_aspect.bzl",
"dex_toolchains.bzl",
"rules.bzl",
],
visibility = [
Expand Down
42 changes: 27 additions & 15 deletions rules/dex_desugar_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,24 @@ load("@rules_java//java/common:java_info.bzl", "JavaInfo")
load(":attrs.bzl", _attrs = "attrs")
load(":desugar.bzl", _desugar = "desugar")
load(":dex.bzl", _dex = "dex")
load(":dex_toolchains.bzl", "dex_toolchains")
load(":min_sdk_version.bzl", _min_sdk_version = "min_sdk_version")
load(":utils.bzl", "ANDROID_SDK_TOOLCHAIN_TYPE", _get_android_sdk = "get_android_sdk", _utils = "utils")

visibility(PROJECT_VISIBILITY)

_tristate = _attrs.tristate

def _aspect_attrs():
"""Attrs of the rule requiring traversal by the aspect."""
return [
"_aidl_lib", # for the aidl runtime on android_library
"deps",
"exports",
"runtime",
"runtime_deps",
"_aspect_proto_toolchain_for_javalite", # To get from proto_library through proto_lang_toolchain rule to proto runtime library.
"_build_stamp_deps", # for build stamp runtime class deps
"_build_stamp_mergee_manifest_lib", # for empty build stamp Service class implementation
"_toolchain", # to get Kotlin toolchain component in android_library
]
_ATTR_ASPECTS = [
"_aidl_lib", # for the aidl runtime on android_library
"deps",
"exports",
"runtime",
"runtime_deps",
"_aspect_proto_toolchain_for_javalite", # To get from proto_library through proto_lang_toolchain rule to proto runtime library.
"_build_stamp_deps", # for build stamp runtime class deps
"_build_stamp_mergee_manifest_lib", # for empty build stamp Service class implementation
]

# Also used by the android_binary rule
def get_aspect_deps(ctx):
Expand All @@ -51,7 +49,7 @@ def get_aspect_deps(ctx):
deps_list: List of all deps of the dex_desugar_aspect that requires traversal.
"""
deps_list = []
for attr in _aspect_attrs():
for attr in _ATTR_ASPECTS:
# android_binary's deps attr has a split transition, so when
# this is called from android_binary, deps should be accessed
# via ctx.split_attr instead of ctx.attr to ensure that the same
Expand All @@ -68,6 +66,12 @@ def get_aspect_deps(ctx):
elif str(type(deps)) == "Target":
deps_list.append(deps)

deps_list.extend([
ctx.toolchains[toolchain_type]
for toolchain_type in dex_toolchains
if (toolchain_type in ctx.toolchains)
])

return deps_list

def _aspect_impl(target, ctx):
Expand Down Expand Up @@ -227,9 +231,16 @@ def _power_set(items):

return power_set

def _opt_kwargs():
"""Optional args to pass to the aspect definition if Bazel supports them."""
result = {}
if dex_toolchains:
result["toolchains_aspects"] = dex_toolchains
return result

dex_desugar_aspect = aspect(
implementation = _aspect_impl,
attr_aspects = _aspect_attrs(),
attr_aspects = _ATTR_ASPECTS,
attrs = _attrs.add(
{
"_desugar_java8": attr.label(
Expand All @@ -253,4 +264,5 @@ dex_desugar_aspect = aspect(
ANDROID_SDK_TOOLCHAIN_TYPE,
],
required_aspect_providers = [[JavaInfo]],
**_opt_kwargs()
)
17 changes: 17 additions & 0 deletions rules/dex_toolchains.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 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.
"""Toolchain types to traverse in dex_desugar_aspect."""

dex_toolchains = [
]

0 comments on commit e90b26d

Please sign in to comment.