Dedup code for generating prebuilt_stubs_sources in snapshot

Removes duplicated code for generating a versioned and non-versioned
form of the prebuilt_stubs_sources module in the snapshot.

Bug: 143678475
Test: m nothing

Change-Id: Ic431b6fcb6f3c7c85f1a04cb6f087424aaf0cffa
This commit is contained in:
Paul Duffin 2019-11-26 21:55:37 +00:00
parent ac37c503e0
commit b1a8813520
2 changed files with 15 additions and 13 deletions

View File

@ -1979,25 +1979,27 @@ func (d *Droidstubs) BuildSnapshot(sdkModuleContext android.ModuleContext, build
snapshotRelativeDir := filepath.Join("java", d.Name()+"_stubs_sources")
builder.UnzipToSnapshot(stubsSrcJar, snapshotRelativeDir)
name := d.Name()
bp := builder.AndroidBpFile()
bp.Printfln("prebuilt_stubs_sources {")
bp.Indent()
bp.Printfln("name: %q,", builder.VersionedSdkMemberName(name))
bp.Printfln("sdk_member_name: %q,", name)
bp.Printfln("srcs: [%q],", snapshotRelativeDir)
bp.Dedent()
bp.Printfln("}")
bp.Printfln("")
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()
bp.Printfln("name: %q,", name)
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.Printfln("prefer: false,")
bp.Dedent()
bp.Printfln("}")
bp.Printfln("")

View File

@ -515,8 +515,8 @@ prebuilt_stubs_sources {
prebuilt_stubs_sources {
name: "myjavaapistubs",
srcs: ["java/myjavaapistubs_stubs_sources"],
prefer: false,
srcs: ["java/myjavaapistubs_stubs_sources"],
}
cc_prebuilt_library_shared {