[Commonizer] Prevent from running commonizer from Gradle more then once

This commit is contained in:
Dmitriy Dolovov
2020-02-10 12:54:28 +07:00
parent 7cf4395ccd
commit 63b03d29dc
3 changed files with 42 additions and 21 deletions
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
import org.jetbrains.kotlin.gradle.targets.native.DisabledNativeTargetsReporter
import org.jetbrains.kotlin.gradle.targets.native.internal.setUpKotlinNativePlatformDependencies
import org.jetbrains.kotlin.gradle.utils.NativeCompilerDownloader
import org.jetbrains.kotlin.gradle.utils.SingleActionPerProject
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
@@ -69,7 +70,9 @@ abstract class AbstractKotlinNativeTargetPreset<T : KotlinNativeTarget>(
createTargetConfigurator().configureTarget(result)
project.gradle.taskGraph.whenReady {
project.rootProject.setUpKotlinNativePlatformDependencies()
SingleActionPerProject.run(project, "setUpKotlinNativePlatformDependencies") {
project.setUpKotlinNativePlatformDependencies()
}
}
if (!konanTarget.enabledOnCurrentHost) {
@@ -1,20 +0,0 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.utils
import org.gradle.api.Project
import java.util.*
internal object SingleWarningPerBuild {
private val rootModuleReceivedWarning = WeakHashMap<Project, MutableSet<String>>()
fun show(project: Project, warningText: String) {
val receivedWarnings = rootModuleReceivedWarning.computeIfAbsent(project.rootProject) { mutableSetOf() }
if (receivedWarnings.add(warningText)) {
project.logger.warn(warningText)
}
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.gradle.utils
import org.gradle.api.Project
import java.util.WeakHashMap
internal abstract class SingleAction {
private val performedActions = WeakHashMap<Project, MutableSet<String>>()
protected abstract fun selectKey(project: Project): Project
fun run(project: Project, actionId: String, action: () -> Unit) {
val performedActions = performedActions.computeIfAbsent(selectKey(project)) { mutableSetOf() }
if (performedActions.add(actionId)) {
action()
}
}
}
internal object SingleActionPerBuild : SingleAction() {
override fun selectKey(project: Project): Project = project.rootProject
}
internal object SingleActionPerProject : SingleAction() {
override fun selectKey(project: Project) = project
}
internal object SingleWarningPerBuild {
private const val ACTION_ID_SHOW_WARNING = "show-warning:"
fun show(project: Project, warningText: String) = SingleActionPerBuild.run(project, ACTION_ID_SHOW_WARNING + warningText) {
project.logger.warn(warningText)
}
}