diff options
author | Pascal Muetschard <pmuetschard@google.com> | 2018-01-08 10:19:08 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-08 10:21:12 -0800 |
commit | 5e708b99cc40f0f9bc99fd6bb962a2a3fae3bc64 (patch) | |
tree | 531378009d33920c04b7eb56644c3331fbb68d1b /src/main/java/com/google/devtools/build/lib/windows/jni | |
parent | e00b457a727e8511e7330d6a0ca5b98898865aaf (diff) |
Add another path to the windows_jni.dll lookup.
This is to fix building android outside of the bazel repository.
To reproduce the issue (on a Windows machine, of course):
1. Copy the examples/android folder from a bazel checkout to a new folder (keep the same folder structure - i.e. `<new folder>/examples/android`)
2. Create a `WORKSPACE` file in `<new folder>` with the `android_sdk_repository` and `android_ndk_repository` rules as described in the example README.
3. `bazel build examples/android/java/bazel:hello_world`
4. Observe the failure to locate `windows_jni.dll`
Closes #4392.
PiperOrigin-RevId: 181181641
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/windows/jni')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/windows/jni/WindowsJniLoader.java | 25 |
1 files changed, 18 insertions, 7 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 d53a10c479..7e4aba28f3 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 @@ -19,6 +19,12 @@ import java.io.IOException; /** Loads native code under Windows. */ public class WindowsJniLoader { + private static final String[] SEARCH_PATHS = { + "io_bazel/src/main/native/windows/windows_jni.dll", + "io_bazel/external/bazel_tools/src/main/native/windows/windows_jni.dll", + "bazel_tools/src/main/native/windows/windows_jni.dll", + }; + private static boolean jniLoaded = false; public static synchronized void loadJni() { @@ -30,17 +36,22 @@ public class WindowsJniLoader { System.loadLibrary("windows_jni"); } catch (UnsatisfiedLinkError ex) { // Try to find the library in the runfiles. - 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; - } - } + loadFromRunfileOrThrow(ex); } jniLoaded = true; } + private static void loadFromRunfileOrThrow(UnsatisfiedLinkError ex) { + for (String path : SEARCH_PATHS) { + if (loadFromRunfileOrThrow(path, ex)) { + return; + } + } + + // We throw the UnsatisfiedLinkError if we cannot find the DLL under any known location. + throw ex; + } + private static boolean loadFromRunfileOrThrow(String runfile, UnsatisfiedLinkError ex) { // Try to find the library in the runfiles. String path; |