Update runpath for jni libs
To support stem, cc libraries will be generated in <pacakge_name>/<label.name>. Update RUNPATH of java binaries so that it can find its jni deps Test: bp2build Test: TH Bug: 240563612 Change-Id: Ia2f70f0424a8526ee35856225c1a8cd1067a8570
This commit is contained in:
@@ -68,7 +68,7 @@ func TestJavaBinaryHost(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
|
MakeBazelTarget("java_binary", "java-binary-host-1", AttrNameToString{
|
||||||
"main_class": `"com.android.test.MainClass"`,
|
"main_class": `"com.android.test.MainClass"`,
|
||||||
"jvm_flags": `["-Djava.library.path=$${RUNPATH}other"]`,
|
"jvm_flags": `["-Djava.library.path=$${RUNPATH}other/jni-lib-1"]`,
|
||||||
"target_compatible_with": `select({
|
"target_compatible_with": `select({
|
||||||
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
"//build/bazel/platforms/os:android": ["@platforms//:incompatible"],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
|
39
java/java.go
39
java/java.go
@@ -3104,24 +3104,15 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
|
|||||||
// Attribute jvm_flags
|
// Attribute jvm_flags
|
||||||
var jvmFlags bazel.StringListAttribute
|
var jvmFlags bazel.StringListAttribute
|
||||||
if m.binaryProperties.Jni_libs != nil {
|
if m.binaryProperties.Jni_libs != nil {
|
||||||
jniLibPackages := map[string]bool{}
|
jniLibPackages := []string{}
|
||||||
for _, jniLibLabel := range android.BazelLabelForModuleDeps(ctx, m.binaryProperties.Jni_libs).Includes {
|
for _, jniLib := range m.binaryProperties.Jni_libs {
|
||||||
jniLibPackage := jniLibLabel.Label
|
if jniLibModule, exists := ctx.ModuleFromName(jniLib); exists {
|
||||||
indexOfColon := strings.Index(jniLibLabel.Label, ":")
|
otherDir := ctx.OtherModuleDir(jniLibModule)
|
||||||
if indexOfColon > 0 {
|
jniLibPackages = append(jniLibPackages, filepath.Join(otherDir, jniLib))
|
||||||
// JNI lib from other package
|
|
||||||
jniLibPackage = jniLibLabel.Label[2:indexOfColon]
|
|
||||||
} else if indexOfColon == 0 {
|
|
||||||
// JNI lib in the same package of java_binary
|
|
||||||
packageOfCurrentModule := m.GetBazelLabel(ctx, m)
|
|
||||||
jniLibPackage = packageOfCurrentModule[2:strings.Index(packageOfCurrentModule, ":")]
|
|
||||||
}
|
|
||||||
if _, inMap := jniLibPackages[jniLibPackage]; !inMap {
|
|
||||||
jniLibPackages[jniLibPackage] = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jniLibPaths := []string{}
|
jniLibPaths := []string{}
|
||||||
for jniLibPackage, _ := range jniLibPackages {
|
for _, jniLibPackage := range jniLibPackages {
|
||||||
// See cs/f:.*/third_party/bazel/.*java_stub_template.txt for the use of RUNPATH
|
// See cs/f:.*/third_party/bazel/.*java_stub_template.txt for the use of RUNPATH
|
||||||
jniLibPaths = append(jniLibPaths, "$${RUNPATH}"+jniLibPackage)
|
jniLibPaths = append(jniLibPaths, "$${RUNPATH}"+jniLibPackage)
|
||||||
}
|
}
|
||||||
@@ -3145,9 +3136,9 @@ func javaBinaryHostBp2Build(ctx android.TopDownMutatorContext, m *Binary) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
libInfo := libraryCreationInfo{
|
libInfo := libraryCreationInfo{
|
||||||
deps: deps,
|
deps: deps,
|
||||||
attrs: commonAttrs,
|
attrs: commonAttrs,
|
||||||
baseName: m.Name(),
|
baseName: m.Name(),
|
||||||
hasKotlin: bp2BuildInfo.hasKotlin,
|
hasKotlin: bp2BuildInfo.hasKotlin,
|
||||||
}
|
}
|
||||||
libName := createLibraryTarget(ctx, libInfo)
|
libName := createLibraryTarget(ctx, libInfo)
|
||||||
@@ -3189,9 +3180,9 @@ func javaTestHostBp2Build(ctx android.TopDownMutatorContext, m *TestHost) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
libInfo := libraryCreationInfo{
|
libInfo := libraryCreationInfo{
|
||||||
deps: deps,
|
deps: deps,
|
||||||
attrs: commonAttrs,
|
attrs: commonAttrs,
|
||||||
baseName: m.Name(),
|
baseName: m.Name(),
|
||||||
hasKotlin: bp2BuildInfo.hasKotlin,
|
hasKotlin: bp2BuildInfo.hasKotlin,
|
||||||
}
|
}
|
||||||
libName := createLibraryTarget(ctx, libInfo)
|
libName := createLibraryTarget(ctx, libInfo)
|
||||||
@@ -3204,9 +3195,9 @@ func javaTestHostBp2Build(ctx android.TopDownMutatorContext, m *TestHost) {
|
|||||||
// libraryCreationInfo encapsulates the info needed to create java_library target from
|
// libraryCreationInfo encapsulates the info needed to create java_library target from
|
||||||
// java_binary_host or java_test_host.
|
// java_binary_host or java_test_host.
|
||||||
type libraryCreationInfo struct {
|
type libraryCreationInfo struct {
|
||||||
deps bazel.LabelListAttribute
|
deps bazel.LabelListAttribute
|
||||||
attrs *javaCommonAttributes
|
attrs *javaCommonAttributes
|
||||||
baseName string
|
baseName string
|
||||||
hasKotlin bool
|
hasKotlin bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user