Turn on relocatable build cache -- change PathSensitivity to RELATIVE
This commit is contained in:
+120
-120
@@ -1,121 +1,121 @@
|
|||||||
package org.jetbrains.kotlin.gradle.internal
|
package org.jetbrains.kotlin.gradle.internal
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import com.intellij.openapi.util.text.StringUtil.compareVersionNumbers
|
import com.intellij.openapi.util.text.StringUtil.compareVersionNumbers
|
||||||
import org.gradle.api.GradleException
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.internal.ConventionTask
|
import org.gradle.api.internal.ConventionTask
|
||||||
import org.gradle.api.tasks.*
|
import org.gradle.api.tasks.*
|
||||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment
|
import org.jetbrains.kotlin.compilerRunner.GradleCompilerEnvironment
|
||||||
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
import org.jetbrains.kotlin.compilerRunner.GradleCompilerRunner
|
||||||
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
|
import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
|
||||||
import org.jetbrains.kotlin.gradle.tasks.*
|
import org.jetbrains.kotlin.gradle.tasks.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@CacheableTask
|
@CacheableTask
|
||||||
open class KaptTask : ConventionTask(), CompilerArgumentAware<K2JVMCompilerArguments> {
|
open class KaptTask : ConventionTask(), CompilerArgumentAware<K2JVMCompilerArguments> {
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
internal val pluginOptions = CompilerPluginOptions()
|
internal val pluginOptions = CompilerPluginOptions()
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
internal lateinit var kotlinCompileTask: KotlinCompile
|
internal lateinit var kotlinCompileTask: KotlinCompile
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
internal lateinit var stubsDir: File
|
internal lateinit var stubsDir: File
|
||||||
|
|
||||||
private fun isInsideDestinationDirs(file: File): Boolean {
|
private fun isInsideDestinationDirs(file: File): Boolean {
|
||||||
return FileUtil.isAncestor(destinationDir, file, /* strict = */ false)
|
return FileUtil.isAncestor(destinationDir, file, /* strict = */ false)
|
||||||
|| FileUtil.isAncestor(classesDir, file, /* strict = */ false)
|
|| FileUtil.isAncestor(classesDir, file, /* strict = */ false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@get:Classpath @get:InputFiles
|
@get:Classpath @get:InputFiles
|
||||||
lateinit var kaptClasspath: List<File>
|
lateinit var kaptClasspath: List<File>
|
||||||
|
|
||||||
@get:OutputDirectory
|
@get:OutputDirectory
|
||||||
internal lateinit var classesDir: File
|
internal lateinit var classesDir: File
|
||||||
|
|
||||||
@get:OutputDirectory
|
@get:OutputDirectory
|
||||||
lateinit var destinationDir: File
|
lateinit var destinationDir: File
|
||||||
|
|
||||||
@get:OutputDirectory
|
@get:OutputDirectory
|
||||||
lateinit var kotlinSourcesDestinationDir: File
|
lateinit var kotlinSourcesDestinationDir: File
|
||||||
|
|
||||||
override fun createCompilerArgs(): K2JVMCompilerArguments = K2JVMCompilerArguments()
|
override fun createCompilerArgs(): K2JVMCompilerArguments = K2JVMCompilerArguments()
|
||||||
|
|
||||||
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean) {
|
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean) {
|
||||||
kotlinCompileTask.setupCompilerArgs(args)
|
kotlinCompileTask.setupCompilerArgs(args)
|
||||||
|
|
||||||
args.pluginClasspaths = (pluginClasspath + args.pluginClasspaths!!).toSet().toTypedArray()
|
args.pluginClasspaths = (pluginClasspath + args.pluginClasspaths!!).toSet().toTypedArray()
|
||||||
args.pluginOptions = (pluginOptions.arguments + args.pluginOptions!!).toTypedArray()
|
args.pluginOptions = (pluginOptions.arguments + args.pluginOptions!!).toTypedArray()
|
||||||
args.verbose = project.hasProperty("kapt.verbose") && project.property("kapt.verbose").toString().toBoolean() == true
|
args.verbose = project.hasProperty("kapt.verbose") && project.property("kapt.verbose").toString().toBoolean() == true
|
||||||
}
|
}
|
||||||
|
|
||||||
@get:Classpath @get:InputFiles
|
@get:Classpath @get:InputFiles
|
||||||
val classpath: FileCollection
|
val classpath: FileCollection
|
||||||
get() = kotlinCompileTask.classpath
|
get() = kotlinCompileTask.classpath
|
||||||
|
|
||||||
@get:Internal
|
@get:Internal
|
||||||
var useBuildCache: Boolean = false
|
var useBuildCache: Boolean = false
|
||||||
|
|
||||||
@get:Classpath @get:InputFiles @Suppress("unused")
|
@get:Classpath @get:InputFiles @Suppress("unused")
|
||||||
internal val kotlinTaskPluginClasspaths get() = kotlinCompileTask.pluginClasspath
|
internal val kotlinTaskPluginClasspaths get() = kotlinCompileTask.pluginClasspath
|
||||||
|
|
||||||
@get:Classpath @get:InputFiles
|
@get:Classpath @get:InputFiles
|
||||||
internal val pluginClasspath get() = pluginOptions.classpath
|
internal val pluginClasspath get() = pluginOptions.classpath
|
||||||
|
|
||||||
@get:InputFiles @get:PathSensitive(PathSensitivity.ABSOLUTE)
|
@get:InputFiles @get:PathSensitive(PathSensitivity.RELATIVE)
|
||||||
val source: FileCollection
|
val source: FileCollection
|
||||||
get() {
|
get() {
|
||||||
val sourcesFromKotlinTask = kotlinCompileTask.source
|
val sourcesFromKotlinTask = kotlinCompileTask.source
|
||||||
.filter { it.extension == "java" && !isInsideDestinationDirs(it) }
|
.filter { it.extension == "java" && !isInsideDestinationDirs(it) }
|
||||||
|
|
||||||
val stubSources = project.fileTree(stubsDir)
|
val stubSources = project.fileTree(stubsDir)
|
||||||
return sourcesFromKotlinTask + stubSources
|
return sourcesFromKotlinTask + stubSources
|
||||||
}
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
fun compile() {
|
fun compile() {
|
||||||
/** Delete everything inside generated sources and classes output directory
|
/** Delete everything inside generated sources and classes output directory
|
||||||
* (annotation processing is not incremental) */
|
* (annotation processing is not incremental) */
|
||||||
destinationDir.clearDirectory()
|
destinationDir.clearDirectory()
|
||||||
classesDir.clearDirectory()
|
classesDir.clearDirectory()
|
||||||
kotlinSourcesDestinationDir.clearDirectory()
|
kotlinSourcesDestinationDir.clearDirectory()
|
||||||
|
|
||||||
val sourceRootsFromKotlin = kotlinCompileTask.sourceRootsContainer.sourceRoots
|
val sourceRootsFromKotlin = kotlinCompileTask.sourceRootsContainer.sourceRoots
|
||||||
val rawSourceRoots = FilteringSourceRootsContainer(sourceRootsFromKotlin, { !isInsideDestinationDirs(it) })
|
val rawSourceRoots = FilteringSourceRootsContainer(sourceRootsFromKotlin, { !isInsideDestinationDirs(it) })
|
||||||
val sourceRoots = SourceRoots.ForJvm.create(kotlinCompileTask.source, rawSourceRoots)
|
val sourceRoots = SourceRoots.ForJvm.create(kotlinCompileTask.source, rawSourceRoots)
|
||||||
|
|
||||||
val args = prepareCompilerArguments()
|
val args = prepareCompilerArguments()
|
||||||
|
|
||||||
val messageCollector = GradleMessageCollector(logger)
|
val messageCollector = GradleMessageCollector(logger)
|
||||||
val outputItemCollector = OutputItemsCollectorImpl()
|
val outputItemCollector = OutputItemsCollectorImpl()
|
||||||
val environment = GradleCompilerEnvironment(kotlinCompileTask.computedCompilerClasspath, messageCollector, outputItemCollector, args)
|
val environment = GradleCompilerEnvironment(kotlinCompileTask.computedCompilerClasspath, messageCollector, outputItemCollector, args)
|
||||||
if (environment.toolsJar == null && !isAtLeastJava9) {
|
if (environment.toolsJar == null && !isAtLeastJava9) {
|
||||||
throw GradleException("Could not find tools.jar in system classpath, which is required for kapt to work")
|
throw GradleException("Could not find tools.jar in system classpath, which is required for kapt to work")
|
||||||
}
|
}
|
||||||
|
|
||||||
val compilerRunner = GradleCompilerRunner(project)
|
val compilerRunner = GradleCompilerRunner(project)
|
||||||
val exitCode = compilerRunner.runJvmCompiler(
|
val exitCode = compilerRunner.runJvmCompiler(
|
||||||
sourceRoots.kotlinSourceFiles,
|
sourceRoots.kotlinSourceFiles,
|
||||||
sourceRoots.javaSourceRoots,
|
sourceRoots.javaSourceRoots,
|
||||||
kotlinCompileTask.javaPackagePrefix,
|
kotlinCompileTask.javaPackagePrefix,
|
||||||
args,
|
args,
|
||||||
environment)
|
environment)
|
||||||
throwGradleExceptionIfError(exitCode)
|
throwGradleExceptionIfError(exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun File.clearDirectory() {
|
private fun File.clearDirectory() {
|
||||||
deleteRecursively()
|
deleteRecursively()
|
||||||
mkdirs()
|
mkdirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
private val isAtLeastJava9: Boolean
|
private val isAtLeastJava9: Boolean
|
||||||
get() = compareVersionNumbers(getJavaRuntimeVersion(), "9") >= 0
|
get() = compareVersionNumbers(getJavaRuntimeVersion(), "9") >= 0
|
||||||
|
|
||||||
private fun getJavaRuntimeVersion(): String {
|
private fun getJavaRuntimeVersion(): String {
|
||||||
val rtVersion = System.getProperty("java.runtime.version")
|
val rtVersion = System.getProperty("java.runtime.version")
|
||||||
return if (Character.isDigit(rtVersion[0])) rtVersion else System.getProperty("java.version")
|
return if (Character.isDigit(rtVersion[0])) rtVersion else System.getProperty("java.version")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -830,7 +830,7 @@ internal class SubpluginEnvironment(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val fileOptionsPathSensitivity = PathSensitivity.ABSOLUTE
|
private val fileOptionsPathSensitivity = PathSensitivity.RELATIVE
|
||||||
|
|
||||||
internal fun Task.registerSubpluginOptionAsInput(subpluginId: String, option: SubpluginOption) {
|
internal fun Task.registerSubpluginOptionAsInput(subpluginId: String, option: SubpluginOption) {
|
||||||
when (option) {
|
when (option) {
|
||||||
|
|||||||
+2
-2
@@ -63,7 +63,7 @@ abstract class AbstractKotlinCompileTool<T : CommonToolArguments>() : AbstractCo
|
|||||||
var compilerClasspath: List<File>? = null
|
var compilerClasspath: List<File>? = null
|
||||||
|
|
||||||
@InputFiles
|
@InputFiles
|
||||||
@PathSensitive(PathSensitivity.ABSOLUTE)
|
@PathSensitive(PathSensitivity.RELATIVE)
|
||||||
override fun getSource() = super.getSource()
|
override fun getSource() = super.getSource()
|
||||||
|
|
||||||
@get:Classpath @get:InputFiles
|
@get:Classpath @get:InputFiles
|
||||||
@@ -473,7 +473,7 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>(),
|
|||||||
|
|
||||||
@get:InputFiles
|
@get:InputFiles
|
||||||
@get:Optional
|
@get:Optional
|
||||||
@get:PathSensitive(PathSensitivity.ABSOLUTE)
|
@get:PathSensitive(PathSensitivity.RELATIVE)
|
||||||
internal val friendDependency
|
internal val friendDependency
|
||||||
get() = friendTaskName
|
get() = friendTaskName
|
||||||
?.let { project.getTasksByName(it, false).singleOrNull() as? Kotlin2JsCompile }
|
?.let { project.getTasksByName(it, false).singleOrNull() as? Kotlin2JsCompile }
|
||||||
|
|||||||
Reference in New Issue
Block a user