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:
Spandan Das
2022-09-22 20:49:16 +00:00
committed by Gerrit Code Review
5 changed files with 147 additions and 1 deletions

View File

@@ -3650,6 +3650,7 @@ const (
sharedLibrary
headerLibrary
testBin // testBinary already declared
ndkLibrary
)
func (c *Module) typ() moduleType {
@@ -3686,6 +3687,8 @@ func (c *Module) typ() moduleType {
return staticLibrary
}
return sharedLibrary
} else if c.isNDKStubLibrary() {
return ndkLibrary
}
return unknownType
}
@@ -3726,6 +3729,8 @@ func (c *Module) ConvertWithBp2build(ctx android.TopDownMutatorContext) {
} else {
sharedOrStaticLibraryBp2Build(ctx, c, false)
}
case ndkLibrary:
ndkLibraryBp2build(ctx, c)
}
}

View File

@@ -25,6 +25,7 @@ import (
"github.com/google/blueprint/proptools"
"android/soong/android"
"android/soong/bazel"
"android/soong/cc/config"
)
@@ -568,5 +569,43 @@ func newStubLibrary() *Module {
func NdkLibraryFactory() android.Module {
module := newStubLibrary()
android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibBoth)
android.InitBazelModule(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)
}