Fix transitive whole_static_libs on prebuilt static libraries

whole_static_libs on static library usually uses the .o files from
the dependency, but on a prebuilt static library has to use the .a file.
whole_static_libs on a static library that itself has whole_static_libs
on a prebuilt static library also needs to use the .a file transitively.

Test: TestWholeStaticLibPrebuilts
Change-Id: I9d4aabf72be0941b461a72e610f2b28287251cb2
This commit is contained in:
Colin Cross 2022-02-11 13:11:55 -08:00
parent 06c80eb851
commit a2bcf2c4b8
4 changed files with 88 additions and 4 deletions

View file

@ -2795,6 +2795,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
// dependency. // dependency.
depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path()) depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
} }
depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts,
staticLibraryInfo.WholeStaticLibsFromPrebuilts...)
} else { } else {
switch libDepTag.Order { switch libDepTag.Order {
case earlyLibraryDependency: case earlyLibraryDependency:

View file

@ -586,7 +586,8 @@ type libraryDecorator struct {
stripper Stripper stripper Stripper
// For whole_static_libs // For whole_static_libs
objects Objects objects Objects
wholeStaticLibsFromPrebuilts android.Paths
// Uses the module's name if empty, but can be overridden. Does not include // Uses the module's name if empty, but can be overridden. Does not include
// shlib suffix. // shlib suffix.
@ -1343,6 +1344,7 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext,
library.objects = deps.WholeStaticLibObjs.Copy() library.objects = deps.WholeStaticLibObjs.Copy()
library.objects = library.objects.Append(objs) library.objects = library.objects.Append(objs)
library.wholeStaticLibsFromPrebuilts = android.CopyOfPaths(deps.WholeStaticLibsFromPrebuilts)
fileName := ctx.ModuleName() + staticLibraryExtension fileName := ctx.ModuleName() + staticLibraryExtension
outputFile := android.PathForModuleOut(ctx, fileName) outputFile := android.PathForModuleOut(ctx, fileName)
@ -1368,9 +1370,10 @@ func (library *libraryDecorator) linkStatic(ctx ModuleContext,
if library.static() { if library.static() {
ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{ ctx.SetProvider(StaticLibraryInfoProvider, StaticLibraryInfo{
StaticLibrary: outputFile, StaticLibrary: outputFile,
ReuseObjects: library.reuseObjects, ReuseObjects: library.reuseObjects,
Objects: library.objects, Objects: library.objects,
WholeStaticLibsFromPrebuilts: library.wholeStaticLibsFromPrebuilts,
TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder(android.TOPOLOGICAL). TransitiveStaticLibrariesForOrdering: android.NewDepSetBuilder(android.TOPOLOGICAL).
Direct(outputFile). Direct(outputFile).

View file

@ -379,3 +379,77 @@ cc_library_shared {
gotFlags := entries.EntryMap["LOCAL_EXPORT_CFLAGS"] gotFlags := entries.EntryMap["LOCAL_EXPORT_CFLAGS"]
android.AssertDeepEquals(t, "androidmk exported cflags", expectedFlags, gotFlags) android.AssertDeepEquals(t, "androidmk exported cflags", expectedFlags, gotFlags)
} }
func TestWholeStaticLibPrebuilts(t *testing.T) {
result := PrepareForIntegrationTestWithCc.RunTestWithBp(t, `
cc_prebuilt_library_static {
name: "libprebuilt",
srcs: ["foo.a"],
}
cc_library_static {
name: "libdirect",
whole_static_libs: ["libprebuilt"],
}
cc_library_static {
name: "libtransitive",
whole_static_libs: ["libdirect"],
}
cc_library_static {
name: "libdirect_with_srcs",
srcs: ["bar.c"],
whole_static_libs: ["libprebuilt"],
}
cc_library_static {
name: "libtransitive_with_srcs",
srcs: ["baz.c"],
whole_static_libs: ["libdirect_with_srcs"],
}
`)
libdirect := result.ModuleForTests("libdirect", "android_arm64_armv8-a_static").Rule("arWithLibs")
libtransitive := result.ModuleForTests("libtransitive", "android_arm64_armv8-a_static").Rule("arWithLibs")
libdirectWithSrcs := result.ModuleForTests("libdirect_with_srcs", "android_arm64_armv8-a_static").Rule("arWithLibs")
libtransitiveWithSrcs := result.ModuleForTests("libtransitive_with_srcs", "android_arm64_armv8-a_static").Rule("arWithLibs")
barObj := result.ModuleForTests("libdirect_with_srcs", "android_arm64_armv8-a_static").Rule("cc")
bazObj := result.ModuleForTests("libtransitive_with_srcs", "android_arm64_armv8-a_static").Rule("cc")
android.AssertStringListContains(t, "missing dependency on foo.a",
libdirect.Inputs.Strings(), "foo.a")
android.AssertStringDoesContain(t, "missing flag for foo.a",
libdirect.Args["arLibs"], "foo.a")
android.AssertStringListContains(t, "missing dependency on foo.a",
libtransitive.Inputs.Strings(), "foo.a")
android.AssertStringDoesContain(t, "missing flag for foo.a",
libtransitive.Args["arLibs"], "foo.a")
android.AssertStringListContains(t, "missing dependency on foo.a",
libdirectWithSrcs.Inputs.Strings(), "foo.a")
android.AssertStringDoesContain(t, "missing flag for foo.a",
libdirectWithSrcs.Args["arLibs"], "foo.a")
android.AssertStringListContains(t, "missing dependency on bar.o",
libdirectWithSrcs.Inputs.Strings(), barObj.Output.String())
android.AssertStringDoesContain(t, "missing flag for bar.o",
libdirectWithSrcs.Args["arObjs"], barObj.Output.String())
android.AssertStringListContains(t, "missing dependency on foo.a",
libtransitiveWithSrcs.Inputs.Strings(), "foo.a")
android.AssertStringDoesContain(t, "missing flag for foo.a",
libtransitiveWithSrcs.Args["arLibs"], "foo.a")
android.AssertStringListContains(t, "missing dependency on bar.o",
libtransitiveWithSrcs.Inputs.Strings(), barObj.Output.String())
android.AssertStringDoesContain(t, "missing flag for bar.o",
libtransitiveWithSrcs.Args["arObjs"], barObj.Output.String())
android.AssertStringListContains(t, "missing dependency on baz.o",
libtransitiveWithSrcs.Inputs.Strings(), bazObj.Output.String())
android.AssertStringDoesContain(t, "missing flag for baz.o",
libtransitiveWithSrcs.Args["arObjs"], bazObj.Output.String())
}

View file

@ -352,6 +352,11 @@ type StaticLibraryInfo struct {
Objects Objects Objects Objects
ReuseObjects Objects ReuseObjects Objects
// A static library may contain prebuilt static libraries included with whole_static_libs
// that won't appear in Objects. They are transitively available in
// WholeStaticLibsFromPrebuilts.
WholeStaticLibsFromPrebuilts android.Paths
// This isn't the actual transitive DepSet, shared library dependencies have been // This isn't the actual transitive DepSet, shared library dependencies have been
// converted into static library analogues. It is only used to order the static // converted into static library analogues. It is only used to order the static
// library dependencies that were specified for the current module. // library dependencies that were specified for the current module.