martmists
12/23/2021, 10:39 AMval createPythonDef = tasks.create("createPythonDef") {
fun getVar(name: String) : String {
return ByteArrayOutputStream().use { os ->
val result = exec {
executable = "python3"
args = listOf("-c", "import sysconfig; print(sysconfig.get_paths()['$name'])")
standardOutput = os
}
os.toString().removeSuffixIfPresent("\n")
}
}
doLast {
val lib = getVar("stdlib").split("/").toMutableList()
val libName = lib.removeLast()
val libPath = lib.joinToString("/")
val includePath = getVar("platinclude")
File(project.projectDir.absolutePath + "/src/nativeInterop/cinterop/python.def.template").inputStream().use { istream ->
File(project.projectDir.absolutePath + "/src/nativeInterop/cinterop/python.def").outputStream().use { ostream ->
val content = istream.readAllBytes().decodeToString()
val formatted = content.format(includePath, libPath, libName)
ostream.write(formatted.encodeToByteArray())
}
}
}
}
tasks.getByName("cinteropPythonNative") {
dependsOn(createPythonDef)
}
How would I make sure this runs for everyone and makes the library work as intended, assuming they have python3 installed, or alternatively, how would I make it so I don't need to use the def on the library side but still use the types that are required for my library to work?