1010
1111package co.touchlab.cklib.gradle
1212
13+ import org.gradle.api.GradleException
1314import org.gradle.api.Plugin
1415import org.gradle.api.Project
1516import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
16- import org.rauschig.jarchivelib.ArchiveFormat
17- import org.rauschig.jarchivelib.ArchiverFactory
1817import java.io.BufferedInputStream
1918import java.io.File
2019import java.io.FileOutputStream
@@ -23,6 +22,9 @@ import java.util.*
2322
2423class CompileToBitcodePlugin : Plugin <Project > {
2524 override fun apply (target : Project ) = with (target) {
25+ if (osName == " windows" ) {
26+ throw GradleException (" Windows is currently not compatible with cklib" )
27+ }
2628 extensions.create(EXTENSION_NAME , CompileToBitcodeExtension ::class .java, target)
2729 downloadIfNeeded(target)
2830
@@ -45,31 +47,31 @@ class CompileToBitcodePlugin : Plugin<Project> {
4547 // This is pretty hacky, but the process changed in 1.6.0. We'll probably just split off and do our own thing
4648 // going forward, but need to be able to build for the next few weeks.
4749 private fun downloadIfNeeded (target : Project ) {
48- val cklibDir = File (" ${ System .getProperty( " user.home " )} /.cklib " )
49- val localFile = File (cklibDir, " clang-llvm-apple-8.0.0-darwin-macos " )
50+ val cklibDir = File (defaultCklibDir )
51+ val localFile = File (cklibDir, llvmName )
5052 val clangExists = localFile.exists()
5153 if (! clangExists){
5254 target.logger.info(" cklib downloading dependencies (may take a while...)" )
5355 cklibDir.mkdirs()
5456 val tempFileName = UUID .randomUUID().toString()
55- val extractDir = File (cklibDir, tempFileName)
56- val tempDl = File (cklibDir, " ${tempFileName} .zip " )
57+ val tempFileNameWithExtension = " ${ tempFileName} .tar.gz "
58+ val tempDl = File (cklibDir, tempFileNameWithExtension )
5759
5860 try {
5961 val fos = FileOutputStream (tempDl)
60- val inp = BufferedInputStream (URL (" https://touchlab-deps-public.s3.us-east-2.amazonaws.com/clang-llvm-apple-8.0.0-darwin-macos.zip" ).openStream())
62+
63+ val inp = BufferedInputStream (URL (" https://download.jetbrains.com/kotlin/native/${llvmName} .tar.gz" ).openStream())
6164 inp.copyTo(fos)
6265 fos.close()
6366 inp.close()
6467
65- val archiver = ArchiverFactory .createArchiver( ArchiveFormat . ZIP )
66-
67- archiver.extract(tempDl, extractDir)
68- val extractChild = File (extractDir, " clang-llvm-apple-8.0.0-darwin-macos " )
69- extractChild.renameTo(localFile)
68+ target.exec {
69+ it.workingDir = cklibDir.absoluteFile
70+ it.executable = " tar "
71+ it.args = listOf ( " -xf " , tempFileNameWithExtension )
72+ }
7073 } finally {
7174 tempDl.delete()
72- extractDir.delete()
7375 }
7476 }
7577 }
0 commit comments