stub variants also re-exports headers

This change fixes a bug that headers are not re-exported from stub
variants of a library, if the headers are not from header libs, but from
shared or static libs. This is because only header lib dependencies
are respected for stubs variants.

The fix is as follows. 1) dependencies to the shared/static libs are
added even for stubs variants. 2) instead, in depsToPaths, they are
treated like header libs (i.e. don't contribute to linkFile) for the
stubs variants.

Bug: 174558745
Test: m

Change-Id: Iab6c77e7817055d0f2d09cb114186b30164fc231
This commit is contained in:
Jiyong Park 2020-12-01 23:40:09 +09:00
parent 47132c4943
commit 1ad8e16fbe
3 changed files with 56 additions and 15 deletions

View file

@ -1697,6 +1697,8 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
filesInfo = append(filesInfo, af)
return true // track transitive dependencies
}
} else if cc.IsHeaderDepTag(depTag) {
// nothing
} else if java.IsJniDepTag(depTag) {
// Because APK-in-APEX embeds jni_libs transitively, we don't need to track transitive deps
return false

View file

@ -1881,13 +1881,6 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
}
}
buildStubs := false
if versioned, ok := c.linker.(versionedInterface); ok {
if versioned.buildStubs() {
buildStubs = true
}
}
rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
// only modules with BOARD_VNDK_VERSION uses snapshot.
if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
@ -1910,7 +1903,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
if buildStubs {
if c.IsStubs() {
actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
depTag, lib)
} else {
@ -1918,12 +1911,6 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
}
}
if buildStubs {
// Stubs lib does not have dependency to other static/shared libraries.
// Don't proceed.
return
}
// sysprop_library has to support both C++ and Java. So sysprop_library internally creates one
// C++ implementation library and one Java implementation library. When a module links against
// sysprop_library, the C++ implementation library has to be linked. syspropImplLibraries is a
@ -2237,6 +2224,11 @@ func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
return false
}
depTag := ctx.OtherModuleDependencyTag(child)
if IsHeaderDepTag(depTag) {
return false
}
// Even if target lib has no vendor variant, keep checking dependency
// graph in case it depends on vendor_available or product_available
// but not double_loadable transtively.
@ -2483,6 +2475,12 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}
}
// Stubs lib doesn't link to the shared lib dependencies. Don't set
// linkFile, depFile, and ptr.
if c.IsStubs() {
break
}
linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
depFile = sharedLibraryInfo.TableOfContents
@ -2510,6 +2508,13 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}
return
}
// Stubs lib doesn't link to the static lib dependencies. Don't set
// linkFile, depFile, and ptr.
if c.IsStubs() {
break
}
staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
if libDepTag.wholeStatic {
@ -2637,7 +2642,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
c.Properties.AndroidMkStaticLibs, makeLibName)
}
}
} else {
} else if !c.IsStubs() {
// Stubs lib doesn't link to the runtime lib, object, crt, etc. dependencies.
switch depTag {
case runtimeDepTag:
c.Properties.AndroidMkRuntimeLibs = append(

View file

@ -4056,3 +4056,35 @@ func TestInstallSharedLibs(t *testing.T) {
}
}
func TestStubsLibReexportsHeaders(t *testing.T) {
ctx := testCc(t, `
cc_library_shared {
name: "libclient",
srcs: ["foo.c"],
shared_libs: ["libfoo#1"],
}
cc_library_shared {
name: "libfoo",
srcs: ["foo.c"],
shared_libs: ["libbar"],
export_shared_lib_headers: ["libbar"],
stubs: {
symbol_file: "foo.map.txt",
versions: ["1", "2", "3"],
},
}
cc_library_shared {
name: "libbar",
export_include_dirs: ["include/libbar"],
srcs: ["foo.c"],
}`)
cFlags := ctx.ModuleForTests("libclient", "android_arm64_armv8-a_shared").Rule("cc").Args["cFlags"]
if !strings.Contains(cFlags, "-Iinclude/libbar") {
t.Errorf("expected %q in cflags, got %q", "-Iinclude/libbar", cFlags)
}
}