Support header and implementation jars in sdk

Add a new java_header_libs property that exports header jars (as
java_libs currently does) and switch java_libs to export implementation
jars instead.

Refactors implementation of the existing library sdk member type so
both properties can be supported from common code as they differ only
on the jar being exported.

Bug: 143678475
Test: m nothing
Change-Id: I04642122f72d083bbdfd3290624f957b71ee8875
This commit is contained in:
Paul Duffin
2019-12-05 11:25:53 +00:00
parent d835daaade
commit a0dbf43a82
4 changed files with 179 additions and 26 deletions

View File

@@ -1711,18 +1711,16 @@ func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
}
const (
aidlIncludeDir = "aidl"
javaStubDir = "java"
javaStubFileSuffix = ".jar"
aidlIncludeDir = "aidl"
javaDir = "java"
jarFileSuffix = ".jar"
)
// path to the stub file of a java library. Relative to <sdk_root>/<api_dir>
func (j *Library) javaStubFilePathFor() string {
return filepath.Join(javaStubDir, j.Name()+javaStubFileSuffix)
// path to the jar file of a java library. Relative to <sdk_root>/<api_dir>
func (j *Library) sdkSnapshotFilePathForJar() string {
return filepath.Join(javaDir, j.Name()+jarFileSuffix)
}
var LibrarySdkMemberType = &librarySdkMemberType{}
type librarySdkMemberType struct {
}
@@ -1735,7 +1733,12 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
return ok
}
func (mt *librarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
func (mt *librarySdkMemberType) buildSnapshot(
sdkModuleContext android.ModuleContext,
builder android.SnapshotBuilder,
member android.SdkMember,
jarToExportGetter func(j *Library) android.Path) {
variants := member.Variants()
if len(variants) != 1 {
sdkModuleContext.ModuleErrorf("sdk contains %d variants of member %q but only one is allowed", len(variants), member.Name())
@@ -1746,12 +1749,9 @@ func (mt *librarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleCon
variant := variants[0]
j := variant.(*Library)
headerJars := j.HeaderJars()
if len(headerJars) != 1 {
panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
}
snapshotRelativeJavaLibPath := j.javaStubFilePathFor()
builder.CopyToSnapshot(headerJars[0], snapshotRelativeJavaLibPath)
exportedJar := jarToExportGetter(j)
snapshotRelativeJavaLibPath := j.sdkSnapshotFilePathForJar()
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
for _, dir := range j.AidlIncludeDirs() {
// TODO(jiyong): copy parcelable declarations only
@@ -1765,6 +1765,40 @@ func (mt *librarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleCon
module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
}
var HeaderLibrarySdkMemberType = &headerLibrarySdkMemberType{}
type headerLibrarySdkMemberType struct {
librarySdkMemberType
}
func (mt *headerLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path {
headerJars := j.HeaderJars()
if len(headerJars) != 1 {
panic(fmt.Errorf("there must be only one header jar from %q", j.Name()))
}
return headerJars[0]
})
}
var ImplLibrarySdkMemberType = &implLibrarySdkMemberType{}
type implLibrarySdkMemberType struct {
librarySdkMemberType
}
func (mt *implLibrarySdkMemberType) BuildSnapshot(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) {
mt.librarySdkMemberType.buildSnapshot(sdkModuleContext, builder, member, func(j *Library) android.Path {
implementationJars := j.ImplementationJars()
if len(implementationJars) != 1 {
panic(fmt.Errorf("there must be only one implementation jar from %q", j.Name()))
}
return implementationJars[0]
})
}
// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
//
// By default, a java_library has a single variant that produces a `.jar` file containing `.class` files that were