Gradle: use builtins workaround only when Gradle >= 3.2 is used
This commit is contained in:
+3
-12
@@ -25,21 +25,12 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.util.io.ZipFileCache
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.vfs.impl.ZipHandler
|
||||
import org.jetbrains.kotlin.com.intellij.openapi.vfs.impl.jar.CoreJarFileSystem
|
||||
import org.jetbrains.kotlin.gradle.utils.ParsedGradleVersion
|
||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile
|
||||
import org.jetbrains.kotlin.incremental.BuildCacheStorage
|
||||
import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifferenceRegistryProvider
|
||||
import java.io.File
|
||||
|
||||
private fun comparableVersionStr(version: String) =
|
||||
"(\\d+)\\.(\\d+).*"
|
||||
.toRegex()
|
||||
.find(version)
|
||||
?.groups
|
||||
?.drop(1)?.take(2)
|
||||
// checking if two subexpression groups are found and length of each is >0 and <4
|
||||
?.let { if (it.all { (it?.value?.length ?: 0).let { it > 0 && it < 4 }}) it else null }
|
||||
?.joinToString(".", transform = { it!!.value.padStart(3, '0') })
|
||||
|
||||
internal class KotlinGradleBuildServices private constructor(gradle: Gradle): BuildAdapter() {
|
||||
companion object {
|
||||
private val CLASS_NAME = KotlinGradleBuildServices::class.java.simpleName
|
||||
@@ -158,9 +149,9 @@ internal class CompilerServicesCleanup() {
|
||||
// It should be noted that because of this behavior there are no benefits of using daemon in these versions.
|
||||
// Starting from 2.4 gradle using cached classloaders, that leads to effective class reusing in the daemon, but
|
||||
// in that case premature stopping of the static daemons may lead to crashes.
|
||||
comparableVersionStr(gradleVersion)?.let {
|
||||
ParsedGradleVersion.parse(gradleVersion)?.let {
|
||||
log.kotlinDebug("detected gradle version $it")
|
||||
if (it < comparableVersionStr("2.4")!!) {
|
||||
if (it < ParsedGradleVersion.parse("2.4")!!) {
|
||||
// TODO: remove ZipFileCache cleanup after switching to recent idea libs
|
||||
stopZipFileCache()
|
||||
}
|
||||
|
||||
+7
-1
@@ -24,6 +24,7 @@ import org.gradle.api.tasks.SourceTask
|
||||
import org.gradle.api.tasks.TaskAction
|
||||
import org.gradle.api.tasks.compile.AbstractCompile
|
||||
import org.gradle.api.tasks.incremental.IncrementalTaskInputs
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.annotation.AnnotationFileUpdater
|
||||
import org.jetbrains.kotlin.annotation.SourceAnnotationsRegistry
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
@@ -42,6 +43,7 @@ import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
||||
import org.jetbrains.kotlin.gradle.plugin.kotlinInfo
|
||||
import org.jetbrains.kotlin.gradle.utils.ParsedGradleVersion
|
||||
import org.jetbrains.kotlin.incremental.*
|
||||
import org.jetbrains.kotlin.incremental.components.SourceRetentionAnnotationHandler
|
||||
import org.jetbrains.kotlin.incremental.multiproject.ArtifactDifferenceRegistryProvider
|
||||
@@ -150,9 +152,13 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
args.pluginClasspaths = pluginOptions.classpath.toTypedArray()
|
||||
args.pluginOptions = pluginOptions.arguments.toTypedArray()
|
||||
args.moduleName = moduleName
|
||||
args.loadBuiltInsFromDependencies = true
|
||||
args.addCompilerBuiltIns = true
|
||||
|
||||
val gradleVersion = getGradleVersion()
|
||||
if (gradleVersion == null || gradleVersion >= ParsedGradleVersion(3, 2)) {
|
||||
args.loadBuiltInsFromDependencies = true
|
||||
}
|
||||
|
||||
friendTaskName?.let addFriendPathForTestTask@ { friendKotlinTaskName ->
|
||||
val friendTask = project.getTasksByName(friendKotlinTaskName, /* recursive = */false).firstOrNull() as? KotlinCompile ?: return@addFriendPathForTestTask
|
||||
args.friendPaths = arrayOf(friendTask.javaOutputDir!!.absolutePath)
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.utils
|
||||
|
||||
internal data class ParsedGradleVersion(val major: Int, val minor: Int) : Comparable<ParsedGradleVersion> {
|
||||
override fun compareTo(other: ParsedGradleVersion): Int {
|
||||
val majorCompare = major.compareTo(other.major)
|
||||
if (majorCompare != 0) return majorCompare
|
||||
|
||||
return minor.compareTo(other.minor)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun String.parseIntOrNull(): Int? =
|
||||
try {
|
||||
toInt()
|
||||
}
|
||||
catch (e: NumberFormatException) {
|
||||
null
|
||||
}
|
||||
|
||||
fun parse(version: String): ParsedGradleVersion? {
|
||||
val matches = "(\\d+)\\.(\\d+).*"
|
||||
.toRegex()
|
||||
.find(version)
|
||||
?.groups
|
||||
?.drop(1)?.take(2)
|
||||
// checking if two subexpression groups are found and length of each is >0 and <4
|
||||
?.let { if (it.all { (it?.value?.length ?: 0).let { it > 0 && it < 4 }}) it else null }
|
||||
|
||||
val versions = matches?.mapNotNull { it?.value?.parseIntOrNull() } ?: emptyList()
|
||||
if (versions.size == 2 && versions.all { it > 0 }) {
|
||||
val (major, minor) = versions
|
||||
return ParsedGradleVersion(major, minor)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.utils
|
||||
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class GradleVersionTest {
|
||||
@Test
|
||||
fun testParse() {
|
||||
fun String.parseToPair() = ParsedGradleVersion.parse(this)?.let { it.major to it.minor }
|
||||
|
||||
assertEquals(2 to 1, "2.1".parseToPair())
|
||||
assertEquals(2 to 10, "2.10".parseToPair())
|
||||
assertEquals(2 to 14, "2.14.1".parseToPair())
|
||||
assertEquals(3 to 2, "3.2-rc-1".parseToPair())
|
||||
assertEquals(3 to 2, "3.2".parseToPair())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCompare() {
|
||||
assert(ParsedGradleVersion(3, 2) == ParsedGradleVersion(3, 2))
|
||||
assert(ParsedGradleVersion(3, 2) > ParsedGradleVersion(2, 14))
|
||||
assert(ParsedGradleVersion(3, 2) > ParsedGradleVersion(3, 1))
|
||||
assert(ParsedGradleVersion(3, 2) < ParsedGradleVersion(3, 3))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user