Merge changes from topic "tvts-test-host-jni"

* changes:
  Add jni_libs property to java tests
  Add Target to cc.SharedLibraryInfo
This commit is contained in:
Treehugger Robot 2021-04-17 04:35:24 +00:00 committed by Gerrit Code Review
commit aef14db78a
9 changed files with 67 additions and 0 deletions

View File

@ -1257,6 +1257,7 @@ func (library *libraryDecorator) linkShared(ctx ModuleContext,
UnstrippedSharedLibrary: library.unstrippedOutputFile,
CoverageSharedLibrary: library.coverageOutputFile,
StaticAnalogue: staticAnalogue,
Target: ctx.Target(),
})
stubs := ctx.GetDirectDepsWithTag(stubImplDepTag)

View File

@ -209,6 +209,7 @@ func HeaderDepTag() blueprint.DependencyTag {
type SharedLibraryInfo struct {
SharedLibrary android.Path
UnstrippedSharedLibrary android.Path
Target android.Target
TableOfContents android.OptionalPath
CoverageSharedLibrary android.OptionalPath

View File

@ -188,6 +188,7 @@ func (ndk *ndkPrebuiltStlLinker) link(ctx ModuleContext, flags Flags,
ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
SharedLibrary: lib,
UnstrippedSharedLibrary: lib,
Target: ctx.Target(),
})
}

View File

@ -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,
})

View File

@ -591,6 +591,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,
})

View File

@ -170,6 +170,7 @@ func (p *vndkPrebuiltLibraryDecorator) link(ctx ModuleContext,
ctx.SetProvider(SharedLibraryInfoProvider, SharedLibraryInfo{
SharedLibrary: in,
UnstrippedSharedLibrary: p.unstrippedOutputFile,
Target: ctx.Target(),
TableOfContents: p.tocFile,
})

View File

@ -27,6 +27,7 @@ import (
"github.com/google/blueprint/proptools"
"android/soong/android"
"android/soong/cc"
"android/soong/dexpreopt"
"android/soong/java/config"
"android/soong/tradefed"
@ -708,6 +709,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 {
@ -769,6 +773,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)
}
@ -793,6 +804,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)
}

View File

@ -462,6 +462,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 {

View File

@ -496,6 +496,7 @@ func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps Pa
ctx.SetProvider(cc.SharedLibraryInfoProvider, cc.SharedLibraryInfo{
SharedLibrary: outputFile,
UnstrippedSharedLibrary: outputFile,
Target: ctx.Target(),
})
}