blob: 3265148ea25a4c563d6f6733ccf37d465b5b5764 [file] [log] [blame]
Spandan Das81593892022-09-06 17:31:48 +00001// Copyright 2022 Google Inc. 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
15package android
16
17import (
18 "github.com/google/blueprint"
19
20 "android/soong/bazel"
21)
22
23func init() {
24 RegisterApiDomainBuildComponents(InitRegistrationContext)
25}
26
27func RegisterApiDomainBuildComponents(ctx RegistrationContext) {
28 ctx.RegisterModuleType("api_domain", ApiDomainFactory)
29}
30
Spandan Das1278c2c2022-08-19 18:17:28 +000031type ApiSurface int
32
33// TODO(b/246656800): Reconcile with android.SdkKind
34const (
35 PublicApi ApiSurface = iota
36 SystemApi
37 VendorApi
38)
39
40func (a ApiSurface) String() string {
41 switch a {
42 case PublicApi:
43 return "publicapi"
44 case SystemApi:
45 return "systemapi"
46 case VendorApi:
47 return "vendorapi"
48 default:
49 return "invalid"
50 }
51}
52
Spandan Das81593892022-09-06 17:31:48 +000053type apiDomain struct {
54 ModuleBase
55 BazelModuleBase
56
57 properties apiDomainProperties
58}
59
60type apiDomainProperties struct {
61 // cc library contributions (.h files/.map.txt) of this API domain
62 // This dependency is a no-op in Soong, but the corresponding Bazel target in the bp2build workspace will provide a `CcApiContributionInfo` provider
63 Cc_api_contributions []string
64}
65
66func ApiDomainFactory() Module {
67 m := &apiDomain{}
68 m.AddProperties(&m.properties)
69 InitAndroidArchModule(m, DeviceSupported, MultilibBoth)
Spandan Das81593892022-09-06 17:31:48 +000070 return m
71}
72
Spandan Daseb6b9072022-10-08 04:29:37 +000073// Do not create any dependency edges in Soong for now to skip visibility checks for some systemapi libraries.
74// Currently, all api_domain modules reside in build/orchestrator/apis/Android.bp
75// However, cc libraries like libsigchain (com.android.art) restrict their visibility to art/*
76// When the api_domain module types are collocated with their contributions, this dependency edge can be restored
Spandan Das81593892022-09-06 17:31:48 +000077func (a *apiDomain) DepsMutator(ctx BottomUpMutatorContext) {
Spandan Das81593892022-09-06 17:31:48 +000078}
79
80// API domain does not have any builld actions yet
81func (a *apiDomain) GenerateAndroidBuildActions(ctx ModuleContext) {
82}
83
84const (
85 apiContributionSuffix = ".contribution"
86)
87
88// ApiContributionTargetName returns the name of the bp2build target (e.g. cc_api_contribution) of contribution modules (e.g. ndk_library)
89// A suffix is necessary to prevent a name collision with the base target in the same bp2build bazel package
90func ApiContributionTargetName(moduleName string) string {
91 return moduleName + apiContributionSuffix
92}
93
94// For each contributing cc_library, format the name to its corresponding contribution bazel target in the bp2build workspace
95func contributionBazelAttributes(ctx TopDownMutatorContext, contributions []string) bazel.LabelListAttribute {
96 addSuffix := func(ctx BazelConversionPathContext, module blueprint.Module) string {
97 baseLabel := BazelModuleLabel(ctx, module)
98 return ApiContributionTargetName(baseLabel)
99 }
100 bazelLabels := BazelLabelForModuleDepsWithFn(ctx, contributions, addSuffix)
101 return bazel.MakeLabelListAttribute(bazelLabels)
102}
103
104type bazelApiDomainAttributes struct {
105 Cc_api_contributions bazel.LabelListAttribute
106}
107
Spandan Das8b4a5f32022-09-29 00:28:24 +0000108var _ ApiProvider = (*apiDomain)(nil)
109
110func (a *apiDomain) ConvertWithApiBp2build(ctx TopDownMutatorContext) {
Spandan Das81593892022-09-06 17:31:48 +0000111 props := bazel.BazelTargetModuleProperties{
112 Rule_class: "api_domain",
113 Bzl_load_location: "//build/bazel/rules/apis:api_domain.bzl",
114 }
115 attrs := &bazelApiDomainAttributes{
116 Cc_api_contributions: contributionBazelAttributes(ctx, a.properties.Cc_api_contributions),
117 }
118 ctx.CreateBazelTargetModule(props, CommonAttributes{
119 Name: ctx.ModuleName(),
120 }, attrs)
121}