Add support for using cc_library in sdk/module_exports
Added link type support in module creation code as cc_prebuilt_library
has to provide both shared and static libraries.
Had to add some calls to FirstUniquePaths() around the include dirs
settings in library_sdk_member as otherwise the shared variant contains
duplicate include dirs (presumably because it gets one set from its
dependency on the static variant and one set of its own). That
difference in include dirs causes problems in the generated
cc_prebuilt_library.
Test: m nothing
Bug: 142918168
Change-Id: Ie7f23fc2341c83c7814cc98e3970df4f5d4c8423
diff --git a/sdk/update.go b/sdk/update.go
index c622ddf..ce25fc4 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -21,6 +21,7 @@
"strings"
"android/soong/apex"
+ "android/soong/cc"
"github.com/google/blueprint"
"github.com/google/blueprint/proptools"
@@ -866,6 +867,9 @@
var archPropertiesList []android.SdkMemberProperties
for _, archInfo := range osInfo.archInfos {
+ // Optimize the arch properties first.
+ archInfo.optimizeProperties(commonValueExtractor)
+
archPropertiesList = append(archPropertiesList, archInfo.Properties)
}
@@ -961,32 +965,107 @@
baseInfo
archType android.ArchType
+
+ linkInfos []*linkTypeSpecificInfo
}
// Create a new archTypeSpecificInfo for the specified arch type and its properties
// structures populated with information from the variants.
func newArchSpecificInfo(archType android.ArchType, variantPropertiesFactory variantPropertiesFactoryFunc, archVariants []android.SdkAware) *archTypeSpecificInfo {
- if len(archVariants) != 1 {
- panic(fmt.Errorf("expected one arch specific variant but found %d", len(archVariants)))
- }
-
// Create an arch specific info into which the variant properties can be copied.
archInfo := &archTypeSpecificInfo{archType: archType}
// Create the properties into which the arch type specific properties will be
// added.
archInfo.Properties = variantPropertiesFactory()
- archInfo.Properties.PopulateFromVariant(archVariants[0])
+
+ if len(archVariants) == 1 {
+ archInfo.Properties.PopulateFromVariant(archVariants[0])
+ } else {
+ // There is more than one variant for this arch type which must be differentiated
+ // by link type.
+ for _, linkVariant := range archVariants {
+ linkType := getLinkType(linkVariant)
+ if linkType == "" {
+ panic(fmt.Errorf("expected one arch specific variant as it is not identified by link type but found %d", len(archVariants)))
+ } else {
+ linkInfo := newLinkSpecificInfo(linkType, variantPropertiesFactory, linkVariant)
+
+ archInfo.linkInfos = append(archInfo.linkInfos, linkInfo)
+ }
+ }
+ }
return archInfo
}
+// Get the link type of the variant
+//
+// If the variant is not differentiated by link type then it returns "",
+// otherwise it returns one of "static" or "shared".
+func getLinkType(variant android.Module) string {
+ linkType := ""
+ if linkable, ok := variant.(cc.LinkableInterface); ok {
+ if linkable.Shared() && linkable.Static() {
+ panic(fmt.Errorf("expected variant %q to be either static or shared but was both", variant.String()))
+ } else if linkable.Shared() {
+ linkType = "shared"
+ } else if linkable.Static() {
+ linkType = "static"
+ } else {
+ panic(fmt.Errorf("expected variant %q to be either static or shared but was neither", variant.String()))
+ }
+ }
+ return linkType
+}
+
+// Optimize the properties by extracting common properties from link type specific
+// properties into arch type specific properties.
+func (archInfo *archTypeSpecificInfo) optimizeProperties(commonValueExtractor *commonValueExtractor) {
+ if len(archInfo.linkInfos) == 0 {
+ return
+ }
+
+ var propertiesList []android.SdkMemberProperties
+ for _, linkInfo := range archInfo.linkInfos {
+ propertiesList = append(propertiesList, linkInfo.Properties)
+ }
+
+ commonValueExtractor.extractCommonProperties(archInfo.Properties, propertiesList)
+}
+
// Add the properties for an arch type to a property set.
func (archInfo *archTypeSpecificInfo) addToPropertySet(builder *snapshotBuilder, archPropertySet android.BpPropertySet, archOsPrefix string) {
archTypeName := archInfo.archType.Name
archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + archTypeName)
archInfo.Properties.AddToPropertySet(builder.ctx, builder, archTypePropertySet)
+
+ for _, linkInfo := range archInfo.linkInfos {
+ linkPropertySet := archTypePropertySet.AddPropertySet(linkInfo.linkType)
+ linkInfo.Properties.AddToPropertySet(builder.ctx, builder, linkPropertySet)
+ }
+}
+
+type linkTypeSpecificInfo struct {
+ baseInfo
+
+ linkType string
+}
+
+// Create a new linkTypeSpecificInfo for the specified link type and its properties
+// structures populated with information from the variant.
+func newLinkSpecificInfo(linkType string, variantPropertiesFactory variantPropertiesFactoryFunc, linkVariant android.SdkAware) *linkTypeSpecificInfo {
+ linkInfo := &linkTypeSpecificInfo{
+ baseInfo: baseInfo{
+ // Create the properties into which the link type specific properties will be
+ // added.
+ Properties: variantPropertiesFactory(),
+ },
+ linkType: linkType,
+ }
+ linkInfo.Properties.PopulateFromVariant(linkVariant)
+ return linkInfo
}
func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, builder *snapshotBuilder, member *sdkMember, bpModule android.BpModule) {