Unverified Commit a30747fe authored by Nikolay Igotti's avatar Nikolay Igotti Committed by GitHub

Support for custom library path. (#82)

parent a4a1af99
...@@ -52,6 +52,7 @@ val additionalArguments = mutableMapOf<String, String>() ...@@ -52,6 +52,7 @@ val additionalArguments = mutableMapOf<String, String>()
val casualRun = tasks.named<JavaExec>("run") { val casualRun = tasks.named<JavaExec>("run") {
systemProperty("skiko.fps.enabled", "true") systemProperty("skiko.fps.enabled", "true")
// Use systemProperty("skiko.library.path", "/tmp") to test loader.
System.getProperties().entries System.getProperties().entries
.associate { .associate {
(it.key as String) to (it.value as String) (it.key as String) to (it.value as String)
......
...@@ -9,6 +9,7 @@ import java.nio.file.StandardCopyOption ...@@ -9,6 +9,7 @@ import java.nio.file.StandardCopyOption
object Library { object Library {
private var loaded = false private var loaded = false
private val skikoLibraryPath = System.getProperty("skiko.library.path")
private val cacheRoot = "${System.getProperty("user.home")}/.skiko/" private val cacheRoot = "${System.getProperty("user.home")}/.skiko/"
private fun loadOrGet(cacheDir: File, path: String, resourceName: String, isLibrary: Boolean) { private fun loadOrGet(cacheDir: File, path: String, resourceName: String, isLibrary: Boolean) {
...@@ -33,24 +34,30 @@ object Library { ...@@ -33,24 +34,30 @@ object Library {
fun load() { fun load() {
if (loaded) return if (loaded) return
val resourcePath = "/"
val name = "skiko-$hostId" val name = "skiko-$hostId"
val platformName = System.mapLibraryName(name) val platformName = System.mapLibraryName(name)
if (skikoLibraryPath != null) {
val library = File(File(skikoLibraryPath), platformName)
System.load(library.absolutePath)
} else {
val resourcePath = "/"
val hashResourceStream = Library::class.java.getResourceAsStream( val hashResourceStream = Library::class.java.getResourceAsStream(
"$resourcePath$platformName.sha256") ?: throw LibraryLoadException( "$resourcePath$platformName.sha256"
) ?: throw LibraryLoadException(
"Cannot find $platformName.sha256, proper native dependency missing." "Cannot find $platformName.sha256, proper native dependency missing."
) )
val hash = hashResourceStream.use { val hash = hashResourceStream.use {
BufferedReader(InputStreamReader(it)).lines().toArray()[0] as String BufferedReader(InputStreamReader(it)).lines().toArray()[0] as String
} }
val cacheDir = File("$cacheRoot/$hash") val cacheDir = File(File(cacheRoot), hash)
cacheDir.mkdirs() cacheDir.mkdirs()
loadOrGet(cacheDir, resourcePath, platformName, true) loadOrGet(cacheDir, resourcePath, platformName, true)
val loadIcu = hostOs.isWindows val loadIcu = hostOs.isWindows
if (loadIcu) { if (loadIcu) {
loadOrGet(cacheDir, resourcePath, "icudtl.dat", false) loadOrGet(cacheDir, resourcePath, "icudtl.dat", false)
} }
}
// TODO move properties to SkikoProperties // TODO move properties to SkikoProperties
Setup.init( Setup.init(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment