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.
This commit is contained in:
Ilya Matveev
2017-06-27 12:16:55 +07:00
committed by ilmat192
parent 974426d70d
commit 6f35106337
3 changed files with 22 additions and 3 deletions
+4
View File
@@ -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
@@ -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<String>) {
/**
* 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<String>,
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)
+2 -1
View File
@@ -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()
}
}