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
Test: m nothing
Change-Id: Iba9799e111ca5672b2133568163d8c49837ba9cd
This commit is contained in:
Paul Duffin
2020-03-17 21:04:24 +00:00
parent 3a4eb50829
commit a551a1c2f9
3 changed files with 70 additions and 29 deletions

View File

@@ -1914,35 +1914,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 {
@@ -1950,7 +1953,7 @@ func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberConte
}
}
propertySet.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
// TODO(b/151933053) - add aidl include dirs property
}
}
@@ -2127,8 +2130,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) {
@@ -2139,21 +2142,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)
}
}