From 266047118e3473b73c32fd5a0fa897f3fc4d69e0 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Tue, 15 Aug 2017 18:19:47 +0700 Subject: [PATCH] dependencies: Set downloading retry parameters in konan.properties --- backend.native/konan.properties | 4 ++++ dependencies/build.gradle | 7 ++++++- .../src/main/kotlin/DependencyDownloader.kt | 21 ++++++++++--------- tools/helpers/src/main/kotlin/Helper0.kt | 6 +++++- tools/helpers/src/main/kotlin/main.kt | 15 +++++++++---- 5 files changed, 37 insertions(+), 16 deletions(-) diff --git a/backend.native/konan.properties b/backend.native/konan.properties index f85ad5fcaa2..14c32b1f338 100644 --- a/backend.native/konan.properties +++ b/backend.native/konan.properties @@ -20,6 +20,10 @@ dependenciesUrl = http://download.jetbrains.com/kotlin/native # Don't check dependencies on a server. # If true, dependency downloader will throw an exception if a dependency isn't found in konan.home. airplaneMode = false + +downloadingAttempts = 10 +downloadingAttemptPauseMs = 3000 + llvmDebugOptFlags = -O0 # Mac OS X. diff --git a/dependencies/build.gradle b/dependencies/build.gradle index c9be5d9815c..69d6e8a5cb7 100644 --- a/dependencies/build.gradle +++ b/dependencies/build.gradle @@ -165,6 +165,11 @@ class TgzNativeDep extends NativeDep { class HelperNativeDep extends TgzNativeDep { + int maxAttempts = Integer.parseInt( + project.rootProject.ext.konanProperties['downloadingAttempts'].toString()) + long attemptPauseMs = Long.parseLong( + project.rootProject.ext.konanProperties['downloadingAttemptPauseMs'].toString()) + public HelperNativeDep() { dependsOn(':tools:helpers:jar') } @@ -175,7 +180,7 @@ class HelperNativeDep extends TgzNativeDep { main = "org.jetbrains.kotlin.konan.MainKt" classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime") classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime").artifacts.files - args baseOutDir.canonicalPath, baseUrl, baseName + args baseOutDir.canonicalPath, baseUrl, maxAttempts, attemptPauseMs, baseName } } } diff --git a/tools/helpers/src/main/kotlin/DependencyDownloader.kt b/tools/helpers/src/main/kotlin/DependencyDownloader.kt index 89493a42ffc..b367d93fdba 100644 --- a/tools/helpers/src/main/kotlin/DependencyDownloader.kt +++ b/tools/helpers/src/main/kotlin/DependencyDownloader.kt @@ -32,7 +32,9 @@ import kotlin.concurrent.withLock class DependencyDownloader(dependenciesRoot: File, val dependenciesUrl: String, val dependencies: List, - val airplaneMode: Boolean = false) { + val airplaneMode: Boolean = false, + val maxAttempts: Int = DEFAULT_MAX_ATTEMPTS, + val attemptPauseMs: Long = DEFAULT_ATTEMPT_PAUSE_MS) { val dependenciesDirectory = dependenciesRoot.apply { mkdirs() } val cacheDirectory = System.getProperty("user.home")?.let { @@ -94,21 +96,20 @@ class DependencyDownloader(dependenciesRoot: File, if (!archive.exists()) { if (!airplaneMode) { var attempt = 0 - var done = false - do { + while(true) { try { download(depName, archive) - done = true + break } catch (e: IOException) { - if (attempt < MAX_ATTEMPTS) { + if (attempt < maxAttempts) { attempt++ - val pauseTime = attempt * ATTEMPT_PAUSE_MS + val pauseTime = attempt * attemptPauseMs println("Downloading error: ${e.message}.\n" + - "Waiting ${pauseTime.toDouble() / 1000} sec and trying again (attempt: $attempt/$MAX_ATTEMPTS)") + "Waiting ${pauseTime.toDouble() / 1000} sec and trying again (attempt: $attempt/$maxAttempts)") Thread.sleep(pauseTime) } else { throw e } } - } while (!done) + } } else { throw RuntimeException(""" Cannot find a dependency locally: $dependency. @@ -228,8 +229,8 @@ class DependencyDownloader(dependenciesRoot: File, companion object { val lock = ReentrantLock() - const val MAX_ATTEMPTS = 10 - const val ATTEMPT_PAUSE_MS = 3000L + const val DEFAULT_MAX_ATTEMPTS = 10 + const val DEFAULT_ATTEMPT_PAUSE_MS = 3000L } fun run() = lock.withLock { diff --git a/tools/helpers/src/main/kotlin/Helper0.kt b/tools/helpers/src/main/kotlin/Helper0.kt index b601df8643c..f2b859d8351 100644 --- a/tools/helpers/src/main/kotlin/Helper0.kt +++ b/tools/helpers/src/main/kotlin/Helper0.kt @@ -28,7 +28,11 @@ class Helper0(val dependenciesDir: String, File(dependenciesDir), properties.getProperty("dependenciesUrl", "https://download.jetbrains.com/kotlin/native"), dependencies, - airplaneMode = properties.getProperty("airplaneMode")?.toBoolean() ?: false + airplaneMode = properties.getProperty("airplaneMode")?.toBoolean() ?: false, + maxAttempts = properties.getProperty("downloadingAttempts")?.toInt() + ?: DependencyDownloader.DEFAULT_MAX_ATTEMPTS, + attemptPauseMs = properties.getProperty("downloadingAttemptPauseMs")?.toLong() + ?: DependencyDownloader.DEFAULT_ATTEMPT_PAUSE_MS ).run() } } \ No newline at end of file diff --git a/tools/helpers/src/main/kotlin/main.kt b/tools/helpers/src/main/kotlin/main.kt index d5b3d50ffd3..bfeb28a3875 100644 --- a/tools/helpers/src/main/kotlin/main.kt +++ b/tools/helpers/src/main/kotlin/main.kt @@ -20,13 +20,20 @@ import java.io.File import java.util.* // TODO: Add command line keys -// Args: dependencies directory, dependencies url, dependencies list +// Args: dependencies directory, dependencies url, max attempts, attempt pause, dependencies list fun main(args: Array) { - if (args.size < 2) { + if (args.size < 5) { System.exit(1) } val dependenciesDir = File(args[0]) val dependenciesUrl = args[1] - val dependencies = List(args.size - 2) { args[2 + it] } - DependencyDownloader(dependenciesDir, dependenciesUrl, dependencies).run() + val maxAttempts = args[2].toInt() + val attemptPause = args[3].toLong() + val dependencies = List(args.size - 4) { args[4 + it] } + DependencyDownloader(dependenciesDir, + dependenciesUrl, + dependencies, + maxAttempts = maxAttempts, + attemptPauseMs = attemptPause + ).run() }