summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
author Colin Cross <ccross@android.com> 2020-10-13 03:33:10 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2020-10-13 03:33:10 +0000
commit9ebc22cf2d2bd8cbe2f5dbdf0fd1eb1ce341b477 (patch)
tree69ec785e32b746947f44a0d48ecd4c04d1fe6efd /java
parentff8838cb86883d6759afd2f325b1ac80be5559a6 (diff)
parent89226d9ef94040215ff9d97212d997a656f5d508 (diff)
Merge changes Ieeca3c39,Iddeea2d0,I8d66a5d3
* changes: Add jni_libs to host java binaries Make java_binary common variant a dependency Replace jniDependencyTag with a value
Diffstat (limited to 'java')
-rwxr-xr-xjava/app.go3
-rw-r--r--java/java.go27
-rw-r--r--java/java_test.go21
3 files changed, 34 insertions, 17 deletions
diff --git a/java/app.go b/java/app.go
index e788ca99f..46ca96918 100755
--- a/java/app.go
+++ b/java/app.go
@@ -379,7 +379,6 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
"can only be set for modules that set sdk_version")
}
- tag := &jniDependencyTag{}
for _, jniTarget := range ctx.MultiTargets() {
variation := append(jniTarget.Variations(),
blueprint.Variation{Mutator: "link", Variation: "shared"})
@@ -393,7 +392,7 @@ func (a *AndroidApp) DepsMutator(ctx android.BottomUpMutatorContext) {
Bool(a.appProperties.Jni_uses_sdk_apis) {
variation = append(variation, blueprint.Variation{Mutator: "sdk", Variation: "sdk"})
}
- ctx.AddFarVariationDependencies(variation, tag, a.appProperties.Jni_libs...)
+ ctx.AddFarVariationDependencies(variation, jniLibTag, a.appProperties.Jni_libs...)
}
a.usesLibrary.deps(ctx, sdkDep.hasFrameworkLibs())
diff --git a/java/java.go b/java/java.go
index 2553a30bd..3ce188586 100644
--- a/java/java.go
+++ b/java/java.go
@@ -547,13 +547,8 @@ type dependencyTag struct {
name string
}
-type jniDependencyTag struct {
- blueprint.BaseDependencyTag
-}
-
func IsJniDepTag(depTag blueprint.DependencyTag) bool {
- _, ok := depTag.(*jniDependencyTag)
- return ok
+ return depTag == jniLibTag
}
var (
@@ -573,6 +568,7 @@ var (
instrumentationForTag = dependencyTag{name: "instrumentation_for"}
usesLibTag = dependencyTag{name: "uses-library"}
extraLintCheckTag = dependencyTag{name: "extra-lint-check"}
+ jniLibTag = dependencyTag{name: "jnilib"}
)
func IsLibDepTag(depTag blueprint.DependencyTag) bool {
@@ -1001,7 +997,7 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
otherName := ctx.OtherModuleName(module)
tag := ctx.OtherModuleDependencyTag(module)
- if _, ok := tag.(*jniDependencyTag); ok {
+ if IsJniDepTag(tag) {
// Handled by AndroidApp.collectAppDeps
return
}
@@ -2436,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 {
@@ -2476,18 +2476,21 @@ func (j *Binary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
j.wrapperFile = android.PathForSource(ctx, "build/soong/scripts/jar-wrapper.sh")
}
- // Depend on the installed jar so that the wrapper doesn't get executed by
- // another build rule before the jar has been installed.
- jarFile := ctx.PrimaryModule().(*Binary).installFile
-
+ // 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 and any JNI
+ // libraries. This is verified by TestBinary.
j.binaryFile = ctx.InstallExecutable(android.PathForModuleInstall(ctx, "bin"),
- ctx.ModuleName(), j.wrapperFile, jarFile)
+ ctx.ModuleName(), j.wrapperFile)
}
}
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...)
}
}
diff --git a/java/java_test.go b/java/java_test.go
index 53053df0e..c751ea4e7 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -460,6 +460,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",
}
`)
@@ -470,10 +478,17 @@ 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 len(barWrapperDeps) != 1 || barWrapperDeps[0] != barJar {
- t.Errorf("expected binary wrapper implicits [%q], got %v",
- barJar, barWrapperDeps)
+ 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)
}
}