Skip to content

Commit

Permalink
fix(jawt): revert d20409b and implement a better fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Dec 7, 2017
1 parent 7f7a521 commit 95d6bfd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
18 changes: 18 additions & 0 deletions modules/core/src/main/java/org/lwjgl/system/APIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import java.lang.reflect.*;
import java.net.*;
import java.nio.*;
import java.nio.file.*;
import java.util.*;
import java.util.function.*;
import java.util.jar.*;
import java.util.regex.*;
import java.util.stream.*;

import static org.lwjgl.system.Checks.*;
import static org.lwjgl.system.MemoryUtil.*;
Expand Down Expand Up @@ -97,6 +99,22 @@ public static Optional<String> apiGetManifestValue(String attributeName) {
return Optional.empty();
}

public static String apiFindLibrary(String start, String name) {
String libName = Platform.get().mapLibraryName(name);
try (Stream<Path> paths = Files.find(
Paths.get(start).toAbsolutePath(),
Integer.MAX_VALUE,
(path, attributes) -> attributes.isRegularFile() && path.getFileName().toString().equals(libName)
)) {
return paths
.findFirst()
.map(Path::toString)
.orElse(name);
} catch (IOException e) {
return name;
}
}

public static SharedLibrary apiCreateLibrary(String name) {
switch (Platform.get()) {
case WINDOWS:
Expand Down
7 changes: 3 additions & 4 deletions modules/core/src/main/java/org/lwjgl/system/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,14 @@ public static SharedLibrary loadNative(Class<?> context, String name) {
public static SharedLibrary loadNative(Class<?> context, String name, boolean bundledWithLWJGL) {
apiLog("Loading library: " + name);

String libName = Platform.get().mapLibraryName(name);

// METHOD 1: absolute path
if (new File(libName).isAbsolute()) {
SharedLibrary lib = apiCreateLibrary(libName);
if (new File(name).isAbsolute()) {
SharedLibrary lib = apiCreateLibrary(name);
apiLog("\tSuccess");
return lib;
}

String libName = Platform.get().mapLibraryName(name);
SharedLibrary lib;

// METHOD 2: org.lwjgl.librarypath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.lwjgl.system.jni.*

val jawt = "JAWTFunctions".nativeClass(JAWT_PACKAGE, prefix = "JAWT_", prefixMethod = "JAWT_", binding = simpleBinding(
"jawt",
libraryExpression = """Configuration.JAWT_LIBRARY_NAME, "jawt", System.getProperty("java.home") + "/bin/jawt"""",
libraryExpression = """Configuration.JAWT_LIBRARY_NAME, "jawt", apiFindLibrary(System.getProperty("java.home"), "jawt")""",
callingConvention = CallingConvention.STDCALL
)) {
nativeDirective(
Expand Down

0 comments on commit 95d6bfd

Please sign in to comment.