Introduce environment variable to .konan parent dir

This commit is contained in:
Sergey Mashkov
2018-03-23 19:04:32 +03:00
committed by ilmat192
parent 1b42eb1d13
commit 420ef4f221
7 changed files with 23 additions and 22 deletions
@@ -37,7 +37,7 @@ fun defaultResolver(repositories: List<String>, target: KonanTarget, distributio
repositories,
target,
distribution.klib,
distribution.localKonanDir
distribution.localKonanDir.absolutePath
)
fun SearchPathResolver.resolveImmediateLibraries(libraryNames: List<String>,
+3 -1
View File
@@ -171,5 +171,7 @@ task update(type: Copy) {
}
task rmDotKonan(type: Delete) {
delete "${System.getProperty("user.home")}/.konan"
def dir = System.getenv("KONAN_DATA_DIR") ?: "${System.getProperty("user.home")}/.konan"
delete dir
}
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.konan.file.File
import org.jetbrains.kotlin.konan.target.Distribution
import org.jetbrains.kotlin.konan.target.PlatformManager
import org.jetbrains.kotlin.konan.util.DependencyProcessor
import org.jetbrains.kotlin.metadata.KonanLinkData
import java.lang.System.out
import kotlin.system.exitProcess
@@ -84,8 +85,7 @@ fun error(text: String) {
exitProcess(1)
}
// TODO: Get rid of the hardcoded path.
val defaultRepository = File(File.userHome, ".konan/klib")
val defaultRepository = File(DependencyProcessor.localKonanDir.resolve("klib").absolutePath)
open class ModuleDeserializer(val library: ByteArray) {
protected val moduleHeader: KonanLinkData.LinkDataLibrary
@@ -26,7 +26,7 @@ class Distribution(
private val konanHomeOverride: String? = null,
private val runtimeFileOverride: String? = null) {
val localKonanDir = "${File.userHome}/.konan"
val localKonanDir = DependencyProcessor.localKonanDir
private fun findKonanHome(): String {
if (konanHomeOverride != null) return konanHomeOverride
@@ -52,7 +52,7 @@ class Distribution(
propertyFilesFromConfigDir(konanSubdir, genericName)
private fun userPropertyFiles(genericName: String) =
propertyFilesFromConfigDir(localKonanDir, genericName)
propertyFilesFromConfigDir(localKonanDir.absolutePath, genericName)
fun additionalPropertyFiles(genericName: String) =
preconfiguredPropertyFiles(genericName) + userPropertyFiles(genericName)
@@ -45,9 +45,6 @@ private val Properties.downloadingAttemptIntervalMs : Long
get() = getProperty("downloadingAttemptPauseMs")?.toLong()
?: DependencyDownloader.DEFAULT_ATTEMPT_INTERVAL_MS
private val Properties.homeDependencyCache : String
get() = getProperty("homeDependencyCache") ?: DependencyProcessor.DEFAULT_HOME_DEPENDENCY_CACHE
private fun Properties.findCandidates(dependencies: List<String>): Map<String, List<DependencySource>> {
val dependencyProfiles = this.propertyList("dependencyProfiles")
return dependencies.map { dependency ->
@@ -73,7 +70,6 @@ private val KonanPropertiesLoader.dependenciesUrl : String get() = pr
private val KonanPropertiesLoader.airplaneMode : Boolean get() = properties.airplaneMode
private val KonanPropertiesLoader.downloadingAttempts : Int get() = properties.downloadingAttempts
private val KonanPropertiesLoader.downloadingAttemptIntervalMs : Long get() = properties.downloadingAttemptIntervalMs
private val KonanPropertiesLoader.homeDependencyCache : String get() = properties.homeDependencyCache
sealed class DependencySource {
data class Local(val path: File) : DependencySource()
@@ -91,7 +87,7 @@ sealed class DependencySource {
class DependencyProcessor(dependenciesRoot: File,
val dependenciesUrl: String,
dependencyToCandidates: Map<String, List<DependencySource>>,
homeDependencyCache: String = DEFAULT_HOME_DEPENDENCY_CACHE,
homeDependencyCache: File = defaultDependencyCacheDir,
val airplaneMode: Boolean = false,
maxAttempts: Int = DependencyDownloader.DEFAULT_MAX_ATTEMPTS,
attemptIntervalMs: Long = DependencyDownloader.DEFAULT_ATTEMPT_INTERVAL_MS,
@@ -99,9 +95,7 @@ class DependencyProcessor(dependenciesRoot: File,
val keepUnstable: Boolean = true) {
val dependenciesDirectory = dependenciesRoot.apply { mkdirs() }
val cacheDirectory = System.getProperty("user.home")?.let {
Paths.get(it).resolve(homeDependencyCache).toFile().apply { mkdirs() }
} ?: dependenciesRoot
val cacheDirectory = homeDependencyCache.apply { mkdirs() }
val lockFile = File(cacheDirectory, ".lock").apply { if (!exists()) createNewFile() }
@@ -212,11 +206,16 @@ class DependencyProcessor(dependenciesRoot: File,
companion object {
private val lock = ReentrantLock()
const val DEFAULT_HOME_DEPENDENCY_CACHE = ".konan/cache"
val localKonanDir: File by lazy {
File(System.getenv("KONAN_DATA_DIR") ?: (System.getProperty("user.home") + File.separator + ".konan"))
}
@JvmStatic
val defaultDependenciesRoot
get() = Paths.get(System.getProperty("user.home")).resolve(".konan/dependencies").toFile()
val defaultDependenciesRoot: File
get() = localKonanDir.resolve("dependencies")
val defaultDependencyCacheDir: File
get() = localKonanDir.resolve("cache")
}
private val resolvedDependencies = dependencyToCandidates.map { (dependency, candidates) ->
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.gradle.plugin.tasks.*
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
import org.jetbrains.kotlin.konan.target.customerDistribution
import org.jetbrains.kotlin.konan.util.*
import java.io.File
import java.util.*
import javax.inject.Inject
@@ -129,7 +130,7 @@ internal fun Project.konanCompilerName(): String =
"kotlin-native-${project.simpleOsName}-${this.konanVersion}"
internal fun Project.konanCompilerDownloadDir(): String =
KonanCompilerDownloadTask.KONAN_PARENT_DIR + "/" + project.konanCompilerName()
DependencyProcessor.localKonanDir.resolve(project.konanCompilerName()).absolutePath
// region Useful extensions and functions ---------------------------------------
@@ -31,8 +31,6 @@ open class KonanCompilerDownloadTask : DefaultTask() {
internal companion object {
internal const val BASE_DOWNLOAD_URL = "https://download.jetbrains.com/kotlin/native/builds"
internal val KONAN_PARENT_DIR = "${System.getProperty("user.home")}/.konan"
}
/**
@@ -61,9 +59,10 @@ open class KonanCompilerDownloadTask : DefaultTask() {
append(project.simpleOsName)
}
val konanCompiler = project.konanCompilerName()
logger.info("Downloading Kotlin/Native compiler from $downloadUrlDirectory/$konanCompiler into $KONAN_PARENT_DIR")
val parentDir = DependencyProcessor.localKonanDir
logger.info("Downloading Kotlin/Native compiler from $downloadUrlDirectory/$konanCompiler into $parentDir")
DependencyProcessor(
File(KONAN_PARENT_DIR),
parentDir,
downloadUrlDirectory,
mapOf(konanCompiler to listOf(DependencySource.Remote.Public))
).run()