[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:
Sergey Bogolepov
2020-02-18 16:07:00 +07:00
committed by Sergey Bogolepov
parent e147993ff2
commit eb486a6e45
3 changed files with 32 additions and 26 deletions
+4 -6
View File
@@ -5,13 +5,10 @@
import groovy.transform.stc.ClosureParams import groovy.transform.stc.ClosureParams
import groovy.transform.stc.FromString import groovy.transform.stc.FromString
import org.jetbrains.kotlin.konan.target.* import org.jetbrains.kotlin.konan.target.*
import org.jetbrains.kotlin.konan.util.DependencyProcessor
import static org.jetbrains.kotlin.konan.target.KonanTarget.* import static org.jetbrains.kotlin.konan.target.KonanTarget.*
import org.jetbrains.kotlin.konan.util.Named import org.jetbrains.kotlin.konan.util.Named
import org.jetbrains.kotlin.konan.properties.KonanPropertiesLoader import org.jetbrains.kotlin.konan.properties.KonanPropertiesLoader
import org.jetbrains.kotlin.konan.target.ConfigurablesImplKt import org.jetbrains.kotlin.konan.util.ArchiveType
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.target.TargetManager
import org.jetbrains.kotlin.konan.util.DependencyProcessor import org.jetbrains.kotlin.konan.util.DependencyProcessor
import static org.jetbrains.kotlin.konan.util.VisibleNamedKt.getVisibleName import static org.jetbrains.kotlin.konan.util.VisibleNamedKt.getVisibleName
@@ -43,7 +40,7 @@ class NativeDep extends DefaultTask {
@TaskAction @TaskAction
void downloadAndExtract() { void downloadAndExtract() {
def downloader = new DependencyProcessor(baseOutDir, konanPropertiesLoader, baseUrl, false) def downloader = new DependencyProcessor(baseOutDir, konanPropertiesLoader, baseUrl, false, ArchiveType.systemDefault)
downloader.showInfo = false downloader.showInfo = false
downloader.run() downloader.run()
} }
@@ -94,7 +91,8 @@ platformManager.filteredOutEnabledButNotSupported.each { target ->
loader.properties, loader.properties,
loader.dependencies, loader.dependencies,
NativeDep.baseUrl, NativeDep.baseUrl,
false false,
ArchiveType.systemDefault
) )
DependencyKind.values().each { kind -> DependencyKind.values().each { kind ->
@@ -20,16 +20,22 @@ import org.jetbrains.kotlin.konan.file.unzipTo
import java.io.File import java.io.File
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
enum class ArchiveType(val fileExtension: String) {
ZIP("zip"),
TAR_GZ("tar.gz");
class DependencyExtractor { companion object {
internal val useZip = System.getProperty("os.name").startsWith("Windows") val systemDefault = if (System.getProperty("os.name").startsWith("Windows")) {
ZIP
internal val archiveExtension = if (useZip) { } else {
"zip" TAR_GZ
} else { }
"tar.gz"
} }
}
class DependencyExtractor(
private val archiveType: ArchiveType
) {
private fun extractTarGz(tarGz: File, targetDirectory: File) { private fun extractTarGz(tarGz: File, targetDirectory: File) {
val tarProcess = ProcessBuilder().apply { val tarProcess = ProcessBuilder().apply {
command("tar", "-xzf", tarGz.canonicalPath) command("tar", "-xzf", tarGz.canonicalPath)
@@ -53,10 +59,9 @@ class DependencyExtractor {
} }
fun extract(archive: File, targetDirectory: File) { fun extract(archive: File, targetDirectory: File) {
if (useZip) { when (archiveType) {
archive.toPath().unzipTo(targetDirectory.toPath()) ArchiveType.ZIP -> archive.toPath().unzipTo(targetDirectory.toPath())
} else { ArchiveType.TAR_GZ -> extractTarGz(archive, targetDirectory)
extractTarGz(archive, targetDirectory)
} }
} }
@@ -93,7 +93,8 @@ class DependencyProcessor(dependenciesRoot: File,
attemptIntervalMs: Long = DependencyDownloader.DEFAULT_ATTEMPT_INTERVAL_MS, attemptIntervalMs: Long = DependencyDownloader.DEFAULT_ATTEMPT_INTERVAL_MS,
customProgressCallback: ProgressCallback? = null, customProgressCallback: ProgressCallback? = null,
val keepUnstable: Boolean = true, val keepUnstable: Boolean = true,
val deleteArchives: Boolean = true) { val deleteArchives: Boolean = true,
private val archiveType: ArchiveType = ArchiveType.systemDefault) {
val dependenciesDirectory = dependenciesRoot.apply { mkdirs() } val dependenciesDirectory = dependenciesRoot.apply { mkdirs() }
val cacheDirectory = homeDependencyCache.apply { mkdirs() } val cacheDirectory = homeDependencyCache.apply { mkdirs() }
@@ -104,32 +105,34 @@ class DependencyProcessor(dependenciesRoot: File,
private var isInfoShown = false private var isInfoShown = false
private val downloader = DependencyDownloader(maxAttempts, attemptIntervalMs, customProgressCallback) private val downloader = DependencyDownloader(maxAttempts, attemptIntervalMs, customProgressCallback)
private val extractor = DependencyExtractor() private val extractor = DependencyExtractor(archiveType)
private val archiveExtension get() = extractor.archiveExtension
constructor(dependenciesRoot: File, constructor(dependenciesRoot: File,
properties: KonanPropertiesLoader, properties: KonanPropertiesLoader,
dependenciesUrl: String = properties.dependenciesUrl, dependenciesUrl: String = properties.dependenciesUrl,
keepUnstable:Boolean = true) : this( keepUnstable:Boolean = true,
archiveType: ArchiveType = ArchiveType.systemDefault) : this(
dependenciesRoot, dependenciesRoot,
properties.properties, properties.properties,
properties.dependencies, properties.dependencies,
dependenciesUrl, dependenciesUrl,
keepUnstable = keepUnstable) keepUnstable = keepUnstable,
archiveType = archiveType)
constructor(dependenciesRoot: File, constructor(dependenciesRoot: File,
properties: Properties, properties: Properties,
dependencies: List<String>, dependencies: List<String>,
dependenciesUrl: String = properties.dependenciesUrl, dependenciesUrl: String = properties.dependenciesUrl,
keepUnstable:Boolean = true) : this( keepUnstable:Boolean = true,
archiveType: ArchiveType = ArchiveType.systemDefault) : this(
dependenciesRoot, dependenciesRoot,
dependenciesUrl, dependenciesUrl,
dependencyToCandidates = properties.findCandidates(dependencies), dependencyToCandidates = properties.findCandidates(dependencies),
airplaneMode = properties.airplaneMode, airplaneMode = properties.airplaneMode,
maxAttempts = properties.downloadingAttempts, maxAttempts = properties.downloadingAttempts,
attemptIntervalMs = properties.downloadingAttemptIntervalMs, attemptIntervalMs = properties.downloadingAttemptIntervalMs,
keepUnstable = keepUnstable) keepUnstable = keepUnstable,
archiveType = archiveType)
class DependencyFile(directory: File, fileName: String) { class DependencyFile(directory: File, fileName: String) {
@@ -165,7 +168,7 @@ class DependencyProcessor(dependenciesRoot: File,
val depDir = File(dependenciesDirectory, dependency) val depDir = File(dependenciesDirectory, dependency)
val depName = depDir.name val depName = depDir.name
val fileName = "$depName.$archiveExtension" val fileName = "$depName.${archiveType.fileExtension}"
val archive = cacheDirectory.resolve(fileName) val archive = cacheDirectory.resolve(fileName)
val url = URL("$baseUrl/$fileName") val url = URL("$baseUrl/$fileName")