diff options
author | 2024-10-11 12:52:21 -0700 | |
---|---|---|
committer | 2024-11-05 14:31:14 -0800 | |
commit | b614cd441b355e48e59d1f5cd61a800103404151 (patch) | |
tree | 52631bc0f41419e8e6e251d9be1653599349c133 /java/app.go | |
parent | 7ceb14aa4bb17638e3521ca11bd5c671e32adc50 (diff) |
Verify that libraries in apexes don't link to implementations outside the apex
As part of removing some of the complexity in Soong around using
stub vs. implementations for shared library dependencies a syntax
will be added to Soong to allow explicitly selecting stubs vs.
implementation. To avoid incorrect use, add a verification pass
on apexes that ensure that all transitive implementation libraries
used to link native libraries or binaries in the apex are
themselves in the apex.
Bug: 372543712
Test: TestApexVerifyNativeImplementationLibs
Flag: EXEMPT host only
Change-Id: I4aeaca00a359ce97e8f9efd2d8bffb8f9d2dc0df
Diffstat (limited to 'java/app.go')
-rw-r--r-- | java/app.go | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/java/app.go b/java/app.go index fed971a55..15b1114a7 100644 --- a/java/app.go +++ b/java/app.go @@ -67,6 +67,9 @@ type AppInfo struct { // TestHelperApp is true if the module is a android_test_helper_app TestHelperApp bool + + // EmbeddedJNILibs is the list of paths to JNI libraries that were embedded in the APK. + EmbeddedJNILibs android.Paths } var AppInfoProvider = blueprint.NewProvider[*AppInfo]() @@ -405,9 +408,18 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) { a.checkEmbedJnis(ctx) a.generateAndroidBuildActions(ctx) a.generateJavaUsedByApex(ctx) + + var embeddedJniLibs []android.Path + + if a.embeddedJniLibs { + for _, jni := range a.jniLibs { + embeddedJniLibs = append(embeddedJniLibs, jni.path) + } + } android.SetProvider(ctx, AppInfoProvider, &AppInfo{ - Updatable: Bool(a.appProperties.Updatable), - TestHelperApp: false, + Updatable: Bool(a.appProperties.Updatable), + TestHelperApp: false, + EmbeddedJNILibs: embeddedJniLibs, }) } @@ -1070,12 +1082,12 @@ func collectAppDeps(ctx android.ModuleContext, app appDepsInterface, app.SdkVersion(ctx).Kind != android.SdkCorePlatform && !app.RequiresStableAPIs(ctx) } jniLib, prebuiltJniPackages := collectJniDeps(ctx, shouldCollectRecursiveNativeDeps, - checkNativeSdkVersion, func(dep cc.LinkableInterface) bool { - return !dep.IsNdk(ctx.Config()) && !dep.IsStubs() - }) + checkNativeSdkVersion, func(dep cc.LinkableInterface) bool { return !dep.IsNdk(ctx.Config()) && !dep.IsStubs() }) var certificates []Certificate + var directImplementationDeps android.Paths + var transitiveImplementationDeps []depset.DepSet[android.Path] ctx.VisitDirectDeps(func(module android.Module) { otherName := ctx.OtherModuleName(module) tag := ctx.OtherModuleDependencyTag(module) @@ -1087,7 +1099,18 @@ func collectAppDeps(ctx android.ModuleContext, app appDepsInterface, ctx.ModuleErrorf("certificate dependency %q must be an android_app_certificate module", otherName) } } + + if IsJniDepTag(tag) { + directImplementationDeps = append(directImplementationDeps, android.OutputFileForModule(ctx, module, "")) + if info, ok := android.OtherModuleProvider(ctx, module, cc.ImplementationDepInfoProvider); ok { + transitiveImplementationDeps = append(transitiveImplementationDeps, info.ImplementationDeps) + } + } }) + android.SetProvider(ctx, cc.ImplementationDepInfoProvider, &cc.ImplementationDepInfo{ + ImplementationDeps: depset.New(depset.PREORDER, directImplementationDeps, transitiveImplementationDeps), + }) + return jniLib, prebuiltJniPackages, certificates } |