Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe46293c authored by John Wu's avatar John Wu Committed by Makoto Onuki
Browse files

[Ravenwood] Generate manifest.properties for Ravenwood tests

Allow setting targetSdkLevel and package name for Ravenwood tests.

Bug: 377765941
Flag: EXEMPT host test change only
Test: m --no-skip-soong-tests nothing
Change-Id: I5f8562cae2c027b400e678ef1745f3221b6268a8
parent 8ffb90f6
Loading
Loading
Loading
Loading
+42 −0
Original line number Original line Diff line number Diff line
@@ -14,6 +14,8 @@
package java
package java


import (
import (
	"strconv"

	"android/soong/android"
	"android/soong/android"
	"android/soong/tradefed"
	"android/soong/tradefed"


@@ -36,6 +38,14 @@ var ravenwoodRuntimeTag = dependencyTag{name: "ravenwoodruntime"}
var ravenwoodTestResourceApkTag = dependencyTag{name: "ravenwoodtestresapk"}
var ravenwoodTestResourceApkTag = dependencyTag{name: "ravenwoodtestresapk"}
var ravenwoodTestInstResourceApkTag = dependencyTag{name: "ravenwoodtest-inst-res-apk"}
var ravenwoodTestInstResourceApkTag = dependencyTag{name: "ravenwoodtest-inst-res-apk"}


var genManifestProperties = pctx.AndroidStaticRule("genManifestProperties",
	blueprint.RuleParams{
		Command: "echo targetSdkVersionInt=$targetSdkVersionInt > $out && " +
			"echo targetSdkVersionRaw=$targetSdkVersionRaw >> $out && " +
			"echo packageName=$packageName >> $out && " +
			"echo instPackageName=$instPackageName >> $out",
	}, "targetSdkVersionInt", "targetSdkVersionRaw", "packageName", "instPackageName")

const ravenwoodUtilsName = "ravenwood-utils"
const ravenwoodUtilsName = "ravenwood-utils"
const ravenwoodRuntimeName = "ravenwood-runtime"
const ravenwoodRuntimeName = "ravenwood-runtime"


@@ -68,6 +78,17 @@ type ravenwoodTestProperties struct {
	// the ravenwood test can access it. This APK will be loaded as resources of the test
	// the ravenwood test can access it. This APK will be loaded as resources of the test
	// instrumentation app itself.
	// instrumentation app itself.
	Inst_resource_apk *string
	Inst_resource_apk *string

	// Specify the package name of the test target apk.
	// This will be set to the target Context's package name.
	// (i.e. Instrumentation.getTargetContext().getPackageName())
	// If this is omitted, Package_name will be used.
	Package_name *string

	// Specify the package name of this test module.
	// This will be set to the test Context's package name.
	//(i.e. Instrumentation.getContext().getPackageName())
	Inst_package_name *string
}
}


type ravenwoodTest struct {
type ravenwoodTest struct {
@@ -216,6 +237,27 @@ func (r *ravenwoodTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	copyResApk(ravenwoodTestResourceApkTag, "ravenwood-res.apk")
	copyResApk(ravenwoodTestResourceApkTag, "ravenwood-res.apk")
	copyResApk(ravenwoodTestInstResourceApkTag, "ravenwood-inst-res.apk")
	copyResApk(ravenwoodTestInstResourceApkTag, "ravenwood-inst-res.apk")


	// Generate manifest properties
	propertiesOutputPath := android.PathForModuleGen(ctx, "ravenwood.properties")

	targetSdkVersion := proptools.StringDefault(r.deviceProperties.Target_sdk_version, "")
	targetSdkVersionInt := r.TargetSdkVersion(ctx).FinalOrFutureInt() // FinalOrFutureInt may be 10000.
	packageName := proptools.StringDefault(r.ravenwoodTestProperties.Package_name, "")
	instPackageName := proptools.StringDefault(r.ravenwoodTestProperties.Inst_package_name, "")
	ctx.Build(pctx, android.BuildParams{
		Rule:        genManifestProperties,
		Description: "genManifestProperties",
		Output:      propertiesOutputPath,
		Args: map[string]string{
			"targetSdkVersionInt": strconv.Itoa(targetSdkVersionInt),
			"targetSdkVersionRaw": targetSdkVersion,
			"packageName":         packageName,
			"instPackageName":     instPackageName,
		},
	})
	installProps := ctx.InstallFile(installPath, "ravenwood.properties", propertiesOutputPath)
	installDeps = append(installDeps, installProps)

	// Install our JAR with all dependencies
	// Install our JAR with all dependencies
	ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.outputFile, installDeps...)
	ctx.InstallFile(installPath, ctx.ModuleName()+".jar", r.outputFile, installDeps...)
}
}
+10 −0
Original line number Original line Diff line number Diff line
@@ -177,6 +177,12 @@ func TestRavenwoodTest(t *testing.T) {
			resource_apk: "app2",
			resource_apk: "app2",
			inst_resource_apk: "app3",
			inst_resource_apk: "app3",
			sdk_version: "test_current",
			sdk_version: "test_current",
			target_sdk_version: "34",
			package_name: "a.b.c",
			inst_package_name: "x.y.z",
		}
		android_ravenwood_test {
			name: "ravenwood-test-empty",
		}
		}
	`)
	`)


@@ -199,12 +205,16 @@ func TestRavenwoodTest(t *testing.T) {
	// Verify that we've emitted test artifacts in expected location
	// Verify that we've emitted test artifacts in expected location
	outputJar := module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.jar")
	outputJar := module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.jar")
	module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.config")
	module.Output(installPathPrefix + "/ravenwood-test/ravenwood-test.config")
	module.Output(installPathPrefix + "/ravenwood-test/ravenwood.properties")
	module.Output(installPathPrefix + "/ravenwood-test/lib64/jni-lib1.so")
	module.Output(installPathPrefix + "/ravenwood-test/lib64/jni-lib1.so")
	module.Output(installPathPrefix + "/ravenwood-test/lib64/libblue.so")
	module.Output(installPathPrefix + "/ravenwood-test/lib64/libblue.so")
	module.Output(installPathPrefix + "/ravenwood-test/lib64/libpink.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-res.apk")
	module.Output(installPathPrefix + "/ravenwood-test/ravenwood-res-apks/ravenwood-inst-res.apk")
	module.Output(installPathPrefix + "/ravenwood-test/ravenwood-res-apks/ravenwood-inst-res.apk")


	module = ctx.ModuleForTests("ravenwood-test-empty", "android_common")
	module.Output(installPathPrefix + "/ravenwood-test-empty/ravenwood.properties")

	// ravenwood-runtime*.so are included in the runtime, so it shouldn't be emitted.
	// ravenwood-runtime*.so are included in the runtime, so it shouldn't be emitted.
	for _, o := range module.AllOutputs() {
	for _, o := range module.AllOutputs() {
		android.AssertStringDoesNotContain(t, "runtime libs shouldn't be included", o, "/ravenwood-test/lib64/ravenwood-runtime")
		android.AssertStringDoesNotContain(t, "runtime libs shouldn't be included", o, "/ravenwood-test/lib64/ravenwood-runtime")