dependencies: Set downloading retry parameters in konan.properties
This commit is contained in:
@@ -20,6 +20,10 @@ dependenciesUrl = http://download.jetbrains.com/kotlin/native
|
|||||||
# Don't check dependencies on a server.
|
# Don't check dependencies on a server.
|
||||||
# If true, dependency downloader will throw an exception if a dependency isn't found in konan.home.
|
# If true, dependency downloader will throw an exception if a dependency isn't found in konan.home.
|
||||||
airplaneMode = false
|
airplaneMode = false
|
||||||
|
|
||||||
|
downloadingAttempts = 10
|
||||||
|
downloadingAttemptPauseMs = 3000
|
||||||
|
|
||||||
llvmDebugOptFlags = -O0
|
llvmDebugOptFlags = -O0
|
||||||
|
|
||||||
# Mac OS X.
|
# Mac OS X.
|
||||||
|
|||||||
Vendored
+6
-1
@@ -165,6 +165,11 @@ class TgzNativeDep extends NativeDep {
|
|||||||
|
|
||||||
class HelperNativeDep extends TgzNativeDep {
|
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() {
|
public HelperNativeDep() {
|
||||||
dependsOn(':tools:helpers:jar')
|
dependsOn(':tools:helpers:jar')
|
||||||
}
|
}
|
||||||
@@ -175,7 +180,7 @@ class HelperNativeDep extends TgzNativeDep {
|
|||||||
main = "org.jetbrains.kotlin.konan.MainKt"
|
main = "org.jetbrains.kotlin.konan.MainKt"
|
||||||
classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime")
|
classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime")
|
||||||
classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime").artifacts.files
|
classpath += project.findProject(':tools:helpers').getConfigurations().getByName("runtime").artifacts.files
|
||||||
args baseOutDir.canonicalPath, baseUrl, baseName
|
args baseOutDir.canonicalPath, baseUrl, maxAttempts, attemptPauseMs, baseName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ import kotlin.concurrent.withLock
|
|||||||
class DependencyDownloader(dependenciesRoot: File,
|
class DependencyDownloader(dependenciesRoot: File,
|
||||||
val dependenciesUrl: String,
|
val dependenciesUrl: String,
|
||||||
val dependencies: List<String>,
|
val dependencies: List<String>,
|
||||||
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 dependenciesDirectory = dependenciesRoot.apply { mkdirs() }
|
||||||
val cacheDirectory = System.getProperty("user.home")?.let {
|
val cacheDirectory = System.getProperty("user.home")?.let {
|
||||||
@@ -94,21 +96,20 @@ class DependencyDownloader(dependenciesRoot: File,
|
|||||||
if (!archive.exists()) {
|
if (!archive.exists()) {
|
||||||
if (!airplaneMode) {
|
if (!airplaneMode) {
|
||||||
var attempt = 0
|
var attempt = 0
|
||||||
var done = false
|
while(true) {
|
||||||
do {
|
|
||||||
try {
|
try {
|
||||||
download(depName, archive)
|
download(depName, archive)
|
||||||
done = true
|
break
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
if (attempt < MAX_ATTEMPTS) {
|
if (attempt < maxAttempts) {
|
||||||
attempt++
|
attempt++
|
||||||
val pauseTime = attempt * ATTEMPT_PAUSE_MS
|
val pauseTime = attempt * attemptPauseMs
|
||||||
println("Downloading error: ${e.message}.\n" +
|
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)
|
Thread.sleep(pauseTime)
|
||||||
} else { throw e }
|
} else { throw e }
|
||||||
}
|
}
|
||||||
} while (!done)
|
}
|
||||||
} else {
|
} else {
|
||||||
throw RuntimeException("""
|
throw RuntimeException("""
|
||||||
Cannot find a dependency locally: $dependency.
|
Cannot find a dependency locally: $dependency.
|
||||||
@@ -228,8 +229,8 @@ class DependencyDownloader(dependenciesRoot: File,
|
|||||||
companion object {
|
companion object {
|
||||||
val lock = ReentrantLock()
|
val lock = ReentrantLock()
|
||||||
|
|
||||||
const val MAX_ATTEMPTS = 10
|
const val DEFAULT_MAX_ATTEMPTS = 10
|
||||||
const val ATTEMPT_PAUSE_MS = 3000L
|
const val DEFAULT_ATTEMPT_PAUSE_MS = 3000L
|
||||||
}
|
}
|
||||||
|
|
||||||
fun run() = lock.withLock {
|
fun run() = lock.withLock {
|
||||||
|
|||||||
@@ -28,7 +28,11 @@ class Helper0(val dependenciesDir: String,
|
|||||||
File(dependenciesDir),
|
File(dependenciesDir),
|
||||||
properties.getProperty("dependenciesUrl", "https://download.jetbrains.com/kotlin/native"),
|
properties.getProperty("dependenciesUrl", "https://download.jetbrains.com/kotlin/native"),
|
||||||
dependencies,
|
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()
|
).run()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,13 +20,20 @@ import java.io.File
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
// TODO: Add command line keys
|
// 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<String>) {
|
fun main(args: Array<String>) {
|
||||||
if (args.size < 2) {
|
if (args.size < 5) {
|
||||||
System.exit(1)
|
System.exit(1)
|
||||||
}
|
}
|
||||||
val dependenciesDir = File(args[0])
|
val dependenciesDir = File(args[0])
|
||||||
val dependenciesUrl = args[1]
|
val dependenciesUrl = args[1]
|
||||||
val dependencies = List<String>(args.size - 2) { args[2 + it] }
|
val maxAttempts = args[2].toInt()
|
||||||
DependencyDownloader(dependenciesDir, dependenciesUrl, dependencies).run()
|
val attemptPause = args[3].toLong()
|
||||||
|
val dependencies = List<String>(args.size - 4) { args[4 + it] }
|
||||||
|
DependencyDownloader(dependenciesDir,
|
||||||
|
dependenciesUrl,
|
||||||
|
dependencies,
|
||||||
|
maxAttempts = maxAttempts,
|
||||||
|
attemptPauseMs = attemptPause
|
||||||
|
).run()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user