From 2df817757575026d937b0ad6e814419a5976d4fa Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 26 Jan 2021 11:00:18 -0800 Subject: [PATCH 1/2] Add Target to cc.SharedLibraryInfo Dependencies from common arch modules like java libraires to cc modules may need to retrieve the Target of the library, add it to SharedLibraryInfo. Bug: 176593487 Test: cc_test.go Change-Id: I93ab9da5fab2ccc42c6b483a6d83c071b541d1e6 --- cc/library.go | 1 + cc/linkable.go | 1 + cc/ndk_prebuilt.go | 1 + cc/prebuilt.go | 1 + cc/snapshot_prebuilt.go | 1 + cc/vndk_prebuilt.go | 1 + rust/library.go | 1 + 7 files changed, 7 insertions(+) diff --git a/cc/library.go b/cc/library.go index af9aaca51..260ff7544 100644 --- a/cc/library.go +++ b/cc/library.go @@ -1110,6 +1110,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext, UnstrippedSharedLibrary: library.unstrippedOutputFile, CoverageSharedLibrary: library.coverageOutputFile, StaticAnalogue: staticAnalogue, + Target: ctx.Target(), }) stubs := ctx.GetDirectDepsWithTag(stubImplDepTag) diff --git a/cc/linkable.go b/cc/linkable.go index ab5a552c1..d15812eb4 100644 --- a/cc/linkable.go +++ b/cc/linkable.go @@ -168,6 +168,7 @@ func HeaderDepTag() blueprint.DependencyTag { type SharedLibraryInfo struct { SharedLibrary android.Path UnstrippedSharedLibrary android.Path + Target android.Target TableOfContents android.OptionalPath CoverageSharedLibrary android.OptionalPath diff --git a/cc/ndk_prebuilt.go b/cc/ndk_prebuilt.go index 8d522d0c4..b91c73722 100644 --- a/cc/ndk_prebuilt.go +++ b/cc/ndk_prebuilt.go @@ -188,6 +188,7 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags, ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ SharedLibrary: lib, UnstrippedSharedLibrary: lib, + Target: ctx.Target(), }) } diff --git a/cc/prebuilt.go b/cc/prebuilt.go index 2cd18cb99..411a3695a 100644 --- a/cc/prebuilt.go +++ b/cc/prebuilt.go @@ -185,6 +185,7 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext, ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ SharedLibrary: outputFile, UnstrippedSharedLibrary: p.unstrippedOutputFile, + Target: ctx.Target(), TableOfContents: p.tocFile, }) diff --git a/cc/snapshot_prebuilt.go b/cc/snapshot_prebuilt.go index 2003e03ff..020dcd77f 100644 --- a/cc/snapshot_prebuilt.go +++ b/cc/snapshot_prebuilt.go @@ -605,6 +605,7 @@ func (p *snapshotLibraryDecorator) link(ctx ModuleContext, flags Flags, deps Pat ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ SharedLibrary: in, UnstrippedSharedLibrary: p.unstrippedOutputFile, + Target: ctx.Target(), TableOfContents: p.tocFile, }) diff --git a/cc/vndk_prebuilt.go b/cc/vndk_prebuilt.go index 04162cdce..cf7c8b6cc 100644 --- a/cc/vndk_prebuilt.go +++ b/cc/vndk_prebuilt.go @@ -166,6 +166,7 @@ func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext, ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{ SharedLibrary: in, UnstrippedSharedLibrary: p.unstrippedOutputFile, + Target: ctx.Target(), TableOfContents: p.tocFile, }) diff --git a/rust/library.go b/rust/library.go index 4ac52b428..8f0a50c20 100644 --- a/rust/library.go +++ b/rust/library.go @@ -505,6 +505,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa ctx.SetProvider(cc.SharedLibraryInfoProvider, cc.SharedLibraryInfo{ SharedLibrary: outputFile, UnstrippedSharedLibrary: outputFile, + Target: ctx.Target(), }) } From 246164a055a529e081a7690cc9043b496757a30c Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 26 Jan 2021 11:01:43 -0800 Subject: [PATCH 2/2] Add jni_libs property to java tests Add jni_libs property to java tests and treat it as test data that should be copied to the lib or lib64 directory in the test directory. Fixes: 176593487 Test: java_test.go Change-Id: I3a118b933ab30dcd731c6dc2708da9bc63ab5520 --- java/java.go | 34 ++++++++++++++++++++++++++++++++++ java/java_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/java/java.go b/java/java.go index 59ec94d5b..bc5bdb192 100644 --- a/java/java.go +++ b/java/java.go @@ -29,6 +29,7 @@ import ( "github.com/google/blueprint/proptools" "android/soong/android" + "android/soong/cc" "android/soong/dexpreopt" "android/soong/java/config" "android/soong/tradefed" @@ -2387,6 +2388,9 @@ type testProperties struct { // Test options. Test_options TestOptions + + // Names of modules containing JNI libraries that should be installed alongside the test. + Jni_libs []string } type hostTestProperties struct { @@ -2448,6 +2452,13 @@ func (j *TestHost) DepsMutator(ctx android.BottomUpMutatorContext) { } } + if len(j.testProperties.Jni_libs) > 0 { + for _, target := range ctx.MultiTargets() { + sharedLibVariations := append(target.Variations(), blueprint.Variation{Mutator: "link", Variation: "shared"}) + ctx.AddFarVariationDependencies(sharedLibVariations, jniLibTag, j.testProperties.Jni_libs...) + } + } + j.deps(ctx) } @@ -2463,6 +2474,29 @@ func (j *Test) GenerateAndroidBuildActions(ctx android.ModuleContext) { j.data = append(j.data, android.OutputFileForModule(ctx, dep, "")) }) + ctx.VisitDirectDepsWithTag(jniLibTag, func(dep android.Module) { + sharedLibInfo := ctx.OtherModuleProvider(dep, cc.SharedLibraryInfoProvider).(cc.SharedLibraryInfo) + if sharedLibInfo.SharedLibrary != nil { + // Copy to an intermediate output directory to append "lib[64]" to the path, + // so that it's compatible with the default rpath values. + var relPath string + if sharedLibInfo.Target.Arch.ArchType.Multilib == "lib64" { + relPath = filepath.Join("lib64", sharedLibInfo.SharedLibrary.Base()) + } else { + relPath = filepath.Join("lib", sharedLibInfo.SharedLibrary.Base()) + } + relocatedLib := android.PathForModuleOut(ctx, "relocated").Join(ctx, relPath) + ctx.Build(pctx, android.BuildParams{ + Rule: android.Cp, + Input: sharedLibInfo.SharedLibrary, + Output: relocatedLib, + }) + j.data = append(j.data, relocatedLib) + } else { + ctx.PropertyErrorf("jni_libs", "%q of type %q is not supported", dep.Name(), ctx.OtherModuleType(dep)) + } + }) + j.Library.GenerateAndroidBuildActions(ctx) } diff --git a/java/java_test.go b/java/java_test.go index 7b8984810..73734feb1 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -499,6 +499,32 @@ func TestBinary(t *testing.T) { } } +func TestTest(t *testing.T) { + ctx, _ := testJava(t, ` + java_test_host { + name: "foo", + srcs: ["a.java"], + jni_libs: ["libjni"], + } + + cc_library_shared { + name: "libjni", + host_supported: true, + device_supported: false, + stl: "none", + } + `) + + buildOS := android.BuildOs.String() + + foo := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost) + + fooTestData := foo.data + if len(fooTestData) != 1 || fooTestData[0].Rel() != "lib64/libjni.so" { + t.Errorf(`expected foo test data relative path ["lib64/libjni.so"], got %q`, fooTestData.Strings()) + } +} + func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) { bp := ` java_library {