Merge changes from topic "api_export"
* changes: Allowlist conversion of api providing module types Multi-tree API bp2build converter for ndk_library
This commit is contained in:
@@ -554,12 +554,15 @@ var (
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bp2buildModuleTypeAlwaysConvertList = []string{
|
Bp2buildModuleTypeAlwaysConvertList = []string{
|
||||||
|
"aidl_interface_headers",
|
||||||
|
"api_domain",
|
||||||
"license",
|
"license",
|
||||||
"linker_config",
|
"linker_config",
|
||||||
"java_import",
|
"java_import",
|
||||||
"java_import_host",
|
"java_import_host",
|
||||||
|
"ndk_headers",
|
||||||
|
"ndk_library",
|
||||||
"sysprop_library",
|
"sysprop_library",
|
||||||
"aidl_interface_headers",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Bp2buildModuleDoNotConvertList = []string{
|
Bp2buildModuleDoNotConvertList = []string{
|
||||||
|
@@ -28,6 +28,28 @@ func RegisterApiDomainBuildComponents(ctx RegistrationContext) {
|
|||||||
ctx.RegisterModuleType("api_domain", ApiDomainFactory)
|
ctx.RegisterModuleType("api_domain", ApiDomainFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ApiSurface int
|
||||||
|
|
||||||
|
// TODO(b/246656800): Reconcile with android.SdkKind
|
||||||
|
const (
|
||||||
|
PublicApi ApiSurface = iota
|
||||||
|
SystemApi
|
||||||
|
VendorApi
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a ApiSurface) String() string {
|
||||||
|
switch a {
|
||||||
|
case PublicApi:
|
||||||
|
return "publicapi"
|
||||||
|
case SystemApi:
|
||||||
|
return "systemapi"
|
||||||
|
case VendorApi:
|
||||||
|
return "vendorapi"
|
||||||
|
default:
|
||||||
|
return "invalid"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type apiDomain struct {
|
type apiDomain struct {
|
||||||
ModuleBase
|
ModuleBase
|
||||||
BazelModuleBase
|
BazelModuleBase
|
||||||
|
77
bp2build/ndk_library_conversion_test.go
Normal file
77
bp2build/ndk_library_conversion_test.go
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
// 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 bp2build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"android/soong/cc"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNdkLibraryContributionSymbolFile(t *testing.T) {
|
||||||
|
bp := `
|
||||||
|
ndk_library {
|
||||||
|
name: "libfoo",
|
||||||
|
symbol_file: "libfoo.map.txt",
|
||||||
|
}
|
||||||
|
`
|
||||||
|
expectedBazelTarget := MakeBazelTargetNoRestrictions(
|
||||||
|
"cc_api_contribution",
|
||||||
|
"libfoo.ndk.contribution",
|
||||||
|
AttrNameToString{
|
||||||
|
"api": `"libfoo.map.txt"`,
|
||||||
|
"api_surfaces": `["publicapi"]`,
|
||||||
|
"library_name": `"libfoo"`,
|
||||||
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
RunBp2BuildTestCase(t, cc.RegisterNdkModuleTypes, Bp2buildTestCase{
|
||||||
|
Blueprint: bp,
|
||||||
|
ExpectedBazelTargets: []string{expectedBazelTarget},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNdkLibraryContributionHeaders(t *testing.T) {
|
||||||
|
bp := `
|
||||||
|
ndk_library {
|
||||||
|
name: "libfoo",
|
||||||
|
symbol_file: "libfoo.map.txt",
|
||||||
|
export_header_libs: ["libfoo_headers"],
|
||||||
|
}
|
||||||
|
`
|
||||||
|
fs := map[string]string{
|
||||||
|
"header_directory/Android.bp": `
|
||||||
|
ndk_headers {
|
||||||
|
name: "libfoo_headers",
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
expectedBazelTarget := MakeBazelTargetNoRestrictions(
|
||||||
|
"cc_api_contribution",
|
||||||
|
"libfoo.ndk.contribution",
|
||||||
|
AttrNameToString{
|
||||||
|
"api": `"libfoo.map.txt"`,
|
||||||
|
"api_surfaces": `["publicapi"]`,
|
||||||
|
"library_name": `"libfoo"`,
|
||||||
|
"hdrs": `["//header_directory:libfoo_headers.contribution"]`,
|
||||||
|
"target_compatible_with": `["//build/bazel/platforms/os:android"]`,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
RunBp2BuildTestCase(t, cc.RegisterNdkModuleTypes, Bp2buildTestCase{
|
||||||
|
Blueprint: bp,
|
||||||
|
Filesystem: fs,
|
||||||
|
ExpectedBazelTargets: []string{expectedBazelTarget},
|
||||||
|
})
|
||||||
|
}
|
5
cc/cc.go
5
cc/cc.go
@@ -3650,6 +3650,7 @@ const (
|
|||||||
sharedLibrary
|
sharedLibrary
|
||||||
headerLibrary
|
headerLibrary
|
||||||
testBin // testBinary already declared
|
testBin // testBinary already declared
|
||||||
|
ndkLibrary
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Module) typ() moduleType {
|
func (c *Module) typ() moduleType {
|
||||||
@@ -3686,6 +3687,8 @@ func (c *Module) typ() moduleType {
|
|||||||
return staticLibrary
|
return staticLibrary
|
||||||
}
|
}
|
||||||
return sharedLibrary
|
return sharedLibrary
|
||||||
|
} else if c.isNDKStubLibrary() {
|
||||||
|
return ndkLibrary
|
||||||
}
|
}
|
||||||
return unknownType
|
return unknownType
|
||||||
}
|
}
|
||||||
@@ -3726,6 +3729,8 @@ func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
|
|||||||
} else {
|
} else {
|
||||||
sharedOrStaticLibraryBp2Build(ctx, c, false)
|
sharedOrStaticLibraryBp2Build(ctx, c, false)
|
||||||
}
|
}
|
||||||
|
case ndkLibrary:
|
||||||
|
ndkLibraryBp2build(ctx, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/google/blueprint/proptools"
|
"github.com/google/blueprint/proptools"
|
||||||
|
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
|
"android/soong/bazel"
|
||||||
"android/soong/cc/config"
|
"android/soong/cc/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -568,5 +569,43 @@ func newStubLibrary() *Module {
|
|||||||
func NdkLibraryFactory() android.Module {
|
func NdkLibraryFactory() android.Module {
|
||||||
module := newStubLibrary()
|
module := newStubLibrary()
|
||||||
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
|
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
|
||||||
|
android.InitBazelModule(module)
|
||||||
return module
|
return module
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type bazelCcApiContributionAttributes struct {
|
||||||
|
Api bazel.LabelAttribute
|
||||||
|
Api_surfaces bazel.StringListAttribute
|
||||||
|
Hdrs bazel.LabelListAttribute
|
||||||
|
Library_name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Names of the cc_api_header targets in the bp2build workspace
|
||||||
|
func (s *stubDecorator) apiHeaderLabels(ctx android.TopDownMutatorContext) bazel.LabelList {
|
||||||
|
addSuffix := func(ctx android.BazelConversionPathContext, module blueprint.Module) string {
|
||||||
|
label := android.BazelModuleLabel(ctx, module)
|
||||||
|
return android.ApiContributionTargetName(label)
|
||||||
|
}
|
||||||
|
return android.BazelLabelForModuleDepsWithFn(ctx, s.properties.Export_header_libs, addSuffix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ndkLibraryBp2build(ctx android.TopDownMutatorContext, m *Module) {
|
||||||
|
props := bazel.BazelTargetModuleProperties{
|
||||||
|
Rule_class: "cc_api_contribution",
|
||||||
|
Bzl_load_location: "//build/bazel/rules/apis:cc_api_contribution.bzl",
|
||||||
|
}
|
||||||
|
stubLibrary := m.compiler.(*stubDecorator)
|
||||||
|
attrs := &bazelCcApiContributionAttributes{
|
||||||
|
Library_name: stubLibrary.implementationModuleName(m.Name()),
|
||||||
|
Api_surfaces: bazel.MakeStringListAttribute(
|
||||||
|
[]string{android.PublicApi.String()}),
|
||||||
|
}
|
||||||
|
if symbolFile := stubLibrary.properties.Symbol_file; symbolFile != nil {
|
||||||
|
apiLabel := android.BazelLabelForModuleSrcSingle(ctx, proptools.String(symbolFile)).Label
|
||||||
|
attrs.Api = *bazel.MakeLabelAttribute(apiLabel)
|
||||||
|
}
|
||||||
|
apiHeaders := stubLibrary.apiHeaderLabels(ctx)
|
||||||
|
attrs.Hdrs = bazel.MakeLabelListAttribute(apiHeaders)
|
||||||
|
apiContributionTargetName := android.ApiContributionTargetName(ctx.ModuleName())
|
||||||
|
ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: apiContributionTargetName}, attrs)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user