Improve consistency of handling java snapshot properties

Previously, java snapshot properties (java_library and java_test)
relied on the properties not being optimized when there was a single os
type and instead being added directly to the common os type properties.
However, that means that the behavior is inconsistent for other member
types depending on whether there was one os type or not.

This change updates the java sdk member handling to support
optimization. This involved:
1) Adding AidlIncludeDirs field to librarySdkMemberProperties to
   specify the aidl include dirs instead of extracting that from the
   library field.

2) Renaming jarToExport to JarToExport (in both
   library/testSdkMemberProperties)to allow it to be optimized.

3) Adding MemberType() and Name() methods to SdkMemberPropertiesContext
   to avoid having to store the former in the properties struct and
   retrieve the latter from the library/test fields.

4) Removing the now unused library/test fields from the properties
   structures.

5) Separating the processing of the jar/test config in
   AddToPropertySet(...) as they may be optimized separately.

6) Ditto for the jar/aidl include dirs.

7) While doing this work I noticed that although the contents of the
   aidl include dirs are copied into the snapshot the java_import does
   not make use of them. Raised bug 151933053 and added TODO to track
   that work.

Bug: 142935992
Bug: 153306490
Test: m nothing
Merged-In: Iba9799e111ca5672b2133568163d8c49837ba9cd
Change-Id: Iba9799e111ca5672b2133568163d8c49837ba9cd
This commit is contained in:
Paul Duffin 2020-03-17 21:04:24 +00:00
parent 17ab883cb0
commit c9103930a4
3 changed files with 70 additions and 29 deletions

View file

@ -465,14 +465,29 @@ func RegisterSdkMemberType(memberType SdkMemberType) {
// Contains common properties that apply across many different member types. These
// are not affected by the optimization to extract common values.
type SdkMemberPropertiesBase struct {
// The setting to use for the compile_multilib property.
Compile_multilib string `sdk:"keep"`
// The number of unique os types supported by the member variants.
//
// If a member has a variant with more than one os type then it will need to differentiate
// the locations of any of their prebuilt files in the snapshot by os type to prevent them
// from colliding. See OsPrefix().
//
// This property is the same for all variants of a member and so would be optimized away
// if it was not explicitly kept.
Os_count int `sdk:"keep"`
// The os type for which these properties refer.
//
// Provided to allow a member to differentiate between os types in the locations of their
// prebuilt files when it supports more than one os type.
//
// This property is the same for all os type specific variants of a member and so would be
// optimized away if it was not explicitly kept.
Os OsType `sdk:"keep"`
// The setting to use for the compile_multilib property.
//
// This property is set after optimization so there is no point in trying to optimize it.
Compile_multilib string `sdk:"keep"`
}
// The os prefix to use for any file paths in the sdk.
@ -515,4 +530,13 @@ type SdkMemberContext interface {
// The builder of the snapshot.
SnapshotBuilder() SnapshotBuilder
// The type of the member.
MemberType() SdkMemberType
// The name of the member.
//
// Provided for use by sdk members to create a member specific location within the snapshot
// into which to copy the prebuilt files.
Name() string
}

View file

@ -1896,35 +1896,38 @@ func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext,
}
func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
return &librarySdkMemberProperties{memberType: mt}
return &librarySdkMemberProperties{}
}
type librarySdkMemberProperties struct {
android.SdkMemberPropertiesBase
memberType *librarySdkMemberType
library *Library
jarToExport android.Path
JarToExport android.Path
AidlIncludeDirs android.Paths
}
func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
j := variant.(*Library)
p.library = j
p.jarToExport = p.memberType.jarToExportGetter(j)
p.JarToExport = ctx.MemberType().(*librarySdkMemberType).jarToExportGetter(j)
p.AidlIncludeDirs = j.AidlIncludeDirs()
}
func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
if p.jarToExport != nil {
sdkModuleContext := ctx.SdkModuleContext()
builder := ctx.SnapshotBuilder()
builder := ctx.SnapshotBuilder()
exportedJar := p.jarToExport
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.library.Name())
exportedJar := p.JarToExport
if exportedJar != nil {
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name())
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
for _, dir := range p.library.AidlIncludeDirs() {
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
}
aidlIncludeDirs := p.AidlIncludeDirs
if len(aidlIncludeDirs) != 0 {
sdkModuleContext := ctx.SdkModuleContext()
for _, dir := range aidlIncludeDirs {
// TODO(jiyong): copy parcelable declarations only
aidlFiles, _ := sdkModuleContext.GlobWithDeps(dir.String()+"/**/*.aidl", nil)
for _, file := range aidlFiles {
@ -1932,7 +1935,7 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte
}
}
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
// TODO(b/151933053) - add aidl include dirs property
}
}
@ -2110,8 +2113,8 @@ func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberPr
type testSdkMemberProperties struct {
android.SdkMemberPropertiesBase
test *Test
jarToExport android.Path
JarToExport android.Path
TestConfig android.Path
}
func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
@ -2122,21 +2125,25 @@ func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberConte
panic(fmt.Errorf("there must be only one implementation jar from %q", test.Name()))
}
p.test = test
p.jarToExport = implementationJars[0]
p.JarToExport = implementationJars[0]
p.TestConfig = test.testConfig
}
func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
if p.jarToExport != nil {
builder := ctx.SnapshotBuilder()
builder := ctx.SnapshotBuilder()
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.test.Name())
builder.CopyToSnapshot(p.jarToExport, snapshotRelativeJavaLibPath)
snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), p.test.Name(), testConfigSuffix)
builder.CopyToSnapshot(p.test.testConfig, snapshotRelativeTestConfigPath)
exportedJar := p.JarToExport
if exportedJar != nil {
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), ctx.Name())
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
}
testConfig := p.TestConfig
if testConfig != nil {
snapshotRelativeTestConfigPath := sdkSnapshotFilePathForMember(p.OsPrefix(), ctx.Name(), testConfigSuffix)
builder.CopyToSnapshot(testConfig, snapshotRelativeTestConfigPath)
propertySet.AddProperty("test_config", snapshotRelativeTestConfigPath)
}
}

View file

@ -255,7 +255,7 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
for _, member := range members {
memberType := member.memberType
memberCtx := &memberContext{ctx, builder}
memberCtx := &memberContext{ctx, builder, memberType, member.name}
prebuiltModule := memberType.AddPrebuiltModule(memberCtx, member)
if prebuiltModule == nil {
@ -1087,6 +1087,8 @@ func newLinkSpecificInfo(ctx android.SdkMemberContext, linkType string, variantP
type memberContext struct {
sdkMemberContext android.ModuleContext
builder *snapshotBuilder
memberType android.SdkMemberType
name string
}
func (m *memberContext) SdkModuleContext() android.ModuleContext {
@ -1097,6 +1099,14 @@ func (m *memberContext) SnapshotBuilder() android.SnapshotBuilder {
return m.builder
}
func (m *memberContext) MemberType() android.SdkMemberType {
return m.memberType
}
func (m *memberContext) Name() string {
return m.name
}
func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule android.BpModule) {
memberType := member.memberType