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

Commit 89226d9e authored by Colin Cross's avatar Colin Cross
Browse files

Add jni_libs to host java binaries

Add a property to support dependencies on JNI libraries for host
java binaries.

Fixes: 170389375
Test: TestBinary
Change-Id: Ieeca3c3997615f0b17ae1f058b94e6c9ba929cab
parent c179ea68
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -2432,6 +2432,10 @@ type binaryProperties struct {

	// Name of the class containing main to be inserted into the manifest as Main-Class.
	Main_class *string

	// Names of modules containing JNI libraries that should be installed alongside the host
	// variant of the binary.
	Jni_libs []string
}

type Binary struct {
@@ -2473,8 +2477,8 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
		}

		// The host installation rules make the installed wrapper depend on all the dependencies
		// of the wrapper variant, which will include the common variant's jar file.  This is
		// verified by TestBinary.
		// of the wrapper variant, which will include the common variant's jar file and any JNI
		// libraries.  This is verified by TestBinary.
		j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
			ctx.ModuleName(), j.wrapperFile)
	}
@@ -2483,6 +2487,10 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
func (j *Binary) DepsMutator(ctx android.BottomUpMutatorContext) {
	if ctx.Arch().ArchType == android.Common {
		j.deps(ctx)
	} else {
		// This dependency ensures the host installation rules will install the jni libraries
		// when the wrapper is installed.
		ctx.AddVariationDependencies(nil, jniLibTag, j.binaryProperties.Jni_libs...)
	}
}

+16 −0
Original line number Diff line number Diff line
@@ -456,6 +456,14 @@ func TestBinary(t *testing.T) {
			name: "bar",
			srcs: ["b.java"],
			static_libs: ["foo"],
			jni_libs: ["libjni"],
		}

		cc_library_shared {
			name: "libjni",
			host_supported: true,
			device_supported: false,
			stl: "none",
		}
	`)

@@ -466,10 +474,18 @@ func TestBinary(t *testing.T) {
	barWrapper := ctx.ModuleForTests("bar", buildOS+"_x86_64")
	barWrapperDeps := barWrapper.Output("bar").Implicits.Strings()

	libjni := ctx.ModuleForTests("libjni", buildOS+"_x86_64_shared")
	libjniSO := libjni.Rule("Cp").Output.String()

	// Test that the install binary wrapper depends on the installed jar file
	if g, w := barWrapperDeps, barJar; !android.InList(w, g) {
		t.Errorf("expected binary wrapper implicits to contain %q, got %q", w, g)
	}

	// Test that the install binary wrapper depends on the installed JNI libraries
	if g, w := barWrapperDeps, libjniSO; !android.InList(w, g) {
		t.Errorf("expected binary wrapper implicits to contain %q, got %q", w, g)
	}
}

func TestHostBinaryNoJavaDebugInfoOverride(t *testing.T) {