Move transitiveClosure into :commonizer-api
This commit is contained in:
+3
-2
@@ -11,6 +11,7 @@ import org.gradle.api.Project
|
|||||||
import org.gradle.api.file.SourceDirectorySet
|
import org.gradle.api.file.SourceDirectorySet
|
||||||
import org.gradle.util.ConfigureUtil
|
import org.gradle.util.ConfigureUtil
|
||||||
import org.jetbrains.kotlin.build.DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS
|
import org.jetbrains.kotlin.build.DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS
|
||||||
|
import org.jetbrains.kotlin.commonizer.util.transitiveClosure
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
|
import org.jetbrains.kotlin.gradle.plugin.KotlinDependencyHandler
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
@@ -246,7 +247,7 @@ internal operator fun KotlinSourceSet.plus(sourceSets: Set<KotlinSourceSet>): Se
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun KotlinSourceSet.resolveAllDependsOnSourceSets(): Set<KotlinSourceSet> {
|
internal fun KotlinSourceSet.resolveAllDependsOnSourceSets(): Set<KotlinSourceSet> {
|
||||||
return transitiveClosure { dependsOn }
|
return transitiveClosure(this) { dependsOn }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Iterable<KotlinSourceSet>.resolveAllDependsOnSourceSets(): Set<KotlinSourceSet> {
|
internal fun Iterable<KotlinSourceSet>.resolveAllDependsOnSourceSets(): Set<KotlinSourceSet> {
|
||||||
@@ -254,5 +255,5 @@ internal fun Iterable<KotlinSourceSet>.resolveAllDependsOnSourceSets(): Set<Kotl
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun KotlinMultiplatformExtension.resolveAllSourceSetsDependingOn(sourceSet: KotlinSourceSet): Set<KotlinSourceSet> {
|
internal fun KotlinMultiplatformExtension.resolveAllSourceSetsDependingOn(sourceSet: KotlinSourceSet): Set<KotlinSourceSet> {
|
||||||
return sourceSet.transitiveClosure { sourceSets.filter { otherSourceSet -> this in otherSourceSet.dependsOn } }
|
return transitiveClosure(sourceSet) { sourceSets.filter { otherSourceSet -> this in otherSourceSet.dependsOn } }
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.kotlinSourceSetsIncludingDefault
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.sources.resolveAllDependsOnSourceSets
|
import org.jetbrains.kotlin.gradle.plugin.sources.resolveAllDependsOnSourceSets
|
||||||
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropCommonizerTask.CInteropGist
|
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropCommonizerTask.CInteropGist
|
||||||
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
|
import org.jetbrains.kotlin.gradle.tasks.CInteropProcess
|
||||||
import org.jetbrains.kotlin.gradle.utils.transitiveClosure
|
import org.jetbrains.kotlin.commonizer.util.transitiveClosure
|
||||||
import org.jetbrains.kotlin.gradle.utils.fileProvider
|
import org.jetbrains.kotlin.gradle.utils.fileProvider
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@@ -211,7 +211,7 @@ private operator fun CommonizerTarget.contains(other: CommonizerTarget): Boolean
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun SharedCommonizerTarget.withAllTransitiveTargets(): Set<CommonizerTarget> {
|
private fun SharedCommonizerTarget.withAllTransitiveTargets(): Set<CommonizerTarget> {
|
||||||
return setOf(this) + this.transitiveClosure<CommonizerTarget> { if (this is SharedCommonizerTarget) this.targets else emptySet() }
|
return setOf(this) + transitiveClosure<CommonizerTarget>(this) { if (this is SharedCommonizerTarget) this.targets else emptySet() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Project.getDependingNativeCompilations(compilation: KotlinSharedNativeCompilation): Set<KotlinNativeCompilation> {
|
private fun Project.getDependingNativeCompilations(compilation: KotlinSharedNativeCompilation): Set<KotlinNativeCompilation> {
|
||||||
|
|||||||
+6
-5
@@ -3,7 +3,7 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* 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
|
package org.jetbrains.kotlin.commonizer.util
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General purpose implementation of a transitive closure
|
* General purpose implementation of a transitive closure
|
||||||
@@ -13,9 +13,9 @@ package org.jetbrains.kotlin.gradle.utils
|
|||||||
* @param edges: Producer function from one node to all its children. This implementation can handle loops and self references gracefully.
|
* @param edges: Producer function from one node to all its children. This implementation can handle loops and self references gracefully.
|
||||||
* @return Note: No guarantees given about the order ot this [Set]
|
* @return Note: No guarantees given about the order ot this [Set]
|
||||||
*/
|
*/
|
||||||
internal inline fun <reified T> T.transitiveClosure(edges: T.() -> Iterable<T>): Set<T> {
|
public inline fun <reified T> transitiveClosure(seed: T, edges: T.() -> Iterable<T>): Set<T> {
|
||||||
// Fast path when initial edges are empty
|
// Fast path when initial edges are empty
|
||||||
val initialEdges = edges()
|
val initialEdges = seed.edges()
|
||||||
if (initialEdges is Collection && initialEdges.isEmpty()) return emptySet()
|
if (initialEdges is Collection && initialEdges.isEmpty()) return emptySet()
|
||||||
|
|
||||||
val queue = deque<T>()
|
val queue = deque<T>()
|
||||||
@@ -24,7 +24,7 @@ internal inline fun <reified T> T.transitiveClosure(edges: T.() -> Iterable<T>):
|
|||||||
while (queue.isNotEmpty()) {
|
while (queue.isNotEmpty()) {
|
||||||
// ArrayDeque implementation will optimize this call to 'removeFirst'
|
// ArrayDeque implementation will optimize this call to 'removeFirst'
|
||||||
val resolved = queue.removeAt(0)
|
val resolved = queue.removeAt(0)
|
||||||
if (resolved != this && results.add(resolved)) {
|
if (resolved != seed && results.add(resolved)) {
|
||||||
queue.addAll(resolved.edges())
|
queue.addAll(resolved.edges())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,8 @@ internal inline fun <reified T> T.transitiveClosure(edges: T.() -> Iterable<T>):
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
private inline fun <reified T> deque(): MutableList<T> {
|
@PublishedApi
|
||||||
|
internal inline fun <reified T> deque(): MutableList<T> {
|
||||||
return if (KotlinVersion.CURRENT.isAtLeast(1, 4)) ArrayDeque()
|
return if (KotlinVersion.CURRENT.isAtLeast(1, 4)) ArrayDeque()
|
||||||
else mutableListOf()
|
else mutableListOf()
|
||||||
}
|
}
|
||||||
+2
-2
@@ -3,7 +3,7 @@
|
|||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* 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
|
package org.jetbrains.kotlin.commonizer
|
||||||
|
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
@@ -25,7 +25,7 @@ class TransitiveClosureTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Node.transitiveClosure() = transitiveClosure { children }
|
private fun Node.transitiveClosure() = org.jetbrains.kotlin.commonizer.util.transitiveClosure(this) { children }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `transitiveClosure does not include root node`() {
|
fun `transitiveClosure does not include root node`() {
|
||||||
Reference in New Issue
Block a user