Make new module creation API more flexible

Previously passing additional information to the implementations of
AddPrebuiltModule() or the SdkMemberProperties interface would have
required making changes to the API. This change added an
SdkMemberContext object into which additional information can easily
be added without requiring changes to existing implementations.

The BuildSnapshot() method was not modified because it is deprecated
and will be removed in a follow up change.

It also switches the API from passing variants as android.SdkAware to
android.Module. That is for a couple of reasons:
1) SdkAware is designed for managing the relationship between the
   module and the SDK, not for generating the output snapshot. As such
   there is nothing in SdkAware that is needed for generating the
   output snapshot.
2) Accepting android.Module instead makes it easier to use the
   underlying code for generating the snapshot module as well as the
   individual member modules.

This is in preparation for a number of improvements and bug fixes in
both the snapshot creation code and implementations to address found
while trying to built the platform against ART prebuilts.

Bug: 151937654
Bug: 153306490
Test: m nothing
Merged-In: Iac10f1200c0f283aa35402167eec8f9aeb65a38e
Change-Id: Iac10f1200c0f283aa35402167eec8f9aeb65a38e
This commit is contained in:
Paul Duffin
2020-03-19 16:11:18 +00:00
parent 5e2e0fd191
commit 17ab883cb0
5 changed files with 77 additions and 49 deletions

View File

@@ -1891,8 +1891,8 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
return ok
}
func (mt *librarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule {
return builder.AddPrebuiltModule(member, "java_import")
func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import")
}
func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
@@ -1908,15 +1908,18 @@ type librarySdkMemberProperties struct {
jarToExport android.Path
}
func (p *librarySdkMemberProperties) PopulateFromVariant(variant android.SdkAware) {
func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
j := variant.(*Library)
p.library = j
p.jarToExport = p.memberType.jarToExportGetter(j)
}
func (p *librarySdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) {
func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
if p.jarToExport != nil {
sdkModuleContext := ctx.SdkModuleContext()
builder := ctx.SnapshotBuilder()
exportedJar := p.jarToExport
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.library.Name())
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
@@ -2096,8 +2099,8 @@ func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
return ok
}
func (mt *testSdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule {
return builder.AddPrebuiltModule(member, "java_test_import")
func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import")
}
func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
@@ -2111,7 +2114,7 @@ type testSdkMemberProperties struct {
jarToExport android.Path
}
func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware) {
func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
test := variant.(*Test)
implementationJars := test.ImplementationJars()
@@ -2123,8 +2126,10 @@ func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware)
p.jarToExport = implementationJars[0]
}
func (p *testSdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) {
func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
if p.jarToExport != nil {
builder := ctx.SnapshotBuilder()
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.test.Name())
builder.CopyToSnapshot(p.jarToExport, snapshotRelativeJavaLibPath)