diff options
| author | Colin Cross <ccross@android.com> | 2019-03-27 09:07:26 -0700 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2019-03-27 09:07:26 -0700 |
| commit | fdd34fae7672fcd21519d8d4a90023c7cd0d55cc (patch) | |
| tree | c8e7777b54407a318911abe3bdc2e742b0cfc4a4 /java | |
| parent | 010bc3f077e148ac54b84c153ed881e289bfff18 (diff) | |
| parent | b1af785608243f26f7185d11236087295d267347 (diff) | |
| download | build_soong-fdd34fae7672fcd21519d8d4a90023c7cd0d55cc.tar.gz build_soong-fdd34fae7672fcd21519d8d4a90023c7cd0d55cc.tar.bz2 build_soong-fdd34fae7672fcd21519d8d4a90023c7cd0d55cc.zip | |
Merge "Always package JNI libs into android_test modules" am: eae12cf400 am: f394fb0a27
am: b1af785608
Change-Id: I73d8243ae1bd428098f4f60b4a22c9b50785c481
Diffstat (limited to 'java')
| -rw-r--r-- | java/app.go | 10 | ||||
| -rw-r--r-- | java/app_test.go | 132 | ||||
| -rw-r--r-- | java/java_test.go | 1 |
3 files changed, 98 insertions, 45 deletions
diff --git a/java/app.go b/java/app.go index 96594df3..ab623e24 100644 --- a/java/app.go +++ b/java/app.go @@ -74,6 +74,11 @@ type appProperties struct { // Store dex files uncompressed in the APK and set the android:useEmbeddedDex="true" manifest attribute so that // they are used from inside the APK at runtime. Use_embedded_dex *bool + + // Forces native libraries to always be packaged into the APK, + // Use_embedded_native_libs still selects whether they are stored uncompressed and aligned or compressed. + // True for android_test* modules. + AlwaysPackageNativeLibs bool `blueprint:"mutated"` } // android_app properties that can be overridden by override_android_app @@ -285,7 +290,8 @@ func (a *AndroidApp) dexBuildActions(ctx android.ModuleContext) android.Path { func (a *AndroidApp) jniBuildActions(jniLibs []jniLib, ctx android.ModuleContext) android.WritablePath { var jniJarFile android.WritablePath if len(jniLibs) > 0 { - embedJni := ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) + embedJni := ctx.Config().UnbundledBuild() || Bool(a.appProperties.Use_embedded_native_libs) || + a.appProperties.AlwaysPackageNativeLibs if embedJni { jniJarFile = android.PathForModuleOut(ctx, "jnilibs.zip") TransformJniLibsToJar(ctx, jniJarFile, jniLibs, a.shouldUncompressJNI(ctx)) @@ -507,6 +513,7 @@ func AndroidTestFactory() android.Module { module.Module.properties.Instrument = true module.Module.properties.Installable = proptools.BoolPtr(true) module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) + module.appProperties.AlwaysPackageNativeLibs = true module.Module.dexpreopter.isTest = true module.AddProperties( @@ -547,6 +554,7 @@ func AndroidTestHelperAppFactory() android.Module { module.Module.properties.Installable = proptools.BoolPtr(true) module.appProperties.Use_embedded_native_libs = proptools.BoolPtr(true) + module.appProperties.AlwaysPackageNativeLibs = true module.Module.dexpreopter.isTest = true module.AddProperties( diff --git a/java/app_test.go b/java/app_test.go index d2662426..781fdfff 100644 --- a/java/app_test.go +++ b/java/app_test.go @@ -16,6 +16,8 @@ package java import ( "android/soong/android" + "android/soong/cc" + "fmt" "path/filepath" "reflect" @@ -537,43 +539,8 @@ func TestAppSdkVersion(t *testing.T) { } } -func TestJNI(t *testing.T) { - ctx := testJava(t, ` - toolchain_library { - name: "libcompiler_rt-extras", - src: "", - } - - toolchain_library { - name: "libatomic", - src: "", - } - - toolchain_library { - name: "libgcc", - src: "", - } - - toolchain_library { - name: "libclang_rt.builtins-aarch64-android", - src: "", - } - - toolchain_library { - name: "libclang_rt.builtins-arm-android", - src: "", - } - - cc_object { - name: "crtbegin_so", - stl: "none", - } - - cc_object { - name: "crtend_so", - stl: "none", - } - +func TestJNIABI(t *testing.T) { + ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` cc_library { name: "libjni", system_shared_libs: [], @@ -615,13 +582,6 @@ func TestJNI(t *testing.T) { } `) - // check the existence of the internal modules - ctx.ModuleForTests("test", "android_common") - ctx.ModuleForTests("test_first", "android_common") - ctx.ModuleForTests("test_both", "android_common") - ctx.ModuleForTests("test_32", "android_common") - ctx.ModuleForTests("test_64", "android_common") - testCases := []struct { name string abis []string @@ -652,6 +612,90 @@ func TestJNI(t *testing.T) { } } +func TestJNIPackaging(t *testing.T) { + ctx := testJava(t, cc.GatherRequiredDepsForTest(android.Android)+` + cc_library { + name: "libjni", + system_shared_libs: [], + stl: "none", + } + + android_app { + name: "app", + jni_libs: ["libjni"], + } + + android_app { + name: "app_noembed", + jni_libs: ["libjni"], + use_embedded_native_libs: false, + } + + android_app { + name: "app_embed", + jni_libs: ["libjni"], + use_embedded_native_libs: true, + } + + android_test { + name: "test", + no_framework_libs: true, + jni_libs: ["libjni"], + } + + android_test { + name: "test_noembed", + no_framework_libs: true, + jni_libs: ["libjni"], + use_embedded_native_libs: false, + } + + android_test_helper_app { + name: "test_helper", + no_framework_libs: true, + jni_libs: ["libjni"], + } + + android_test_helper_app { + name: "test_helper_noembed", + no_framework_libs: true, + jni_libs: ["libjni"], + use_embedded_native_libs: false, + } + `) + + testCases := []struct { + name string + packaged bool + compressed bool + }{ + {"app", false, false}, + {"app_noembed", false, false}, + {"app_embed", true, false}, + {"test", true, false}, + {"test_noembed", true, true}, + {"test_helper", true, false}, + {"test_helper_noembed", true, true}, + } + + for _, test := range testCases { + t.Run(test.name, func(t *testing.T) { + app := ctx.ModuleForTests(test.name, "android_common") + jniLibZip := app.MaybeOutput("jnilibs.zip") + if g, w := (jniLibZip.Rule != nil), test.packaged; g != w { + t.Errorf("expected jni packaged %v, got %v", w, g) + } + + if jniLibZip.Rule != nil { + if g, w := !strings.Contains(jniLibZip.Args["jarArgs"], "-L 0"), test.compressed; g != w { + t.Errorf("expected jni compressed %v, got %v", w, g) + } + } + }) + } + +} + func TestCertificates(t *testing.T) { testCases := []struct { name string diff --git a/java/java_test.go b/java/java_test.go index f4664996..ec4c100f 100644 --- a/java/java_test.go +++ b/java/java_test.go @@ -103,6 +103,7 @@ func testContext(config android.Config, bp string, ctx.RegisterModuleType("cc_library", android.ModuleFactoryAdaptor(cc.LibraryFactory)) ctx.RegisterModuleType("cc_object", android.ModuleFactoryAdaptor(cc.ObjectFactory)) ctx.RegisterModuleType("toolchain_library", android.ModuleFactoryAdaptor(cc.ToolchainLibraryFactory)) + ctx.RegisterModuleType("llndk_library", android.ModuleFactoryAdaptor(cc.LlndkLibraryFactory)) ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) { ctx.BottomUp("link", cc.LinkageMutator).Parallel() ctx.BottomUp("begin", cc.BeginMutator).Parallel() |
