[DependencyProcessor] Untie from platform-default archive type
MinGW artifacts have `.zip` extension, while their versions for Linux and macOS have `.tar.gz`. To be able to download zips on macOS (and vice-versa) we pass archive type as parameter to DependencyProcessor.
This commit is contained in:
committed by
Sergey Bogolepov
parent
e147993ff2
commit
eb486a6e45
Vendored
+4
-6
@@ -5,13 +5,10 @@
|
||||
import groovy.transform.stc.ClosureParams
|
||||
import groovy.transform.stc.FromString
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.util.DependencyProcessor
|
||||
import static org.jetbrains.kotlin.konan.target.KonanTarget.*
|
||||
import org.jetbrains.kotlin.konan.util.Named
|
||||
import org.jetbrains.kotlin.konan.properties.KonanPropertiesLoader
|
||||
import org.jetbrains.kotlin.konan.target.ConfigurablesImplKt
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.TargetManager
|
||||
import org.jetbrains.kotlin.konan.util.ArchiveType
|
||||
import org.jetbrains.kotlin.konan.util.DependencyProcessor
|
||||
|
||||
import static org.jetbrains.kotlin.konan.util.VisibleNamedKt.getVisibleName
|
||||
@@ -43,7 +40,7 @@ class NativeDep extends DefaultTask {
|
||||
|
||||
@TaskAction
|
||||
void downloadAndExtract() {
|
||||
def downloader = new DependencyProcessor(baseOutDir, konanPropertiesLoader, baseUrl, false)
|
||||
def downloader = new DependencyProcessor(baseOutDir, konanPropertiesLoader, baseUrl, false, ArchiveType.systemDefault)
|
||||
downloader.showInfo = false
|
||||
downloader.run()
|
||||
}
|
||||
@@ -94,7 +91,8 @@ platformManager.filteredOutEnabledButNotSupported.each { target ->
|
||||
loader.properties,
|
||||
loader.dependencies,
|
||||
NativeDep.baseUrl,
|
||||
false
|
||||
false,
|
||||
ArchiveType.systemDefault
|
||||
)
|
||||
|
||||
DependencyKind.values().each { kind ->
|
||||
|
||||
@@ -20,16 +20,22 @@ import org.jetbrains.kotlin.konan.file.unzipTo
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
enum class ArchiveType(val fileExtension: String) {
|
||||
ZIP("zip"),
|
||||
TAR_GZ("tar.gz");
|
||||
|
||||
class DependencyExtractor {
|
||||
internal val useZip = System.getProperty("os.name").startsWith("Windows")
|
||||
|
||||
internal val archiveExtension = if (useZip) {
|
||||
"zip"
|
||||
} else {
|
||||
"tar.gz"
|
||||
companion object {
|
||||
val systemDefault = if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
ZIP
|
||||
} else {
|
||||
TAR_GZ
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DependencyExtractor(
|
||||
private val archiveType: ArchiveType
|
||||
) {
|
||||
private fun extractTarGz(tarGz: File, targetDirectory: File) {
|
||||
val tarProcess = ProcessBuilder().apply {
|
||||
command("tar", "-xzf", tarGz.canonicalPath)
|
||||
@@ -53,10 +59,9 @@ class DependencyExtractor {
|
||||
}
|
||||
|
||||
fun extract(archive: File, targetDirectory: File) {
|
||||
if (useZip) {
|
||||
archive.toPath().unzipTo(targetDirectory.toPath())
|
||||
} else {
|
||||
extractTarGz(archive, targetDirectory)
|
||||
when (archiveType) {
|
||||
ArchiveType.ZIP -> archive.toPath().unzipTo(targetDirectory.toPath())
|
||||
ArchiveType.TAR_GZ -> extractTarGz(archive, targetDirectory)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,8 @@ class DependencyProcessor(dependenciesRoot: File,
|
||||
attemptIntervalMs: Long = DependencyDownloader.DEFAULT_ATTEMPT_INTERVAL_MS,
|
||||
customProgressCallback: ProgressCallback? = null,
|
||||
val keepUnstable: Boolean = true,
|
||||
val deleteArchives: Boolean = true) {
|
||||
val deleteArchives: Boolean = true,
|
||||
private val archiveType: ArchiveType = ArchiveType.systemDefault) {
|
||||
|
||||
val dependenciesDirectory = dependenciesRoot.apply { mkdirs() }
|
||||
val cacheDirectory = homeDependencyCache.apply { mkdirs() }
|
||||
@@ -104,32 +105,34 @@ class DependencyProcessor(dependenciesRoot: File,
|
||||
private var isInfoShown = false
|
||||
|
||||
private val downloader = DependencyDownloader(maxAttempts, attemptIntervalMs, customProgressCallback)
|
||||
private val extractor = DependencyExtractor()
|
||||
|
||||
private val archiveExtension get() = extractor.archiveExtension
|
||||
private val extractor = DependencyExtractor(archiveType)
|
||||
|
||||
constructor(dependenciesRoot: File,
|
||||
properties: KonanPropertiesLoader,
|
||||
dependenciesUrl: String = properties.dependenciesUrl,
|
||||
keepUnstable:Boolean = true) : this(
|
||||
keepUnstable:Boolean = true,
|
||||
archiveType: ArchiveType = ArchiveType.systemDefault) : this(
|
||||
dependenciesRoot,
|
||||
properties.properties,
|
||||
properties.dependencies,
|
||||
dependenciesUrl,
|
||||
keepUnstable = keepUnstable)
|
||||
keepUnstable = keepUnstable,
|
||||
archiveType = archiveType)
|
||||
|
||||
constructor(dependenciesRoot: File,
|
||||
properties: Properties,
|
||||
dependencies: List<String>,
|
||||
dependenciesUrl: String = properties.dependenciesUrl,
|
||||
keepUnstable:Boolean = true) : this(
|
||||
keepUnstable:Boolean = true,
|
||||
archiveType: ArchiveType = ArchiveType.systemDefault) : this(
|
||||
dependenciesRoot,
|
||||
dependenciesUrl,
|
||||
dependencyToCandidates = properties.findCandidates(dependencies),
|
||||
airplaneMode = properties.airplaneMode,
|
||||
maxAttempts = properties.downloadingAttempts,
|
||||
attemptIntervalMs = properties.downloadingAttemptIntervalMs,
|
||||
keepUnstable = keepUnstable)
|
||||
keepUnstable = keepUnstable,
|
||||
archiveType = archiveType)
|
||||
|
||||
|
||||
class DependencyFile(directory: File, fileName: String) {
|
||||
@@ -165,7 +168,7 @@ class DependencyProcessor(dependenciesRoot: File,
|
||||
val depDir = File(dependenciesDirectory, dependency)
|
||||
val depName = depDir.name
|
||||
|
||||
val fileName = "$depName.$archiveExtension"
|
||||
val fileName = "$depName.${archiveType.fileExtension}"
|
||||
val archive = cacheDirectory.resolve(fileName)
|
||||
val url = URL("$baseUrl/$fileName")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user