From 6f35106337318b50dd698818a266dab36918e6cf Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Tue, 27 Jun 2017 12:16:55 +0700 Subject: [PATCH] dependencies: Add "airplane mode" The patch adds airplaneMode parameter in konan.properties. If airplaneMode = true the dependency downloader will throw an exception instead of downloading a missing dependency. --- backend.native/konan.properties | 4 ++++ .../src/main/kotlin/DependencyDownloader.kt | 18 ++++++++++++++++-- tools/helpers/src/main/kotlin/Helper0.kt | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/backend.native/konan.properties b/backend.native/konan.properties index 9623754c768..f8ee6d3163e 100644 --- a/backend.native/konan.properties +++ b/backend.native/konan.properties @@ -17,6 +17,10 @@ # TODO: Do we need a $variable substitution mechanism here? 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 + # Mac OS X. llvmVersion.osx = 3.9.0 llvmHome.osx = clang-llvm-3.9.0-darwin-macos diff --git a/tools/helpers/src/main/kotlin/DependencyDownloader.kt b/tools/helpers/src/main/kotlin/DependencyDownloader.kt index 1f07b8ff618..e280ad2cedd 100644 --- a/tools/helpers/src/main/kotlin/DependencyDownloader.kt +++ b/tools/helpers/src/main/kotlin/DependencyDownloader.kt @@ -25,7 +25,14 @@ import kotlin.concurrent.thread import kotlin.concurrent.withLock // TODO: Try to use some dependency management system (Ivy?) -class DependencyDownloader(dependenciesRoot: File, val dependenciesUrl: String, val dependencies: List) { +/** + * Inspects [dependencies] and downloads all the missing ones into [dependenciesDirectory] from [dependenciesUrl]. + * If [airplaneMode] is true will throw a RuntimeException instead of downloading. + */ +class DependencyDownloader(dependenciesRoot: File, + val dependenciesUrl: String, + val dependencies: List, + val airplaneMode: Boolean = false) { val dependenciesDirectory = dependenciesRoot.apply { mkdirs() } val cacheDirectory = System.getProperty("user.home")?.let { @@ -85,7 +92,14 @@ class DependencyDownloader(dependenciesRoot: File, val dependenciesUrl: String, val archive = File(cacheDirectory.canonicalPath, "$depName.$archiveExtension") if (!archive.exists()) { - download(depName, archive) + if (!airplaneMode) { + download(depName, archive) + } else { + throw RuntimeException(""" + Cannot find a dependency locally: $dependency. + Set `airplaneMode = false` in konan.properties to download it. + """.trimIndent()) + } } extract(archive, dependenciesDirectory) extractedDependencies.addWithSave(depName) diff --git a/tools/helpers/src/main/kotlin/Helper0.kt b/tools/helpers/src/main/kotlin/Helper0.kt index 668f999db1b..b601df8643c 100644 --- a/tools/helpers/src/main/kotlin/Helper0.kt +++ b/tools/helpers/src/main/kotlin/Helper0.kt @@ -27,7 +27,8 @@ class Helper0(val dependenciesDir: String, DependencyDownloader( File(dependenciesDir), properties.getProperty("dependenciesUrl", "https://download.jetbrains.com/kotlin/native"), - dependencies + dependencies, + airplaneMode = properties.getProperty("airplaneMode")?.toBoolean() ?: false ).run() } } \ No newline at end of file