1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 00:17:11 -07:00

Fix class path look up in kapt3.

This commit is contained in:
Cedric Beust 2017-04-19 11:16:05 -07:00
parent 5bcb8185b8
commit 43844cbf80
5 changed files with 34 additions and 16 deletions

View file

@ -12,4 +12,5 @@ data class CompilerActionInfo(val directory: String?,
val outputDir: File, val outputDir: File,
val compilerArgs: List<String>, val compilerArgs: List<String>,
val friendPaths: List<String>, val friendPaths: List<String>,
val forceRecompile: Boolean) val forceRecompile: Boolean,
val compilerSeparateProcess: Boolean = false)

View file

@ -79,10 +79,12 @@ open class NewRunCommand(val info: RunCommandInfo) {
// Run the command and collect the return code and streams // Run the command and collect the return code and streams
val returnCode = process.waitFor(30, TimeUnit.SECONDS) val returnCode = process.waitFor(30, TimeUnit.SECONDS)
val input = if (process.inputStream.available() > 0) fromStream(process.inputStream) val input =
else listOf() if (process.inputStream.available() > 0) fromStream(process.inputStream)
val error = if (process.errorStream.available() > 0) fromStream(process.errorStream) else listOf()
else listOf() val error =
if (process.errorStream.available() > 0) fromStream(process.errorStream)
else listOf()
// Check to see if the command succeeded // Check to see if the command succeeded
val isSuccess = val isSuccess =

View file

@ -131,7 +131,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
generatedClasses(project, context, config.outputDir))) generatedClasses(project, context, config.outputDir)))
val flags = listOf<String>() val flags = listOf<String>()
val cai = CompilerActionInfo(project.directory, allDependencies(project), sourceFiles, listOf(".kt"), val cai = CompilerActionInfo(project.directory, allDependencies(project), sourceFiles, listOf(".kt"),
buildDirectory, flags, emptyList(), forceRecompile = true) buildDirectory, flags, emptyList(), forceRecompile = true, compilerSeparateProcess = true)
val cr = compilerUtils.invokeCompiler(project, context, kotlinPlugin.compiler, cai) val cr = compilerUtils.invokeCompiler(project, context, kotlinPlugin.compiler, cai)
success = cr.failedResult == null success = cr.failedResult == null
@ -151,6 +151,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
val allDeps = arrayListOf<IClasspathDependency>() val allDeps = arrayListOf<IClasspathDependency>()
allDeps.add(annotationProcessorDependency()) allDeps.add(annotationProcessorDependency())
allDeps.addAll(aptJarDependencies(project)) allDeps.addAll(aptJarDependencies(project))
return allDeps return allDeps
} }
@ -177,6 +178,11 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
flags.add(toolsJar.absolutePath) flags.add(toolsJar.absolutePath)
} }
aptJarDependencies(project).forEach {
flags.add("-Xplugin")
flags.add(it.jarFile.get().absolutePath)
}
// //
// Pass options to the annotation plugin // Pass options to the annotation plugin
// //
@ -200,12 +206,12 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
listOf(Scope.COMPILE), listOf(Scope.COMPILE),
allDeps) allDeps)
dependencies.forEach { dependencies.forEach {
val jarFile = it.jarFile.get() val jarFile = it.jarFile.get().absolutePath
kaptPluginFlags.add(kaptPluginFlag("apclasspath=$jarFile")) kaptPluginFlags.add(kaptPluginFlag("apclasspath=$jarFile"))
} }
flags.add(kaptPluginFlags.joinToString(",")) flags.add(kaptPluginFlags.joinToString(","))
listOf("-language-version", "1.1", " -api-version", "1.1").forEach { listOf("-language-version", "1.1", "-api-version", "1.1").forEach {
flags.add(it) flags.add(it)
} }
@ -214,7 +220,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
.toList() + generatedSources .toList() + generatedSources
val buildDirectory = File(KFiles.joinDir(project.directory, generated)) val buildDirectory = File(KFiles.joinDir(project.directory, generated))
val cai = CompilerActionInfo(project.directory, allDeps, sourceFiles, listOf(".kt"), val cai = CompilerActionInfo(project.directory, allDeps, sourceFiles, listOf(".kt"),
buildDirectory, flags, emptyList(), forceRecompile = true) buildDirectory, flags, emptyList(), forceRecompile = true, compilerSeparateProcess = true)
context.logger.log(project.name, 2, " " + kaptPluginFlags.joinToString("\n ")) context.logger.log(project.name, 2, " " + kaptPluginFlags.joinToString("\n "))
val cr = compilerUtils.invokeCompiler(project, context, kotlinPlugin.compiler, cai) val cr = compilerUtils.invokeCompiler(project, context, kotlinPlugin.compiler, cai)

View file

@ -89,7 +89,8 @@ class KotlinCompiler @Inject constructor(
// the K2JVMCompiler class directly // the K2JVMCompiler class directly
val actualVersion = kotlinVersion(project) val actualVersion = kotlinVersion(project)
if (settings.kobaltCompilerSeparateProcess || actualVersion != Constants.KOTLIN_COMPILER_VERSION) { if (settings.kobaltCompilerSeparateProcess || actualVersion != Constants.KOTLIN_COMPILER_VERSION
|| info.compilerSeparateProcess) {
return invokeCompilerInSeparateProcess(classpath, info, actualVersion, project) return invokeCompilerInSeparateProcess(classpath, info, actualVersion, project)
} else { } else {
@ -114,20 +115,24 @@ class KotlinCompiler @Inject constructor(
val newArgs = listOf( val newArgs = listOf(
"-classpath", compilerClasspath, "-classpath", compilerClasspath,
K2JVMCompiler::class.java.name, K2JVMCompiler::class.java.name,
*info.compilerArgs.toTypedArray(),
"-classpath", classpath, "-classpath", classpath,
"-d", info.outputDir.absolutePath, "-d", info.outputDir.absolutePath,
*xFlagsArray, *xFlagsArray,
*info.sourceFiles.toTypedArray()) *info.sourceFiles.toTypedArray())
.filter { ! it.isEmpty() } .filter { ! it.isEmpty() }
log(2, " Invoking separate kotlinc:\n " + java!!.absolutePath + " " + newArgs.joinToString()) log(2, " Invoking separate kotlinc:\n " + java!!.absolutePath + " " + newArgs.joinToString(" "))
val result = NewRunCommand(RunCommandInfo().apply { val result = NewRunCommand(RunCommandInfo().apply {
command = java.absolutePath command = java.absolutePath
args = newArgs args = newArgs
directory = File(".") directory = File(".")
// The Kotlin compiler issues warnings on stderr :-( // // The Kotlin compiler issues warnings on stderr :-(
containsErrors = { errors: List<String> -> errors.any { it.contains("rror")} } useErrorStreamAsErrorIndicator = false
// containsErrors = {
// errors: List<String> -> errors.any { it.contains("rror")}
// }
}).invoke() }).invoke()
return TaskResult(result == 0, errorMessage = "Error while compiling") return TaskResult(result == 0, errorMessage = "Error while compiling")
} }
@ -388,7 +393,8 @@ class KotlinCompiler @Inject constructor(
* JvmCompilerPlugin#createCompilerActionInfo instead * JvmCompilerPlugin#createCompilerActionInfo instead
*/ */
fun compile(project: Project?, context: KobaltContext?, compileDependencies: List<IClasspathDependency>, fun compile(project: Project?, context: KobaltContext?, compileDependencies: List<IClasspathDependency>,
otherClasspath: List<String>, sourceFiles: List<String>, outputDir: File, args: List<String>) : TaskResult { otherClasspath: List<String>, sourceFiles: List<String>, outputDir: File, args: List<String>,
compilerSeparateProcess: Boolean) : TaskResult {
val executor = executors.newExecutor("KotlinCompiler", 10) val executor = executors.newExecutor("KotlinCompiler", 10)
@ -414,7 +420,7 @@ class KotlinCompiler @Inject constructor(
emptyList<String>() emptyList<String>()
} }
val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args, val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args,
friendPaths, context?.internalContext?.forceRecompile ?: false) friendPaths, context?.internalContext?.forceRecompile ?: false, compilerSeparateProcess)
return jvmCompiler.doCompile(project, context, compilerAction, info, return jvmCompiler.doCompile(project, context, compilerAction, info,
if (context != null) compilerUtils.sourceCompilerFlags(project, context, info) else emptyList()) if (context != null) compilerUtils.sourceCompilerFlags(project, context, info) else emptyList())
@ -428,6 +434,7 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){
var output: File by Delegates.notNull() var output: File by Delegates.notNull()
val args = arrayListOf<String>() val args = arrayListOf<String>()
var noIncrementalKotlin = false var noIncrementalKotlin = false
var compilerSeparateProcess = false
fun sourceFiles(s: String) = source.add(s) fun sourceFiles(s: String) = source.add(s)
@ -442,7 +449,8 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){
fun compile(project: Project? = null, context: KobaltContext? = null) : TaskResult { fun compile(project: Project? = null, context: KobaltContext? = null) : TaskResult {
val saved = context?.internalContext?.noIncrementalKotlin ?: false val saved = context?.internalContext?.noIncrementalKotlin ?: false
if (context != null) context.internalContext.noIncrementalKotlin = noIncrementalKotlin if (context != null) context.internalContext.noIncrementalKotlin = noIncrementalKotlin
val result = compiler.compile(project, context, dependencies, classpath, source, output, args) val result = compiler.compile(project, context, dependencies, classpath, source, output, args,
compilerSeparateProcess)
if (context != null) context.internalContext.noIncrementalKotlin = saved if (context != null) context.internalContext.noIncrementalKotlin = saved
return result return result
} }

View file

@ -83,6 +83,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen
sourceFiles(info.sourceFiles) sourceFiles(info.sourceFiles)
compilerArgs(info.compilerArgs) compilerArgs(info.compilerArgs)
output = info.outputDir output = info.outputDir
compilerSeparateProcess = info.compilerSeparateProcess
}.compile(project, context) }.compile(project, context)
} }