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,23 +34,29 @@ object Library { ...@@ -33,23 +34,29 @@ 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)
val hashResourceStream = Library::class.java.getResourceAsStream( if (skikoLibraryPath != null) {
"$resourcePath$platformName.sha256") ?: throw LibraryLoadException( val library = File(File(skikoLibraryPath), platformName)
"Cannot find $platformName.sha256, proper native dependency missing." System.load(library.absolutePath)
) } else {
val hash = hashResourceStream.use { val resourcePath = "/"
BufferedReader(InputStreamReader(it)).lines().toArray()[0] as String val hashResourceStream = Library::class.java.getResourceAsStream(
} "$resourcePath$platformName.sha256"
val cacheDir = File("$cacheRoot/$hash") ) ?: throw LibraryLoadException(
cacheDir.mkdirs() "Cannot find $platformName.sha256, proper native dependency missing."
loadOrGet(cacheDir, resourcePath, platformName, true) )
val loadIcu = hostOs.isWindows val hash = hashResourceStream.use {
if (loadIcu) { BufferedReader(InputStreamReader(it)).lines().toArray()[0] as String
loadOrGet(cacheDir, resourcePath, "icudtl.dat", false) }
val cacheDir = File(File(cacheRoot), hash)
cacheDir.mkdirs()
loadOrGet(cacheDir, resourcePath, platformName, true)
val loadIcu = hostOs.isWindows
if (loadIcu) {
loadOrGet(cacheDir, resourcePath, "icudtl.dat", false)
}
} }
// TODO move properties to SkikoProperties // TODO move properties to SkikoProperties
......
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