platform_build_soong/android/api_domain.go
Chris Parsons 5f1b3c7ad8 create, but dont register, bp2build_deps mutator
This is the bulk of the "allowlist v2" feature. It will disable bp2build
generation for modules which have transitive dependencies without a
bazel build definition.

This CL includes this mutator, but doesn't register it as a bp2build
mutator (outside of a few unit tests). This allows us to easily iterate
on completion of this feature and ensure there are no launch blockers
before we finalize the change in AOSP.

Bug: 285631638
Test: Unit tests
Change-Id: Ifb0a079c409ca19b02cafa3fab2efa0d3deebc50
2023-10-03 00:16:30 +00:00

93 lines
3 KiB
Go

// Copyright 2022 Google Inc. 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.
package android
func init() {
RegisterApiDomainBuildComponents(InitRegistrationContext)
}
func RegisterApiDomainBuildComponents(ctx RegistrationContext) {
ctx.RegisterModuleType("api_domain", ApiDomainFactory)
}
type ApiSurface int
// TODO(b/246656800): Reconcile with android.SdkKind
const (
// API surface provided by platform and mainline modules to other mainline modules
ModuleLibApi ApiSurface = iota
PublicApi // Aka NDK
VendorApi // Aka LLNDK
)
func (a ApiSurface) String() string {
switch a {
case ModuleLibApi:
return "module-libapi"
case PublicApi:
return "publicapi"
case VendorApi:
return "vendorapi"
default:
return "invalid"
}
}
type apiDomain struct {
ModuleBase
BazelModuleBase
properties apiDomainProperties
}
type apiDomainProperties struct {
// cc library contributions (.h files/.map.txt) of this API domain
// This dependency is a no-op in Soong, but the corresponding Bazel target in the api_bp2build workspace
// will provide a `CcApiContributionInfo` provider
Cc_api_contributions []string
// java library contributions (as .txt) of this API domain
// This dependency is a no-op in Soong, but the corresponding Bazel target in the api_bp2build workspace
// will provide a `JavaApiContributionInfo` provider
Java_api_contributions []string
}
func ApiDomainFactory() Module {
m := &apiDomain{}
m.AddProperties(&m.properties)
InitAndroidArchModule(m, DeviceSupported, MultilibBoth)
return m
}
// Do not create any dependency edges in Soong for now to skip visibility checks for some systemapi libraries.
// Currently, all api_domain modules reside in build/orchestrator/apis/Android.bp
// However, cc libraries like libsigchain (com.android.art) restrict their visibility to art/*
// When the api_domain module types are collocated with their contributions, this dependency edge can be restored
func (a *apiDomain) DepsMutator(ctx BottomUpMutatorContext) {
}
// API domain does not have any builld actions yet
func (a *apiDomain) GenerateAndroidBuildActions(ctx ModuleContext) {
}
const (
apiContributionSuffix = ".contribution"
)
// ApiContributionTargetName returns the name of the bp2build target (e.g. cc_api_contribution) of contribution modules (e.g. ndk_library)
// A suffix is necessary to prevent a name collision with the base target in the same bp2build bazel package
func ApiContributionTargetName(moduleName string) string {
return moduleName + apiContributionSuffix
}