[K/N][build] Composite build with build.tools-conventions plugin
Adds convention plugin instead of sources inclusion inside the buildSrc, effectively reducing the amount of the code to be compiled in buildSrc. Merge-request: KT-MR-8898
This commit is contained in:
committed by
Space Team
parent
45637c1b94
commit
395e3e0f81
@@ -39,6 +39,9 @@ plugins {
|
||||
signing
|
||||
id("org.jetbrains.kotlin.jvm") apply false
|
||||
id("org.jetbrains.kotlin.plugin.serialization") apply false
|
||||
if (kotlinBuildProperties.isKotlinNativeEnabled) {
|
||||
id("kotlin.native.build-tools-conventions") apply false
|
||||
}
|
||||
}
|
||||
|
||||
pill {
|
||||
|
||||
@@ -30,7 +30,6 @@ apply {
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
`java-gradle-plugin`
|
||||
`groovy`
|
||||
id("org.jetbrains.kotlin.jvm")
|
||||
id("org.jetbrains.kotlin.plugin.sam.with.receiver")
|
||||
}
|
||||
@@ -84,18 +83,6 @@ java {
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets["main"].withConvention(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::class) {
|
||||
kotlin.srcDir("src/main/kotlin")
|
||||
if (!kotlinBuildProperties.isInJpsBuildIdeaSync) {
|
||||
kotlin.srcDir("../kotlin-native/shared/src/library/kotlin")
|
||||
kotlin.srcDir("../kotlin-native/shared/src/main/kotlin")
|
||||
kotlin.srcDir("../kotlin-native/build-tools/src/main/kotlin")
|
||||
kotlin.srcDir("../kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin")
|
||||
kotlin.srcDir("../compiler/util-klib/src")
|
||||
kotlin.srcDir("../native/utils/src")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.validatePlugins.configure {
|
||||
enabled = false
|
||||
}
|
||||
@@ -124,23 +111,13 @@ dependencies {
|
||||
|
||||
compileOnly(gradleApi())
|
||||
|
||||
val kotlinVersion = project.bootstrapKotlinVersion
|
||||
val metadataVersion = "0.0.1-dev-10"
|
||||
val coroutinesVersion = "1.5.0"
|
||||
|
||||
// See https://github.com/gradle/gradle/issues/22510
|
||||
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:2.4.1")
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib:${project.bootstrapKotlinVersion}")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:${project.bootstrapKotlinVersion}")
|
||||
implementation("com.google.code.gson:gson:2.8.9") // Workaround for Gradle dependency resolution error
|
||||
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-metadata-klib:$metadataVersion")
|
||||
if (kotlinBuildProperties.isInJpsBuildIdeaSync) {
|
||||
implementation("org.jetbrains.kotlin:kotlin-native-utils:${project.bootstrapKotlinVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
samWithReceiver {
|
||||
@@ -161,58 +138,15 @@ tasks.withType<KotlinCompile>().configureEach {
|
||||
}
|
||||
}
|
||||
|
||||
if (!kotlinBuildProperties.isInJpsBuildIdeaSync) {
|
||||
sourceSets["main"].extensions
|
||||
.getByType(GroovySourceDirectorySet::class.java)
|
||||
.srcDir("../kotlin-native/build-tools/src/main/groovy")
|
||||
}
|
||||
|
||||
tasks.withType<GroovyCompile>().configureEach {
|
||||
classpath += project.files(compileKotlin.outputs)
|
||||
dependsOn(compileKotlin)
|
||||
}
|
||||
|
||||
allprojects {
|
||||
tasks.register("checkBuild")
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("compileToBitcode") {
|
||||
id = "compile-to-bitcode"
|
||||
implementationClass = "org.jetbrains.kotlin.bitcode.CompileToBitcodePlugin"
|
||||
}
|
||||
create("runtimeTesting") {
|
||||
id = "runtime-testing"
|
||||
implementationClass = "org.jetbrains.kotlin.testing.native.RuntimeTestingPlugin"
|
||||
}
|
||||
create("compilationDatabase") {
|
||||
id = "compilation-database"
|
||||
implementationClass = "org.jetbrains.kotlin.cpp.CompilationDatabasePlugin"
|
||||
}
|
||||
create("konan") {
|
||||
id = "konan"
|
||||
implementationClass = "org.jetbrains.kotlin.gradle.plugin.konan.KonanPlugin"
|
||||
}
|
||||
// We bundle a shaded version of kotlinx-serialization plugin
|
||||
create("kotlinx-serialization-native") {
|
||||
id = "kotlinx-serialization-native"
|
||||
implementationClass = "shadow.org.jetbrains.kotlinx.serialization.gradle.SerializationGradleSubplugin"
|
||||
}
|
||||
|
||||
create("org.jetbrains.kotlin.konan") {
|
||||
id = "org.jetbrains.kotlin.konan"
|
||||
implementationClass = "org.jetbrains.kotlin.gradle.plugin.konan.KonanPlugin"
|
||||
}
|
||||
|
||||
create("native") {
|
||||
id = "native"
|
||||
implementationClass = "org.jetbrains.gradle.plugins.tools.NativePlugin"
|
||||
}
|
||||
|
||||
create("native-interop-plugin") {
|
||||
id = "native-interop-plugin"
|
||||
implementationClass = "org.jetbrains.kotlin.NativeInteropPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ import org.jetbrains.kotlin.konan.target.HostManager.Companion.hostIsMac
|
||||
|
||||
plugins {
|
||||
`kotlin`
|
||||
`native-interop-plugin`
|
||||
id("kotlin.native.build-tools-conventions")
|
||||
id("native-interop-plugin")
|
||||
`native`
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
import org.jetbrains.gradle.plugins.tools.lib
|
||||
import org.jetbrains.gradle.plugins.tools.solib
|
||||
import org.jetbrains.kotlin.*
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
val kotlinVersion = project.bootstrapKotlinVersion
|
||||
plugins {
|
||||
|
||||
@@ -13,7 +13,7 @@ buildscript {
|
||||
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: org.jetbrains.kotlin.NativeInteropPlugin
|
||||
apply plugin: "native-interop-plugin"
|
||||
apply plugin: "maven-publish"
|
||||
apply plugin: CppConsumerPlugin
|
||||
|
||||
|
||||
@@ -21,17 +21,11 @@ buildscript {
|
||||
url project.bootstrapKotlinRepo
|
||||
}
|
||||
}
|
||||
ext.useCustomDist = UtilsKt.getUseCustomDist(project)
|
||||
ext.kotlinNativeDist = UtilsKt.getKotlinNativeDist(project)
|
||||
if (!useCustomDist) {
|
||||
ext.setProperty("kotlin.native.home", kotlinNativeDist.absolutePath)
|
||||
ext.setProperty("org.jetbrains.kotlin.native.home", kotlinNativeDist.absolutePath)
|
||||
ext.setProperty("konan.home", kotlinNativeDist.absolutePath)
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'konan'
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'kotlin.native.build-tools-conventions'
|
||||
|
||||
configurations {
|
||||
cli_bc
|
||||
@@ -56,6 +50,13 @@ ext.testLibraryDir = "${ext.testOutputRoot}/klib/platform/${project.target.name}
|
||||
// NOTE: If this persists in a gradle daemon, environment update (e.g. an Xcode update) may lead to execution failures.
|
||||
project.extensions.executor = ExecutorServiceKt.create(project)
|
||||
|
||||
ext.useCustomDist = UtilsKt.getUseCustomDist(project)
|
||||
ext.kotlinNativeDist = UtilsKt.getKotlinNativeDist(project)
|
||||
if (!useCustomDist) {
|
||||
ext.setProperty("kotlin.native.home", kotlinNativeDist.absolutePath)
|
||||
ext.setProperty("org.jetbrains.kotlin.native.home", kotlinNativeDist.absolutePath)
|
||||
ext.setProperty("konan.home", kotlinNativeDist.absolutePath)
|
||||
}
|
||||
|
||||
compileTestKotlin {
|
||||
kotlinOptions {
|
||||
|
||||
@@ -6,51 +6,44 @@
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.util.Properties
|
||||
|
||||
plugins {
|
||||
kotlin
|
||||
groovy
|
||||
id("org.gradle.kotlin.kotlin-dsl")
|
||||
id("gradle-plugin-dependency-configuration")
|
||||
id("org.jetbrains.kotlin.plugin.sam.with.receiver")
|
||||
}
|
||||
|
||||
buildscript {
|
||||
val rootBuildDirectory by extra(project.file("../.."))
|
||||
|
||||
apply(from = rootBuildDirectory.resolve("kotlin-native/gradle/loadRootProperties.gradle"))
|
||||
|
||||
dependencies {
|
||||
classpath(commonDependency("com.google.code.gson:gson"))
|
||||
classpath("com.google.code.gson:gson:2.8.9")
|
||||
}
|
||||
}
|
||||
|
||||
val rootProperties = Properties().apply {
|
||||
project(":kotlin-native").projectDir.resolve("gradle.properties").reader().use(::load)
|
||||
}
|
||||
|
||||
val kotlinVersion = project.bootstrapKotlinVersion
|
||||
val metadataVersion: String by rootProperties
|
||||
|
||||
group = "org.jetbrains.kotlin"
|
||||
version = kotlinVersion
|
||||
|
||||
repositories {
|
||||
maven("https://cache-redirector.jetbrains.com/maven-central")
|
||||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
plugins {
|
||||
groovy
|
||||
kotlin("jvm")
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(gradleApi())
|
||||
|
||||
api(kotlinStdlib())
|
||||
implementation(commonDependency("org.jetbrains.kotlin:kotlin-reflect")) { isTransitive = false }
|
||||
api("org.jetbrains.kotlin:kotlin-stdlib:${project.bootstrapKotlinVersion}")
|
||||
implementation("org.jetbrains.kotlin:kotlin-reflect:${project.bootstrapKotlinVersion}") { isTransitive = false }
|
||||
implementation("org.jetbrains.kotlin:kotlin-build-gradle-plugin:${kotlinBuildProperties.buildGradlePluginVersion}")
|
||||
implementation("org.jetbrains.kotlin:kotlin-native-utils:${project.bootstrapKotlinVersion}")
|
||||
|
||||
// To build Konan Gradle plugin
|
||||
implementation("org.jetbrains.kotlin:kotlin-build-common:${project.bootstrapKotlinVersion}")
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:${project.bootstrapKotlinVersion}")
|
||||
|
||||
val versionProperties = Properties()
|
||||
project.rootProject.projectDir.resolve("gradle/versions.properties").inputStream().use { propInput ->
|
||||
project.rootProject.projectDir.resolve("../../gradle/versions.properties").inputStream().use { propInput ->
|
||||
versionProperties.load(propInput)
|
||||
}
|
||||
implementation(commonDependency("com.google.code.gson:gson"))
|
||||
implementation("com.google.code.gson:gson:2.8.9")
|
||||
configurations.all {
|
||||
resolutionStrategy.eachDependency {
|
||||
if (requested.group == "com.google.code.gson" && requested.name == "gson") {
|
||||
@@ -60,12 +53,18 @@ dependencies {
|
||||
}
|
||||
}
|
||||
|
||||
implementation(commonDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core"))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0")
|
||||
val metadataVersion = "0.0.1-dev-10"
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-metadata-klib:$metadataVersion")
|
||||
|
||||
implementation(commonDependency("org.jetbrains.kotlin:kotlin-native-utils:$kotlinVersion"))
|
||||
implementation(commonDependency("org.jetbrains.kotlinx:kotlinx-metadata-klib:$metadataVersion"))
|
||||
implementation("org.jetbrains.kotlin:kotlin-util-klib:${project.bootstrapKotlinVersion}")
|
||||
implementation("org.jetbrains.kotlin:kotlin-native-utils:${project.bootstrapKotlinVersion}")
|
||||
}
|
||||
|
||||
api(project(":kotlin-native-shared"))
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(8))
|
||||
}
|
||||
}
|
||||
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
@@ -73,11 +72,12 @@ val compileGroovy: GroovyCompile by tasks
|
||||
|
||||
compileKotlin.apply {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs += listOf(
|
||||
"-Xskip-prerelease-check",
|
||||
"-Xsuppress-version-warnings",
|
||||
"-opt-in=kotlin.ExperimentalStdlibApi")
|
||||
"-opt-in=kotlin.ExperimentalStdlibApi",
|
||||
"-opt-in=kotlin.RequiresOptIn"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,3 +86,43 @@ compileGroovy.apply {
|
||||
classpath += project.files(compileKotlin.destinationDirectory)
|
||||
dependsOn(compileKotlin)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
main {
|
||||
kotlin.srcDir("src/main/kotlin")
|
||||
kotlin.srcDir("../../kotlin-native/shared/src/library/kotlin")
|
||||
kotlin.srcDir("../../kotlin-native/shared/src/main/kotlin")
|
||||
kotlin.srcDir("../../kotlin-native/tools/kotlin-native-gradle-plugin/src/main/kotlin")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
create("compileToBitcode") {
|
||||
id = "compile-to-bitcode"
|
||||
implementationClass = "org.jetbrains.kotlin.bitcode.CompileToBitcodePlugin"
|
||||
}
|
||||
create("runtimeTesting") {
|
||||
id = "runtime-testing"
|
||||
implementationClass = "org.jetbrains.kotlin.testing.native.RuntimeTestingPlugin"
|
||||
}
|
||||
create("compilationDatabase") {
|
||||
id = "compilation-database"
|
||||
implementationClass = "org.jetbrains.kotlin.cpp.CompilationDatabasePlugin"
|
||||
}
|
||||
create("konanPlugin") {
|
||||
id = "konan"
|
||||
implementationClass = "org.jetbrains.kotlin.gradle.plugin.konan.KonanPlugin"
|
||||
}
|
||||
create("native-interop-plugin") {
|
||||
id = "native-interop-plugin"
|
||||
implementationClass = "org.jetbrains.kotlin.NativeInteropPlugin"
|
||||
}
|
||||
create("native") {
|
||||
id = "native"
|
||||
implementationClass = "org.jetbrains.kotlin.tools.NativePlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
cacheRedirectorEnabled=true
|
||||
bootstrap.kotlin.default.version=1.8.20-dev-5197
|
||||
kotlin.build.gradlePlugin.version=0.0.39
|
||||
|
||||
org.gradle.java.installations.fromEnv=\
|
||||
JDK_1_6,JDK_16,\
|
||||
JDK_1_7,JDK_17,\
|
||||
JDK_1_8,JDK_18,\
|
||||
JDK_9_0,JDK_9,\
|
||||
JDK_10_0,JDK_10,\
|
||||
JDK_11_0,JDK_11,\
|
||||
JDK_15_0,JDK_15,\
|
||||
JDK_16_0,\
|
||||
JDK_17_0
|
||||
@@ -0,0 +1,29 @@
|
||||
rootProject.name = "build-tools"
|
||||
|
||||
pluginManagement {
|
||||
apply(from = "../../repo/scripts/cache-redirector.settings.gradle.kts")
|
||||
apply(from = "../../repo/scripts/kotlin-bootstrap.settings.gradle.kts")
|
||||
repositories {
|
||||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
id("jvm-toolchain-provisioning")
|
||||
id("build-cache")
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-dependencies")
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
val buildGradlePluginVersion = extra["kotlin.build.gradlePlugin.version"]
|
||||
dependencies {
|
||||
classpath("org.jetbrains.kotlin:kotlin-build-gradle-plugin:$buildGradlePluginVersion")
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,11 @@ import org.gradle.api.Action
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.internal.file.FileOperations
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.process.ExecOperations
|
||||
import org.gradle.process.ExecResult
|
||||
import org.gradle.process.ExecSpec
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import org.jetbrains.kotlin.konan.file.*
|
||||
import org.jetbrains.kotlin.konan.file.File as KFile
|
||||
import java.io.File
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@@ -7,13 +7,11 @@ package org.jetbrains.kotlin
|
||||
|
||||
import groovy.lang.Closure
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.*
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Files
|
||||
|
||||
/**
|
||||
* Gradle task that wraps FileCheck LLVM utility.
|
||||
|
||||
+3
-2
@@ -4,6 +4,7 @@ import org.gradle.api.Action
|
||||
import org.gradle.api.Task
|
||||
import org.gradle.api.tasks.Input
|
||||
import org.gradle.api.tasks.Internal
|
||||
import org.gradle.api.tasks.Nested
|
||||
|
||||
/**
|
||||
* An interface that any test that works with ExecutorService
|
||||
@@ -20,7 +21,7 @@ interface KonanTestExecutable : Task {
|
||||
* Action that configures task or does some workload before the test will be executed.
|
||||
* Could be done as a first step in the test or just as a `doFirst` action in the test task.
|
||||
*/
|
||||
@get:Input
|
||||
@get:Nested
|
||||
var doBeforeRun: Action<in Task>?
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,7 @@ interface KonanTestExecutable : Task {
|
||||
* Depending on the test task implementation this action is done before the build task
|
||||
* or as its `doFirst` action.
|
||||
*/
|
||||
@get:Input
|
||||
@get:Nested
|
||||
var doBeforeBuild: Action<in Task>?
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin
|
||||
import org.gradle.process.ExecSpec
|
||||
import org.jetbrains.kotlin.konan.exec.Command
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.target.Family
|
||||
import org.jetbrains.kotlin.konan.target.LinkerOutputKind
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
import com.google.gson.*
|
||||
import com.google.gson.annotations.*
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
import java.io.File
|
||||
|
||||
private const val MODULE_DELIMITER = ",\\s*"
|
||||
// These patterns are copies from
|
||||
|
||||
@@ -18,8 +18,6 @@ import org.jetbrains.kotlin.konan.properties.saveProperties
|
||||
import org.jetbrains.kotlin.konan.target.*
|
||||
import java.io.File
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.nio.file.Path
|
||||
import org.jetbrains.kotlin.konan.file.File as KFile
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
|
||||
-1
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.cpp
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.attributes.Attribute
|
||||
import org.gradle.api.attributes.AttributeDisambiguationRule
|
||||
import org.gradle.api.attributes.MultipleCandidatesDetails
|
||||
import org.jetbrains.kotlin.bitcode.CompileToBitcodePlugin
|
||||
|
||||
-1
@@ -13,7 +13,6 @@ import org.gradle.api.provider.Provider
|
||||
import org.gradle.api.tasks.TaskProvider
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import org.jetbrains.kotlin.bitcode.CompileToBitcodeExtension
|
||||
import org.jetbrains.kotlin.bitcode.CompileToBitcodePlugin
|
||||
import org.jetbrains.kotlin.resolve
|
||||
import java.io.File
|
||||
import java.net.URL
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
package org.jetbrains.kotlin.utils
|
||||
|
||||
import java.util.*
|
||||
|
||||
// Copied from Kotlin org.jetbrains.kotlin.utils.DFS class
|
||||
@Suppress("MemberVisibilityCanBePrivate", "MemberVisibilityCanBePrivate", "unused")
|
||||
object DFS {
|
||||
fun <N, R> dfs(nodes: Collection<N>, neighbors: Neighbors<N>, visited: Visited<N>, handler: NodeHandler<N, R>): R {
|
||||
for (node in nodes) {
|
||||
doDfs(node, neighbors, visited, handler)
|
||||
}
|
||||
return handler.result()
|
||||
}
|
||||
|
||||
fun <N, R> dfs(
|
||||
nodes: Collection<N>,
|
||||
neighbors: Neighbors<N>,
|
||||
handler: NodeHandler<N, R>
|
||||
): R {
|
||||
return dfs(nodes, neighbors, VisitedWithSet(), handler)
|
||||
}
|
||||
|
||||
fun <N> ifAny(
|
||||
nodes: Collection<N>,
|
||||
neighbors: Neighbors<N>,
|
||||
predicate: Function1<N, Boolean>
|
||||
): Boolean {
|
||||
val result = BooleanArray(1)
|
||||
return dfs(nodes, neighbors, object : AbstractNodeHandler<N, Boolean?>() {
|
||||
override fun beforeChildren(current: N): Boolean {
|
||||
if (predicate.invoke(current)) {
|
||||
result[0] = true
|
||||
}
|
||||
return !result[0]
|
||||
}
|
||||
|
||||
override fun result(): Boolean {
|
||||
return result[0]
|
||||
}
|
||||
})!!
|
||||
}
|
||||
|
||||
fun <N, R> dfsFromNode(node: N, neighbors: Neighbors<N>, visited: Visited<N>, handler: NodeHandler<N, R>): R {
|
||||
doDfs(node, neighbors, visited, handler)
|
||||
return handler.result()
|
||||
}
|
||||
|
||||
fun <N> dfsFromNode(
|
||||
node: N,
|
||||
neighbors: Neighbors<N>,
|
||||
visited: Visited<N>
|
||||
) {
|
||||
dfsFromNode(node, neighbors, visited, object : AbstractNodeHandler<N, Void?>() {
|
||||
override fun result(): Void? {
|
||||
return null
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun <N> topologicalOrder(nodes: Iterable<N>, neighbors: Neighbors<N>, visited: Visited<N>): List<N> {
|
||||
val handler = TopologicalOrder<N>()
|
||||
for (node in nodes) {
|
||||
doDfs(node, neighbors, visited, handler)
|
||||
}
|
||||
return handler.result()
|
||||
}
|
||||
|
||||
fun <N> topologicalOrder(nodes: Iterable<N>, neighbors: Neighbors<N>): List<N> {
|
||||
return topologicalOrder(nodes, neighbors, VisitedWithSet())
|
||||
}
|
||||
|
||||
fun <N> doDfs(current: N, neighbors: Neighbors<N>, visited: Visited<N>, handler: NodeHandler<N, *>) {
|
||||
if (!visited.checkAndMarkVisited(current)) return
|
||||
if (!handler.beforeChildren(current)) return
|
||||
for (neighbor in neighbors.getNeighbors(current)) {
|
||||
doDfs(neighbor, neighbors, visited, handler)
|
||||
}
|
||||
handler.afterChildren(current)
|
||||
}
|
||||
|
||||
interface NodeHandler<N, R> {
|
||||
fun beforeChildren(current: N): Boolean
|
||||
fun afterChildren(current: N)
|
||||
fun result(): R
|
||||
}
|
||||
|
||||
interface Neighbors<N> {
|
||||
fun getNeighbors(current: N): Iterable<N>
|
||||
}
|
||||
|
||||
interface Visited<N> {
|
||||
fun checkAndMarkVisited(current: N): Boolean
|
||||
}
|
||||
|
||||
abstract class AbstractNodeHandler<N, R> : NodeHandler<N, R> {
|
||||
override fun beforeChildren(current: N): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun afterChildren(current: N) {}
|
||||
}
|
||||
|
||||
class VisitedWithSet<N> @JvmOverloads constructor(private val visited: MutableSet<N> = HashSet()) : Visited<N> {
|
||||
override fun checkAndMarkVisited(current: N): Boolean {
|
||||
return visited.add(current)
|
||||
}
|
||||
}
|
||||
|
||||
abstract class CollectingNodeHandler<N, R, C : Iterable<R>> protected constructor(protected val result: C) : AbstractNodeHandler<N, C>() {
|
||||
override fun result(): C {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
abstract class NodeHandlerWithListResult<N, R> protected constructor() : CollectingNodeHandler<N, R, LinkedList<R>>(LinkedList<R>())
|
||||
class TopologicalOrder<N> : NodeHandlerWithListResult<N, N>() {
|
||||
override fun afterChildren(current: N) {
|
||||
result.addFirst(current)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,8 @@ if (isMac()) {
|
||||
checkXcodeVersion(project)
|
||||
}
|
||||
|
||||
apply plugin: "kotlin.native.build-tools-conventions"
|
||||
|
||||
ext {
|
||||
distDir = UtilsKt.getKotlinNativeDist(project)
|
||||
dependenciesDir = DependencyProcessor.defaultDependenciesRoot
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("kotlin.native.build-tools-conventions")
|
||||
id("compile-to-bitcode")
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ extra["org.jetbrains.kotlin.native.home"] = konanHome
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
konan
|
||||
id("kotlin.native.build-tools-conventions")
|
||||
id("konan")
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
||||
@@ -6,13 +6,13 @@ import org.jetbrains.kotlin.UtilsKt
|
||||
|
||||
buildscript {
|
||||
apply from: "$rootDir/kotlin-native/gradle/kotlinGradlePlugin.gradle"
|
||||
|
||||
ext.useCustomDist = UtilsKt.getUseCustomDist(project)
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'konan'
|
||||
|
||||
ext.useCustomDist = UtilsKt.getUseCustomDist(project)
|
||||
|
||||
konanArtifacts {
|
||||
def testFiles = fileTree('src/test/testData') {
|
||||
include "*.kt"
|
||||
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.jetbrains.gradle.plugins.tools.lib
|
||||
import org.jetbrains.kotlin.*
|
||||
import org.jetbrains.kotlin.konan.target.Family.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
plugins{
|
||||
`native`
|
||||
import org.jetbrains.kotlin.tools.lib
|
||||
import org.jetbrains.kotlin.*
|
||||
|
||||
plugins {
|
||||
id("kotlin.native.build-tools-conventions")
|
||||
id("native")
|
||||
}
|
||||
val libclangextEnabled = org.jetbrains.kotlin.konan.target.HostManager.hostIsMac
|
||||
extra["isEnabled"] = libclangextEnabled
|
||||
|
||||
@@ -14,14 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.jetbrains.gradle.plugins.tools.lib
|
||||
import org.jetbrains.kotlin.tools.lib
|
||||
import org.jetbrains.kotlin.*
|
||||
import org.jetbrains.kotlin.konan.target.ClangArgs
|
||||
import org.jetbrains.kotlin.konan.target.Family.*
|
||||
import org.jetbrains.kotlin.konan.target.HostManager
|
||||
|
||||
plugins {
|
||||
`native`
|
||||
id("kotlin.native.build-tools-conventions")
|
||||
id("native")
|
||||
}
|
||||
|
||||
native {
|
||||
|
||||
@@ -105,11 +105,11 @@ gradlePlugin {
|
||||
}
|
||||
create("compileToBitcode") {
|
||||
id = "compile-to-bitcode"
|
||||
implementationClass = "org.jetbrains.kotlin.bitcode.CompileToBitcodePlugin"
|
||||
implementationClass = "CompileToBitcodePlugin"
|
||||
}
|
||||
create("runtimeTesting") {
|
||||
id = "runtime-testing"
|
||||
implementationClass = "org.jetbrains.kotlin.testing.native.RuntimeTestingPlugin"
|
||||
implementationClass = "RuntimeTestingPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+36
-52
@@ -18,11 +18,10 @@ import org.gradle.nativeplatform.TargetMachine
|
||||
import org.gradle.nativeplatform.TargetMachineFactory
|
||||
import org.gradle.nativeplatform.platform.NativePlatform
|
||||
import org.gradle.nativeplatform.platform.internal.*
|
||||
import org.jetbrains.kotlin.gradle.utils.isGradleVersionAtLeast
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.konan.util.visibleName
|
||||
|
||||
interface KotlinNativePlatform: NativePlatform {
|
||||
interface KotlinNativePlatform : NativePlatform {
|
||||
val target: KonanTarget
|
||||
}
|
||||
|
||||
@@ -38,19 +37,18 @@ fun KonanTarget.getGradleCPU(): ArchitectureInternal = architecture.visibleName.
|
||||
Architectures.forInput(it)
|
||||
}
|
||||
|
||||
fun KonanTarget.toTargetMachine(objectFactory: ObjectFactory): TargetMachine = object: TargetMachine {
|
||||
fun KonanTarget.toTargetMachine(objectFactory: ObjectFactory): TargetMachine = object : TargetMachine {
|
||||
override fun getOperatingSystemFamily(): OperatingSystemFamily =
|
||||
getGradleOSFamily(objectFactory)
|
||||
getGradleOSFamily(objectFactory)
|
||||
|
||||
override fun getArchitecture(): MachineArchitecture =
|
||||
objectFactory.named(MachineArchitecture::class.java, this@toTargetMachine.architecture.visibleName)
|
||||
objectFactory.named(MachineArchitecture::class.java, this@toTargetMachine.architecture.visibleName)
|
||||
}
|
||||
|
||||
class DefaultKotlinNativePlatform(name: String, override val target: KonanTarget):
|
||||
class DefaultKotlinNativePlatform(name: String, override val target: KonanTarget) :
|
||||
DefaultNativePlatform(name, target.getGradleOS(), target.getGradleCPU()),
|
||||
KotlinNativePlatform
|
||||
{
|
||||
constructor(target: KonanTarget): this(target.visibleName, target)
|
||||
KotlinNativePlatform {
|
||||
constructor(target: KonanTarget) : this(target.visibleName, target)
|
||||
|
||||
// TODO: Extend ImmutableDefaultNativePlatform and get rid of these methods after switch to Gradle 4.8
|
||||
private fun notImplemented(): Nothing = throw NotImplementedError("Not Implemented in Kotlin/Native plugin")
|
||||
@@ -62,50 +60,36 @@ class DefaultKotlinNativePlatform(name: String, override val target: KonanTarget
|
||||
// NativeVariantIdentity constructor was changed in Gradle 5.1
|
||||
// So we have to use reflection to create instance of this class in earlier versions.
|
||||
internal fun compatibleVariantIdentity(
|
||||
project: Project,
|
||||
name: String,
|
||||
baseName: Provider<String>,
|
||||
group: Provider<String>,
|
||||
version: Provider<String>,
|
||||
debuggable: Boolean,
|
||||
optimized: Boolean,
|
||||
target: KonanTarget,
|
||||
linkUsage: UsageContext?,
|
||||
runtimeUsage: UsageContext?
|
||||
project: Project,
|
||||
name: String,
|
||||
baseName: Provider<String>,
|
||||
group: Provider<String>,
|
||||
version: Provider<String>,
|
||||
debuggable: Boolean,
|
||||
optimized: Boolean,
|
||||
target: KonanTarget,
|
||||
linkUsage: UsageContext?,
|
||||
runtimeUsage: UsageContext?
|
||||
): NativeVariantIdentity =
|
||||
if (isGradleVersionAtLeast(5, 1)) {
|
||||
val targetMachineFactory = (project as ProjectInternal).services.get(TargetMachineFactory::class.java)
|
||||
NativeVariantIdentity(
|
||||
name,
|
||||
baseName,
|
||||
group,
|
||||
version,
|
||||
debuggable,
|
||||
optimized,
|
||||
targetMachineFactory.os(target.family.name),
|
||||
linkUsage,
|
||||
runtimeUsage
|
||||
)
|
||||
} else {
|
||||
NativeVariantIdentity::class.java.getConstructor(
|
||||
String::class.java,
|
||||
Provider::class.java,
|
||||
Provider::class.java,
|
||||
Provider::class.java,
|
||||
Boolean::class.javaPrimitiveType,
|
||||
Boolean::class.javaPrimitiveType,
|
||||
OperatingSystemFamily::class.java,
|
||||
UsageContext::class.java,
|
||||
UsageContext::class.java
|
||||
String::class.java,
|
||||
Provider::class.java,
|
||||
Provider::class.java,
|
||||
Provider::class.java,
|
||||
Boolean::class.javaPrimitiveType,
|
||||
Boolean::class.javaPrimitiveType,
|
||||
OperatingSystemFamily::class.java,
|
||||
UsageContext::class.java,
|
||||
UsageContext::class.java
|
||||
).newInstance(
|
||||
name,
|
||||
baseName,
|
||||
group,
|
||||
version,
|
||||
debuggable,
|
||||
optimized,
|
||||
target.getGradleOSFamily(project.objects),
|
||||
linkUsage,
|
||||
runtimeUsage
|
||||
name,
|
||||
baseName,
|
||||
group,
|
||||
version,
|
||||
debuggable,
|
||||
optimized,
|
||||
target.getGradleOSFamily(project.objects),
|
||||
linkUsage,
|
||||
runtimeUsage
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -342,7 +342,7 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
|
||||
// If the JDK that was set is not available get the JDK 11 as a default
|
||||
service.launcherFor(object : Action<JavaToolchainSpec> {
|
||||
override fun execute(toolchainSpec: JavaToolchainSpec) {
|
||||
toolchainSpec.languageVersion.set(JavaLanguageVersion.of(JdkMajorVersion.JDK_11_0.majorVersion))
|
||||
toolchainSpec.languageVersion.set(JavaLanguageVersion.of(11)) // FIXME: not resolved from buildSrc JdkMajorVersion.JDK_11_0.majorVersion))
|
||||
}
|
||||
}).get()
|
||||
}
|
||||
|
||||
+1
-1
@@ -788,6 +788,7 @@ project(':kotlin-scripting-ide-common').projectDir = "$rootDir/plugins/scripting
|
||||
// Uncomment to use locally built protobuf-relocated
|
||||
// includeBuild("dependencies/protobuf")
|
||||
if (buildProperties.isKotlinNativeEnabled) {
|
||||
includeBuild("kotlin-native/build-tools")
|
||||
include ':kotlin-native:dependencies'
|
||||
include ':kotlin-native:endorsedLibraries:kotlinx.cli'
|
||||
include ':kotlin-native:endorsedLibraries'
|
||||
@@ -810,7 +811,6 @@ if (buildProperties.isKotlinNativeEnabled) {
|
||||
include ':kotlin-native:backend.native:tests'
|
||||
include ":kotlin-native-compiler-embeddable"
|
||||
project(":kotlin-native-compiler-embeddable").projectDir = "$rootDir/kotlin-native/prepare/kotlin-native-embeddable-compiler" as File
|
||||
include ':kotlin-native:build-tools'
|
||||
include ':kotlin-native-shared'
|
||||
project(":kotlin-native-shared").projectDir = "$rootDir/kotlin-native/shared" as File
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user