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

Commit 0fc368cf authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Generate a default wrapper for device java_binary"

parents 3bb3763a ca65b40f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ func TestDexpreoptEnabled(t *testing.T) {
				java_binary {
					name: "foo",
					srcs: ["a.java"],
					main_class: "foo.bar.jb",
				}`,
			enabled: true,
		},
+33 −1
Original line number Diff line number Diff line
@@ -211,6 +211,14 @@ var (
			PropertyName: "java_tests",
		},
	}

	// Rule for generating device binary default wrapper
	deviceBinaryWrapper = pctx.StaticRule("deviceBinaryWrapper", blueprint.RuleParams{
		Command: `echo -e '#!/system/bin/sh\n` +
			`export CLASSPATH=/system/framework/$jar_name\n` +
			`exec app_process /$partition/bin $main_class "$$@"'> ${out}`,
		Description: "Generating device binary wrapper ${jar_name}",
	}, "jar_name", "partition", "main_class")
)

// JavaInfo contains information about a java module for use by modules that depend on it.
@@ -1398,8 +1406,32 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
				ctx.PropertyErrorf("wrapper", "wrapper is required for Windows")
			}

			if ctx.Device() {
				// device binary should have a main_class property if it does not
				// have a specific wrapper, so that a default wrapper can
				// be generated for it.
				if j.binaryProperties.Main_class == nil {
					ctx.PropertyErrorf("main_class", "main_class property "+
						"is required for device binary if no default wrapper is assigned")
				} else {
					wrapper := android.PathForModuleOut(ctx, ctx.ModuleName()+".sh")
					jarName := j.Stem() + ".jar"
					partition := j.PartitionTag(ctx.DeviceConfig())
					ctx.Build(pctx, android.BuildParams{
						Rule:   deviceBinaryWrapper,
						Output: wrapper,
						Args: map[string]string{
							"jar_name":   jarName,
							"partition":  partition,
							"main_class": String(j.binaryProperties.Main_class),
						},
					})
					j.wrapperFile = wrapper
				}
			} else {
				j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
			}
		}

		ext := ""
		if ctx.Windows() {
+23 −0
Original line number Diff line number Diff line
@@ -1783,3 +1783,26 @@ func TestGenAidlIncludeFlagsForMixedBuilds(t *testing.T) {
		t.Errorf("expected flags to be %q; was %q", expectedFlags, flags)
	}
}

func TestDeviceBinaryWrapperGeneration(t *testing.T) {
	// Scenario 1: java_binary has main_class property in its bp
	ctx, _ := testJava(t, `
		java_binary {
			name: "foo",
			srcs: ["foo.java"],
			main_class: "foo.bar.jb",
		}
	`)
	wrapperPath := fmt.Sprint(ctx.ModuleForTests("foo", "android_arm64_armv8-a").AllOutputs())
	if !strings.Contains(wrapperPath, "foo.sh") {
		t.Errorf("wrapper file foo.sh is not generated")
	}

	// Scenario 2: java_binary has neither wrapper nor main_class, its build
	// is expected to be failed.
	testJavaError(t, "main_class property is required for device binary if no default wrapper is assigned", `
		java_binary {
			name: "foo",
			srcs: ["foo.java"],
		}`)
}