From 5d2d0728c027d0d2e51220a2dec46a76f35d2843 Mon Sep 17 00:00:00 2001 From: Laszlo Csomor Date: Mon, 31 Jul 2017 16:31:26 +0200 Subject: 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 --- .../build/lib/windows/jni/WindowsJniLoader.java | 28 ++++++++++++++++++---- .../com/google/devtools/build/android/BUILD.tools | 1 + 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"], ) -- cgit v1.2.3