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:
parent
5bcb8185b8
commit
43844cbf80
5 changed files with 34 additions and 16 deletions
|
@ -12,4 +12,5 @@ data class CompilerActionInfo(val directory: String?,
|
|||
val outputDir: File,
|
||||
val compilerArgs: List<String>,
|
||||
val friendPaths: List<String>,
|
||||
val forceRecompile: Boolean)
|
||||
val forceRecompile: Boolean,
|
||||
val compilerSeparateProcess: Boolean = false)
|
||||
|
|
|
@ -79,9 +79,11 @@ open class NewRunCommand(val info: RunCommandInfo) {
|
|||
|
||||
// Run the command and collect the return code and streams
|
||||
val returnCode = process.waitFor(30, TimeUnit.SECONDS)
|
||||
val input = if (process.inputStream.available() > 0) fromStream(process.inputStream)
|
||||
val input =
|
||||
if (process.inputStream.available() > 0) fromStream(process.inputStream)
|
||||
else listOf()
|
||||
val error = if (process.errorStream.available() > 0) fromStream(process.errorStream)
|
||||
val error =
|
||||
if (process.errorStream.available() > 0) fromStream(process.errorStream)
|
||||
else listOf()
|
||||
|
||||
// Check to see if the command succeeded
|
||||
|
|
|
@ -131,7 +131,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
generatedClasses(project, context, config.outputDir)))
|
||||
val flags = listOf<String>()
|
||||
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)
|
||||
success = cr.failedResult == null
|
||||
|
@ -151,6 +151,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
val allDeps = arrayListOf<IClasspathDependency>()
|
||||
allDeps.add(annotationProcessorDependency())
|
||||
allDeps.addAll(aptJarDependencies(project))
|
||||
|
||||
return allDeps
|
||||
}
|
||||
|
||||
|
@ -177,6 +178,11 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
flags.add(toolsJar.absolutePath)
|
||||
}
|
||||
|
||||
aptJarDependencies(project).forEach {
|
||||
flags.add("-Xplugin")
|
||||
flags.add(it.jarFile.get().absolutePath)
|
||||
}
|
||||
|
||||
//
|
||||
// Pass options to the annotation plugin
|
||||
//
|
||||
|
@ -200,7 +206,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
listOf(Scope.COMPILE),
|
||||
allDeps)
|
||||
dependencies.forEach {
|
||||
val jarFile = it.jarFile.get()
|
||||
val jarFile = it.jarFile.get().absolutePath
|
||||
kaptPluginFlags.add(kaptPluginFlag("apclasspath=$jarFile"))
|
||||
}
|
||||
|
||||
|
@ -214,7 +220,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va
|
|||
.toList() + generatedSources
|
||||
val buildDirectory = File(KFiles.joinDir(project.directory, generated))
|
||||
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 "))
|
||||
val cr = compilerUtils.invokeCompiler(project, context, kotlinPlugin.compiler, cai)
|
||||
|
|
|
@ -89,7 +89,8 @@ class KotlinCompiler @Inject constructor(
|
|||
// the K2JVMCompiler class directly
|
||||
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)
|
||||
|
||||
} else {
|
||||
|
@ -114,20 +115,24 @@ class KotlinCompiler @Inject constructor(
|
|||
val newArgs = listOf(
|
||||
"-classpath", compilerClasspath,
|
||||
K2JVMCompiler::class.java.name,
|
||||
*info.compilerArgs.toTypedArray(),
|
||||
"-classpath", classpath,
|
||||
"-d", info.outputDir.absolutePath,
|
||||
*xFlagsArray,
|
||||
*info.sourceFiles.toTypedArray())
|
||||
.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 {
|
||||
command = java.absolutePath
|
||||
args = newArgs
|
||||
directory = File(".")
|
||||
// The Kotlin compiler issues warnings on stderr :-(
|
||||
containsErrors = { errors: List<String> -> errors.any { it.contains("rror")} }
|
||||
// // The Kotlin compiler issues warnings on stderr :-(
|
||||
useErrorStreamAsErrorIndicator = false
|
||||
// containsErrors = {
|
||||
// errors: List<String> -> errors.any { it.contains("rror")}
|
||||
// }
|
||||
}).invoke()
|
||||
return TaskResult(result == 0, errorMessage = "Error while compiling")
|
||||
}
|
||||
|
@ -388,7 +393,8 @@ class KotlinCompiler @Inject constructor(
|
|||
* JvmCompilerPlugin#createCompilerActionInfo instead
|
||||
*/
|
||||
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)
|
||||
|
||||
|
@ -414,7 +420,7 @@ class KotlinCompiler @Inject constructor(
|
|||
emptyList<String>()
|
||||
}
|
||||
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,
|
||||
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()
|
||||
val args = arrayListOf<String>()
|
||||
var noIncrementalKotlin = false
|
||||
var compilerSeparateProcess = false
|
||||
|
||||
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 {
|
||||
val saved = context?.internalContext?.noIncrementalKotlin ?: false
|
||||
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
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@ class KotlinPlugin @Inject constructor(val executors: KobaltExecutors, val depen
|
|||
sourceFiles(info.sourceFiles)
|
||||
compilerArgs(info.compilerArgs)
|
||||
output = info.outputDir
|
||||
compilerSeparateProcess = info.compilerSeparateProcess
|
||||
}.compile(project, context)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue