• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2022 The Android Open Source Project
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"""Bazel rules for generating the metadata of API domain contributions to an API surface"""
16
17load(":api_surface.bzl", "ALL_API_SURFACES")
18load(":cc_api_contribution.bzl", "CcApiContributionInfo")
19load(":java_api_contribution.bzl", "JavaApiContributionInfo")
20
21def _api_domain_impl(ctx):
22    """Implementation of the api_domain rule
23    Currently it only supports exporting the API surface contributions of the API domain
24    """
25    out = []
26    for api_surface in ALL_API_SURFACES:
27        # TODO(b/220938703): Add other contributions (e.g. resource_api_contribution)
28        # cc
29        cc_libraries = [cc[CcApiContributionInfo] for cc in ctx.attr.cc_api_contributions if api_surface in cc[CcApiContributionInfo].api_surfaces]
30
31        # java
32        java_libraries = [java[JavaApiContributionInfo] for java in ctx.attr.java_api_contributions if api_surface in java[JavaApiContributionInfo].api_surfaces]
33
34        # The contributions of an API domain are always at ver=current
35        # Contributions of an API domain to previous Android SDKs will be snapshot and imported into the build graph by a separate Bazel rule
36        api_surface_metadata = struct(
37            name = api_surface,
38            version = "current",
39            api_domain = ctx.attr.name,
40            cc_libraries = cc_libraries,
41            java_libraries = java_libraries,
42        )
43        api_surface_filestem = "-".join([api_surface, "current", ctx.attr.name])
44        api_surface_file = ctx.actions.declare_file(api_surface_filestem + ".json")
45        ctx.actions.write(api_surface_file, json.encode(api_surface_metadata))
46        out.append(api_surface_file)
47
48    return [DefaultInfo(files = depset(out))]
49
50api_domain = rule(
51    implementation = _api_domain_impl,
52    attrs = {
53        "cc_api_contributions": attr.label_list(providers = [CcApiContributionInfo]),
54        "java_api_contributions": attr.label_list(providers = [JavaApiContributionInfo]),
55    },
56)
57