From ed392f7097160802d28ae46b85248d61699a2986 Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Tue, 17 Sep 2024 09:56:33 -0700 Subject: [PATCH] Fix resource-apk inclusion - We used to include the "install" files, but we really should be using "output" files instead. - Also supports a new "inst_resource_apk" property, which is another APK that's loaded as resources of the instrumentation app itself. Flag: EXEMPT host test change only Bug: 292141694 Test: m nothing --no-skip-soong-tests Test: manual test with a local test module change and make sure the second apk exists Change-Id: Ibd3f9d4a1cbc0f805b2294605ae8bc06fdf53b75 --- java/ravenwood.go | 24 +++++++++++++++++++----- java/ravenwood_test.go | 6 ++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/java/ravenwood.go b/java/ravenwood.go index 3fa73e64d..9239bbd6b 100644 --- a/java/ravenwood.go +++ b/java/ravenwood.go @@ -34,6 +34,7 @@ var ravenwoodLibContentTag = dependencyTag{name: "ravenwoodlibcontent"} var ravenwoodUtilsTag = dependencyTag{name: "ravenwoodutils"} var ravenwoodRuntimeTag = dependencyTag{name: "ravenwoodruntime"} var ravenwoodTestResourceApkTag = dependencyTag{name: "ravenwoodtestresapk"} +var ravenwoodTestInstResourceApkTag = dependencyTag{name: "ravenwoodtest-inst-res-apk"} const ravenwoodUtilsName = "ravenwood-utils" const ravenwoodRuntimeName = "ravenwood-runtime" @@ -56,11 +57,17 @@ type ravenwoodTestProperties struct { Jni_libs []string // Specify another android_app module here to copy it to the test directory, so that - // the ravenwood test can access it. + // the ravenwood test can access it. This APK will be loaded as resources of the test + // target app. // TODO: For now, we simply refer to another android_app module and copy it to the // test directory. Eventually, android_ravenwood_test should support all the resource // related properties and build resources from the `res/` directory. Resource_apk *string + + // Specify another android_app module here to copy it to the test directory, so that + // the ravenwood test can access it. This APK will be loaded as resources of the test + // instrumentation app itself. + Inst_resource_apk *string } type ravenwoodTest struct { @@ -127,6 +134,10 @@ func (r *ravenwoodTest) DepsMutator(ctx android.BottomUpMutatorContext) { if resourceApk := proptools.String(r.ravenwoodTestProperties.Resource_apk); resourceApk != "" { ctx.AddVariationDependencies(nil, ravenwoodTestResourceApkTag, resourceApk) } + + if resourceApk := proptools.String(r.ravenwoodTestProperties.Inst_resource_apk); resourceApk != "" { + ctx.AddVariationDependencies(nil, ravenwoodTestInstResourceApkTag, resourceApk) + } } func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { @@ -194,13 +205,16 @@ func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) { } resApkInstallPath := installPath.Join(ctx, "ravenwood-res-apks") - if resApk := ctx.GetDirectDepsWithTag(ravenwoodTestResourceApkTag); len(resApk) > 0 { - for _, installFile := range android.OtherModuleProviderOrDefault( - ctx, resApk[0], android.InstallFilesProvider).InstallFiles { - installResApk := ctx.InstallFile(resApkInstallPath, "ravenwood-res.apk", installFile) + + copyResApk := func(tag blueprint.DependencyTag, toFileName string) { + if resApk := ctx.GetDirectDepsWithTag(tag); len(resApk) > 0 { + installFile := android.OutputFileForModule(ctx, resApk[0], "") + installResApk := ctx.InstallFile(resApkInstallPath, toFileName, installFile) installDeps = append(installDeps, installResApk) } } + copyResApk(ravenwoodTestResourceApkTag, "ravenwood-res.apk") + copyResApk(ravenwoodTestInstResourceApkTag, "ravenwood-inst-res.apk") // Install our JAR with all dependencies ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.outputFile, installDeps...) diff --git a/java/ravenwood_test.go b/java/ravenwood_test.go index 0a1b08926..753a118e9 100644 --- a/java/ravenwood_test.go +++ b/java/ravenwood_test.go @@ -66,6 +66,10 @@ var prepareRavenwoodRuntime = android.GroupFixturePreparers( name: "app2", sdk_version: "current", } + android_app { + name: "app3", + sdk_version: "current", + } prebuilt_font { name: "Font.ttf", src: "Font.ttf", @@ -167,6 +171,7 @@ func TestRavenwoodTest(t *testing.T) { "ravenwood-runtime-jni2", ], resource_apk: "app2", + inst_resource_apk: "app3", sdk_version: "test_current", } `) @@ -194,6 +199,7 @@ func TestRavenwoodTest(t *testing.T) { module.Output(installPathPrefix + "/ravenwood-test/lib64/libblue.so") module.Output(installPathPrefix + "/ravenwood-test/lib64/libpink.so") module.Output(installPathPrefix + "/ravenwood-test/ravenwood-res-apks/ravenwood-res.apk") + module.Output(installPathPrefix + "/ravenwood-test/ravenwood-res-apks/ravenwood-inst-res.apk") // ravenwood-runtime*.so are included in the runtime, so it shouldn't be emitted. for _, o := range module.AllOutputs() {