mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-14 04:10:50 +08:00
[build] Use project lazy instead of global lazy
This commit is contained in:
parent
460275fc0f
commit
0a60c5147e
@ -45,6 +45,7 @@ plugins {
|
|||||||
|
|
||||||
osDetector = osdetector
|
osDetector = osdetector
|
||||||
BuildSrcRootProjectHolder.value = rootProject
|
BuildSrcRootProjectHolder.value = rootProject
|
||||||
|
BuildSrcRootProjectHolder.lastUpdateTime = System.currentTimeMillis()
|
||||||
|
|
||||||
analyzes.CompiledCodeVerify.run { registerAllVerifyTasks() }
|
analyzes.CompiledCodeVerify.run { registerAllVerifyTasks() }
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ enum class HostArch {
|
|||||||
|
|
||||||
/// eg. "!a;!b" means to enable all targets but a or b
|
/// eg. "!a;!b" means to enable all targets but a or b
|
||||||
/// eg. "a;b;!other" means to disable all targets but a or b
|
/// eg. "a;b;!other" means to disable all targets but a or b
|
||||||
val ENABLED_TARGETS by lazy {
|
val ENABLED_TARGETS by projectLazy {
|
||||||
|
|
||||||
val targets = getMiraiTargetFromGradle() // enable all by default
|
val targets = getMiraiTargetFromGradle() // enable all by default
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ fun isTargetEnabled(name: String): Boolean {
|
|||||||
fun Set<String>.filterTargets() =
|
fun Set<String>.filterTargets() =
|
||||||
this.filter { isTargetEnabled(it) }.toSet()
|
this.filter { isTargetEnabled(it) }.toSet()
|
||||||
|
|
||||||
val MAC_TARGETS: Set<String> by lazy {
|
val MAC_TARGETS: Set<String> by projectLazy {
|
||||||
setOf(
|
setOf(
|
||||||
// "watchosX86",
|
// "watchosX86",
|
||||||
"macosX64",
|
"macosX64",
|
||||||
@ -142,13 +142,13 @@ val MAC_TARGETS: Set<String> by lazy {
|
|||||||
).filterTargets()
|
).filterTargets()
|
||||||
}
|
}
|
||||||
|
|
||||||
val WIN_TARGETS by lazy { setOf("mingwX64").filterTargets() }
|
val WIN_TARGETS by projectLazy { setOf("mingwX64").filterTargets() }
|
||||||
|
|
||||||
val LINUX_TARGETS by lazy { setOf("linuxX64").filterTargets() }
|
val LINUX_TARGETS by projectLazy { setOf("linuxX64").filterTargets() }
|
||||||
|
|
||||||
val UNIX_LIKE_TARGETS by lazy { LINUX_TARGETS + MAC_TARGETS }
|
val UNIX_LIKE_TARGETS by projectLazy { LINUX_TARGETS + MAC_TARGETS }
|
||||||
|
|
||||||
val NATIVE_TARGETS by lazy { UNIX_LIKE_TARGETS + WIN_TARGETS }
|
val NATIVE_TARGETS by projectLazy { UNIX_LIKE_TARGETS + WIN_TARGETS }
|
||||||
|
|
||||||
private val POSSIBLE_NATIVE_TARGETS by lazy { setOf("mingwX64", "macosX64", "macosArm64", "linuxX64") }
|
private val POSSIBLE_NATIVE_TARGETS by lazy { setOf("mingwX64", "macosX64", "macosArm64", "linuxX64") }
|
||||||
|
|
||||||
|
@ -21,10 +21,41 @@ import java.util.*
|
|||||||
|
|
||||||
object BuildSrcRootProjectHolder {
|
object BuildSrcRootProjectHolder {
|
||||||
lateinit var value: Project
|
lateinit var value: Project
|
||||||
|
var lastUpdateTime: Long = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
val rootProject: Project get() = BuildSrcRootProjectHolder.value
|
val rootProject: Project get() = BuildSrcRootProjectHolder.value
|
||||||
|
|
||||||
|
fun <T> projectLazy(action: () -> T): Lazy<T> {
|
||||||
|
val projLazy = object : Lazy<T> {
|
||||||
|
private lateinit var delegate: Lazy<T>
|
||||||
|
private var holdTime: Long = -1
|
||||||
|
|
||||||
|
override val value: T
|
||||||
|
get() {
|
||||||
|
if (holdTime != BuildSrcRootProjectHolder.lastUpdateTime) {
|
||||||
|
synchronized(this) {
|
||||||
|
if (holdTime != BuildSrcRootProjectHolder.lastUpdateTime) {
|
||||||
|
delegate = lazy(action)
|
||||||
|
holdTime = BuildSrcRootProjectHolder.lastUpdateTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return delegate.value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isInitialized(): Boolean {
|
||||||
|
if (!::delegate.isInitialized) return false
|
||||||
|
|
||||||
|
if (holdTime == BuildSrcRootProjectHolder.lastUpdateTime) {
|
||||||
|
return delegate.isInitialized()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return projLazy
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private lateinit var localProperties: Properties
|
private lateinit var localProperties: Properties
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user