Parameterize the sdk member processing
Extracts the type specific functionality into the SdkMemberType interface which has to be implemented by each module type that can be added as a member of the sdk. It provides functionality to add the required dependencies for the module type, check to see if a resolved module is the correct instance and build the snapshot. The latter was previously part of SdkAware but was moved because it has to be able to process multiple SdkAware variants so delegating it to a single instance did not make sense. The custom code for handling each member type specific property, e.g. java_libs, has been replaced with common code that processes a list of sdkMemberListProperty struct which associates the property (name and getter) with the SdkMemberType and a special DependencyTag which is passed to the SdkMemberType when it has to add dependencies. The DependencyTag contains a reference to the appropriate sdkMemberListProperty which allows the resolved dependencies to be grouped by type. Previously, the dependency collection methods would ignore a module if it was an unsupported type because they did not have a way of determining which property it was initially listed in. That meant it was possible to add say a droidstubs module to the java_libs property (and because they had the same variants) it would work as if it was added to the stubs_sources property. Or alternatively, a module of an unsupported type could be added to any property and it would just be ignored. However, the DependencyTag provides information about which property a resolved module was referenced in and so it can detect when the resolved module is of the wrong type and report an error. That check identified a bug in one of the tests where the sdk referenced a java_import module (which is not allowed in an sdk) instead of a java_library module (which is allowed). That test was fixed as part of this. A list of sdkMemberListProperty structs defines the member properties supported by the sdk and are processed in order to ensure consistent behaviour. The resolved dependencies are grouped by type and each group is then processed in defined order. Within each type dependencies are grouped by name and encapsulated behind an SdkMember interface which includes the name and the list of variants. The Droidstubs and java.Library types can only support one variant and will fail if given more. The processing for the native_shared_libs property has been moved into the cc/library.go file so the sdk package code should now have no type specific information in it apart from what is if the list of sdkMemberListProperty structs. Bug: 143678475 Test: m conscrypt-module-sdk Change-Id: I10203594d33dbf53441f655aff124f9ab3538d87
This commit is contained in:
72
sdk/sdk.go
72
sdk/sdk.go
@@ -27,6 +27,7 @@ import (
|
||||
// registered before mutators in this package. See RegisterPostDepsMutators for more details.
|
||||
_ "android/soong/apex"
|
||||
"android/soong/cc"
|
||||
"android/soong/java"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -37,6 +38,14 @@ func init() {
|
||||
android.RegisterModuleType("sdk_snapshot", SnapshotModuleFactory)
|
||||
android.PreDepsMutators(RegisterPreDepsMutators)
|
||||
android.PostDepsMutators(RegisterPostDepsMutators)
|
||||
|
||||
// Populate the dependency tags for each member list property. This needs to
|
||||
// be done here to break an initialization cycle.
|
||||
for _, memberListProperty := range sdkMemberListProperties {
|
||||
memberListProperty.dependencyTag = &sdkMemberDependencyTag{
|
||||
memberListProperty: memberListProperty,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type sdk struct {
|
||||
@@ -62,6 +71,45 @@ type sdkProperties struct {
|
||||
Snapshot bool `blueprint:"mutated"`
|
||||
}
|
||||
|
||||
type sdkMemberDependencyTag struct {
|
||||
blueprint.BaseDependencyTag
|
||||
memberListProperty *sdkMemberListProperty
|
||||
}
|
||||
|
||||
// Contains information about the sdk properties that list sdk members, e.g.
|
||||
// Java_libs.
|
||||
type sdkMemberListProperty struct {
|
||||
// the name of the property as used in a .bp file
|
||||
name string
|
||||
|
||||
// getter for the list of member names
|
||||
getter func(properties *sdkProperties) []string
|
||||
|
||||
// the type of member referenced in the list
|
||||
memberType android.SdkMemberType
|
||||
|
||||
// the dependency tag used for items in this list.
|
||||
dependencyTag *sdkMemberDependencyTag
|
||||
}
|
||||
|
||||
var sdkMemberListProperties = []*sdkMemberListProperty{
|
||||
{
|
||||
name: "java_libs",
|
||||
getter: func(properties *sdkProperties) []string { return properties.Java_libs },
|
||||
memberType: java.LibrarySdkMemberType,
|
||||
},
|
||||
{
|
||||
name: "stubs_sources",
|
||||
getter: func(properties *sdkProperties) []string { return properties.Stubs_sources },
|
||||
memberType: java.DroidStubsSdkMemberType,
|
||||
},
|
||||
{
|
||||
name: "native_shared_libs",
|
||||
getter: func(properties *sdkProperties) []string { return properties.Native_shared_libs },
|
||||
memberType: cc.LibrarySdkMemberType,
|
||||
},
|
||||
}
|
||||
|
||||
// sdk defines an SDK which is a logical group of modules (e.g. native libs, headers, java libs, etc.)
|
||||
// which Mainline modules like APEX can choose to build with.
|
||||
func ModuleFactory() android.Module {
|
||||
@@ -145,10 +193,6 @@ type dependencyTag struct {
|
||||
blueprint.BaseDependencyTag
|
||||
}
|
||||
|
||||
// For dependencies from an SDK module to its members
|
||||
// e.g. mysdk -> libfoo and libbar
|
||||
var sdkMemberDepTag dependencyTag
|
||||
|
||||
// For dependencies from an in-development version of an SDK member to frozen versions of the same member
|
||||
// e.g. libfoo -> libfoo.mysdk.11 and libfoo.mysdk.12
|
||||
type sdkMemberVesionedDepTag struct {
|
||||
@@ -160,22 +204,10 @@ type sdkMemberVesionedDepTag struct {
|
||||
// Step 1: create dependencies from an SDK module to its members.
|
||||
func memberMutator(mctx android.BottomUpMutatorContext) {
|
||||
if m, ok := mctx.Module().(*sdk); ok {
|
||||
mctx.AddVariationDependencies(nil, sdkMemberDepTag, m.properties.Java_libs...)
|
||||
mctx.AddVariationDependencies(nil, sdkMemberDepTag, m.properties.Stubs_sources...)
|
||||
|
||||
targets := mctx.MultiTargets()
|
||||
for _, target := range targets {
|
||||
for _, lib := range m.properties.Native_shared_libs {
|
||||
name, version := cc.StubsLibNameAndVersion(lib)
|
||||
if version == "" {
|
||||
version = cc.LatestStubsVersionFor(mctx.Config(), name)
|
||||
}
|
||||
mctx.AddFarVariationDependencies(append(target.Variations(), []blueprint.Variation{
|
||||
{Mutator: "image", Variation: android.CoreVariation},
|
||||
{Mutator: "link", Variation: "shared"},
|
||||
{Mutator: "version", Variation: version},
|
||||
}...), sdkMemberDepTag, name)
|
||||
}
|
||||
for _, memberListProperty := range sdkMemberListProperties {
|
||||
names := memberListProperty.getter(&m.properties)
|
||||
tag := memberListProperty.dependencyTag
|
||||
memberListProperty.memberType.AddDependencies(mctx, tag, names)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user