aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-07-31 16:31:26 +0200
committerGravatar Dmitry Lomov <dslomov@google.com>2017-07-31 18:39:36 +0200
commit5d2d0728c027d0d2e51220a2dec46a76f35d2843 (patch)
tree60cd790b5437dcd08959fb27c5689412d90e50ff
parent1a06cb90e8a5bfd6134ed0a00f86cf73eb4cb60f (diff)
Windows: Android BusyBox can access the JNI lib
Add a data-dependency on the windows_jni.dll from the BusyBox in BUILD.tools, so the BusyBox in @build_tools// can actually find it at runtime. Also update the script that builds the .dll so that it works if the source files have an "external/bazel_tools/" prefix. Related to https://github.com/bazelbuild/bazel/issues/3264 Change-Id: I005e9d2c00253a59d2cd5cc9f3a93528dc4d2e9e PiperOrigin-RevId: 163691320
-rw-r--r--src/main/java/com/google/devtools/build/lib/windows/jni/WindowsJniLoader.java28
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/BUILD.tools1
2 files changed, 24 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/windows/jni/WindowsJniLoader.java b/src/main/java/com/google/devtools/build/lib/windows/jni/WindowsJniLoader.java
index 974fe4e6dc..d53a10c479 100644
--- a/src/main/java/com/google/devtools/build/lib/windows/jni/WindowsJniLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/windows/jni/WindowsJniLoader.java
@@ -30,13 +30,31 @@ public class WindowsJniLoader {
System.loadLibrary("windows_jni");
} catch (UnsatisfiedLinkError ex) {
// Try to find the library in the runfiles.
- try {
- System.load(WindowsRunfiles.getRunfile("io_bazel/src/main/native/windows/windows_jni.dll"));
- } catch (IOException e) {
- // We throw the UnsatisfiedLinkError if we cannot find the runfiles
- throw ex;
+ if (!loadFromRunfileOrThrow("io_bazel/src/main/native/windows/windows_jni.dll", ex)) {
+ if (!loadFromRunfileOrThrow(
+ "io_bazel/external/bazel_tools/src/main/native/windows/windows_jni.dll", ex)) {
+ // We throw the UnsatisfiedLinkError if we cannot find the DLL under any known location.
+ throw ex;
+ }
}
}
jniLoaded = true;
}
+
+ private static boolean loadFromRunfileOrThrow(String runfile, UnsatisfiedLinkError ex) {
+ // Try to find the library in the runfiles.
+ String path;
+ try {
+ path = WindowsRunfiles.getRunfile(runfile);
+ if (path == null) {
+ // Just return false if the runfile path was not found. Maybe it's under a different path.
+ return false;
+ }
+ System.load(path);
+ return true;
+ } catch (IOException e) {
+ // We throw the UnsatisfiedLinkError if we cannot find the runfiles
+ throw ex;
+ }
+ }
}
diff --git a/src/tools/android/java/com/google/devtools/build/android/BUILD.tools b/src/tools/android/java/com/google/devtools/build/android/BUILD.tools
index a8670b12b4..e67a400f97 100644
--- a/src/tools/android/java/com/google/devtools/build/android/BUILD.tools
+++ b/src/tools/android/java/com/google/devtools/build/android/BUILD.tools
@@ -11,4 +11,5 @@ java_binary(
runtime_deps = [
":classes",
],
+ data = ["//src/main/native/windows:windows_jni.dll"],
)