Merge "APEX uses the latest version of the stub" am: ce80f18749

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1609533

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I294103da51c7a9ad11a81e3eadb1a0e2e98920e8
This commit is contained in:
Treehugger Robot 2021-03-02 02:03:34 +00:00 committed by Automerger Merge Worker
commit 3310e2d9ea
2 changed files with 22 additions and 91 deletions

View File

@ -972,8 +972,8 @@ func TestApexWithStubsWithMinSdkVersion(t *testing.T) {
mylibLdFlags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex29").Rule("ld").Args["libFlags"]
// Ensure that mylib is linking with the version 29 stubs for mylib2
ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_29/mylib2.so")
// Ensure that mylib is linking with the latest version of stub for mylib2
ensureContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared_current/mylib2.so")
// ... and not linking to the non-stub (impl) variant of mylib2
ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")
@ -1057,11 +1057,11 @@ func TestApex_PlatformUsesLatestStubFromApex(t *testing.T) {
config.TestProductVariables.Platform_version_active_codenames = []string{"Z"}
})
// Ensure that mylib from myapex is built against "min_sdk_version" stub ("Z"), which is non-final
// Ensure that mylib from myapex is built against the latest stub (current)
mylibCflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_static_apex10000").Rule("cc").Args["cFlags"]
ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=9000 ")
ensureContains(t, mylibCflags, "-D__LIBSTUB_API__=10000 ")
mylibLdflags := ctx.ModuleForTests("mylib", "android_arm64_armv8-a_shared_apex10000").Rule("ld").Args["libFlags"]
ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_Z/libstub.so ")
ensureContains(t, mylibLdflags, "libstub/android_arm64_armv8-a_shared_current/libstub.so ")
// Ensure that libplatform is built against latest stub ("current") of mylib3 from the apex
libplatformCflags := ctx.ModuleForTests("libplatform", "android_arm64_armv8-a_static").Rule("cc").Args["cFlags"]
@ -1359,18 +1359,18 @@ func TestApexDependsOnLLNDKTransitively(t *testing.T) {
shouldNotLink []string
}{
{
name: "should link to the latest",
name: "unspecified version links to the latest",
minSdkVersion: "",
apexVariant: "apex10000",
shouldLink: "30",
shouldNotLink: []string{"29"},
},
{
name: "should link to llndk#29",
name: "always use the latest",
minSdkVersion: "min_sdk_version: \"29\",",
apexVariant: "apex29",
shouldLink: "29",
shouldNotLink: []string{"30"},
shouldLink: "30",
shouldNotLink: []string{"29"},
},
}
for _, tc := range testcases {
@ -1532,8 +1532,8 @@ func TestApexWithSystemLibsStubs(t *testing.T) {
}
func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T) {
// there are three links between liba --> libz
// 1) myapex -> libx -> liba -> libz : this should be #29 link, but fallback to #28
// there are three links between liba --> libz.
// 1) myapex -> libx -> liba -> libz : this should be #30 link
// 2) otherapex -> liby -> liba -> libz : this should be #30 link
// 3) (platform) -> liba -> libz : this should be non-stub link
ctx, _ := testApex(t, `
@ -1607,9 +1607,9 @@ func TestApexMinSdkVersion_NativeModulesShouldBeBuiltAgainstStubs(t *testing.T)
}
// platform liba is linked to non-stub version
expectLink("liba", "shared", "libz", "shared")
// liba in myapex is linked to #28
expectLink("liba", "shared_apex29", "libz", "shared_28")
expectNoLink("liba", "shared_apex29", "libz", "shared_30")
// liba in myapex is linked to #30
expectLink("liba", "shared_apex29", "libz", "shared_30")
expectNoLink("liba", "shared_apex29", "libz", "shared_28")
expectNoLink("liba", "shared_apex29", "libz", "shared")
// liba in otherapex is linked to #30
expectLink("liba", "shared_apex30", "libz", "shared_30")
@ -1827,41 +1827,6 @@ func TestQTargetApexUsesStaticUnwinder(t *testing.T) {
ensureListNotContains(t, cm.Properties.AndroidMkStaticLibs, "libunwind")
}
func TestApexMinSdkVersion_ErrorIfIncompatibleStubs(t *testing.T) {
testApexError(t, `"libz" .*: not found a version\(<=29\)`, `
apex {
name: "myapex",
key: "myapex.key",
native_shared_libs: ["libx"],
min_sdk_version: "29",
}
apex_key {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}
cc_library {
name: "libx",
shared_libs: ["libz"],
system_shared_libs: [],
stl: "none",
apex_available: [ "myapex" ],
min_sdk_version: "29",
}
cc_library {
name: "libz",
system_shared_libs: [],
stl: "none",
stubs: {
versions: ["30"],
},
}
`)
}
func TestApexMinSdkVersion_ErrorIfIncompatibleVersion(t *testing.T) {
testApexError(t, `module "mylib".*: should support min_sdk_version\(29\)`, `
apex {
@ -2173,7 +2138,7 @@ func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion
private_key: "testkey.pem",
}
// mylib in myapex will link to mylib2#29
// mylib in myapex will link to mylib2#30
// mylib in otherapex will link to mylib2(non-stub) in otherapex as well
cc_library {
name: "mylib",
@ -2207,7 +2172,7 @@ func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion
libFlags := ld.Args["libFlags"]
ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
}
expectLink("mylib", "shared_apex29", "mylib2", "shared_29")
expectLink("mylib", "shared_apex29", "mylib2", "shared_30")
expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30")
}
@ -2276,7 +2241,7 @@ func TestApexMinSdkVersion_WorksWithActiveCodenames(t *testing.T) {
// ensure libfoo is linked with "S" version of libbar stub
libfoo := ctx.ModuleForTests("libfoo", "android_arm64_armv8-a_shared_apex10000")
libFlags := libfoo.Rule("ld").Args["libFlags"]
ensureContains(t, libFlags, "android_arm64_armv8-a_shared_S/libbar.so")
ensureContains(t, libFlags, "android_arm64_armv8-a_shared_T/libbar.so")
}
func TestFilesInSubDir(t *testing.T) {

View File

@ -2420,36 +2420,6 @@ func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
}
}
// Returns the highest version which is <= maxSdkVersion.
// For example, with maxSdkVersion is 10 and versionList is [9,11]
// it returns 9 as string. The list of stubs must be in order from
// oldest to newest.
func (c *Module) chooseSdkVersion(ctx android.PathContext, stubsInfo []SharedStubLibrary,
maxSdkVersion android.ApiLevel) (SharedStubLibrary, error) {
for i := range stubsInfo {
stubInfo := stubsInfo[len(stubsInfo)-i-1]
var ver android.ApiLevel
if stubInfo.Version == "" {
ver = android.FutureApiLevel
} else {
var err error
ver, err = android.ApiLevelFromUser(ctx, stubInfo.Version)
if err != nil {
return SharedStubLibrary{}, err
}
}
if ver.LessThanOrEqualTo(maxSdkVersion) {
return stubInfo, nil
}
}
var versionList []string
for _, stubInfo := range stubsInfo {
versionList = append(versionList, stubInfo.Version)
}
return SharedStubLibrary{}, fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion.String(), versionList)
}
// Convert dependencies to paths. Returns a PathDeps containing paths
func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
var depPaths PathDeps
@ -2633,16 +2603,12 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
}
// when to use (unspecified) stubs, check min_sdk_version and choose the right one
// when to use (unspecified) stubs, use the latest one.
if useStubs {
sharedLibraryStubsInfo, err :=
c.chooseSdkVersion(ctx, sharedLibraryStubsInfo.SharedStubLibraries, c.apexSdkVersion)
if err != nil {
ctx.OtherModuleErrorf(dep, err.Error())
return
}
sharedLibraryInfo = sharedLibraryStubsInfo.SharedLibraryInfo
depExporterInfo = sharedLibraryStubsInfo.FlagExporterInfo
stubs := sharedLibraryStubsInfo.SharedStubLibraries
toUse := stubs[len(stubs)-1]
sharedLibraryInfo = toUse.SharedLibraryInfo
depExporterInfo = toUse.FlagExporterInfo
}
}