Add model to represent generated snapshot .bp file
Having each module type generate the contents of the snapshot's .bp file results in lots of duplicated code. This adds an intermediate model for use by the module types and then generates the .bp file contents from that. This not only removes the duplicated formatting code but it also allows consistent handling of shared properties such as name further reducing duplication. It also makes it possible to duplicate the versioned and unversioned prebuilt modules from the same model. Extracts generatedContents from generatedFile to allow the contents to be populated without creating an output file, for testing. Cleans up unused code. Bug: 143678475 Test: m nothing Change-Id: If21b84db0ef3fdfb5dc11ea0973ce6cb73603ea3
This commit is contained in:
@@ -1979,28 +1979,6 @@ func (d *Droidstubs) BuildSnapshot(sdkModuleContext android.ModuleContext, build
|
||||
snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources")
|
||||
builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir)
|
||||
|
||||
d.generatePrebuiltStubsSources(builder, snapshotRelativeDir, true)
|
||||
|
||||
// This module is for the case when the source tree for the unversioned module
|
||||
// doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false
|
||||
// so that this module does not eclipse the unversioned module if it exists.
|
||||
d.generatePrebuiltStubsSources(builder, snapshotRelativeDir, false)
|
||||
}
|
||||
|
||||
func (d *Droidstubs) generatePrebuiltStubsSources(builder android.SnapshotBuilder, snapshotRelativeDir string, versioned bool) {
|
||||
bp := builder.AndroidBpFile()
|
||||
name := d.Name()
|
||||
bp.Printfln("prebuilt_stubs_sources {")
|
||||
bp.Indent()
|
||||
if versioned {
|
||||
bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name))
|
||||
bp.Printfln("sdk_member_name: %q,", name)
|
||||
} else {
|
||||
bp.Printfln("name: %q,", name)
|
||||
bp.Printfln("prefer: false,")
|
||||
}
|
||||
bp.Printfln("srcs: [%q],", snapshotRelativeDir)
|
||||
bp.Dedent()
|
||||
bp.Printfln("}")
|
||||
bp.Printfln("")
|
||||
pbm := builder.AddPrebuiltModule(sdkModuleContext.OtherModuleName(d), "prebuilt_stubs_sources")
|
||||
pbm.AddProperty("srcs", []string{snapshotRelativeDir})
|
||||
}
|
||||
|
26
java/java.go
26
java/java.go
@@ -1729,30 +1729,8 @@ func (j *Library) BuildSnapshot(sdkModuleContext android.ModuleContext, builder
|
||||
}
|
||||
}
|
||||
|
||||
j.generateJavaImport(builder, snapshotRelativeJavaLibPath, true)
|
||||
|
||||
// This module is for the case when the source tree for the unversioned module
|
||||
// doesn't exist (i.e. building in an unbundled tree). "prefer:" is set to false
|
||||
// so that this module does not eclipse the unversioned module if it exists.
|
||||
j.generateJavaImport(builder, snapshotRelativeJavaLibPath, false)
|
||||
}
|
||||
|
||||
func (j *Library) generateJavaImport(builder android.SnapshotBuilder, snapshotRelativeJavaLibPath string, versioned bool) {
|
||||
bp := builder.AndroidBpFile()
|
||||
name := j.Name()
|
||||
bp.Printfln("java_import {")
|
||||
bp.Indent()
|
||||
if versioned {
|
||||
bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name))
|
||||
bp.Printfln("sdk_member_name: %q,", name)
|
||||
} else {
|
||||
bp.Printfln("name: %q,", name)
|
||||
bp.Printfln("prefer: false,")
|
||||
}
|
||||
bp.Printfln("jars: [%q],", snapshotRelativeJavaLibPath)
|
||||
bp.Dedent()
|
||||
bp.Printfln("}")
|
||||
bp.Printfln("")
|
||||
module := builder.AddPrebuiltModule(sdkModuleContext.OtherModuleName(j), "java_import")
|
||||
module.AddProperty("jars", []string{snapshotRelativeJavaLibPath})
|
||||
}
|
||||
|
||||
// java_library builds and links sources into a `.jar` file for the device, and possibly for the host as well.
|
||||
|
Reference in New Issue
Block a user