From 1f3f666d93b34c0cfc4eb3553677a1f74f5b5f78 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 10 Mar 2017 12:39:44 -0800 Subject: [PATCH] Always compile the build files with Kotlin incremental compilation disabled. --- .../main/kotlin/com/beust/kobalt/api/KobaltContext.kt | 9 ++++++++- .../kotlin/com/beust/kobalt/internal/CompilerUtils.kt | 2 +- .../kotlin/com/beust/kobalt/app/BuildFileCompiler.kt | 5 +++-- .../kotlin/com/beust/kobalt/app/ParsedBuildFile.kt | 2 ++ .../kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt | 2 +- .../com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt | 11 ++++++++--- 6 files changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt index 57939069..b7e5ace8 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt @@ -19,7 +19,6 @@ import java.io.File class KobaltContext(val args: Args) { lateinit var variant: Variant val profiles = arrayListOf() - var forceRecompile: Boolean = false init { args.profiles?.split(',')?.filterNotNull()?.forEach { @@ -106,4 +105,12 @@ class InternalContext { * The absolute directory of the current project. */ var absoluteDir: File? = null + + /** + * If true, will force a recompile of the files even if using the incremental compile + */ + var forceRecompile: Boolean = false + + var noIncrementalKotlin: Boolean = false + } \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt index e17ee4d4..b47fab50 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/CompilerUtils.kt @@ -167,7 +167,7 @@ class CompilerUtils @Inject constructor(val files: KFiles, val dependencyManager // Finally, alter the info with the compiler interceptors before returning it val initialActionInfo = CompilerActionInfo(projectDirectory.path, classpath, allSources, sourceSuffixes, buildDirectory, emptyList() /* the flags will be provided by flag contributors */, - emptyList(), context.forceRecompile) + emptyList(), context.internalContext.forceRecompile) val result = context.pluginInfo.compilerInterceptors.fold(initialActionInfo, { ai, interceptor -> interceptor.intercept(project, context, ai) }) diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index 97f08a0d..730cb304 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -61,7 +61,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil context.resolver = resolver context.pomGeneratorFactory = pomGeneratorFactory context.logger = parallelLogger - context.forceRecompile = forceRecompile + context.internalContext.forceRecompile = forceRecompile Kobalt.context = context // The list of dynamic plug-ins has to be a companion since it's modified directly from @@ -111,7 +111,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil KFiles.saveFile(modifiedBuildFile, parsedBuildFile.buildScriptCode) val taskResult = maybeCompileBuildFile(context, BuildFile(Paths.get(modifiedBuildFile.path), "Modified ${Constants.BUILD_FILE_NAME}", buildFile.realPath), - buildScriptJarFile, pluginUrls, context.forceRecompile) + buildScriptJarFile, pluginUrls, context.internalContext.forceRecompile) if (taskResult.success) { projects.addAll(buildScriptUtil.runBuildScriptJarFile(buildScriptJarFile, pluginUrls, context)) } else { @@ -155,6 +155,7 @@ class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val buildFil classpath(buildFileClasspath) sourceFiles(listOf(buildFile.path.toFile().absolutePath)) output = buildScriptJarFile + noIncrementalKotlin = true }.compile(context = context) diff --git a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt index d4f7e436..8f7d3fe3 100644 --- a/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt +++ b/src/main/kotlin/com/beust/kobalt/app/ParsedBuildFile.kt @@ -138,11 +138,13 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val val kotlinDeps = dependencyManager.calculateDependencies(null, context) val deps: List = kotlinDeps.map { it.jarFile.get().absolutePath } val outputJar = File(buildScriptJarFile.absolutePath) + val saved = context.internalContext.noIncrementalKotlin val result = kotlinCompilePrivate { classpath(files.kobaltJar) classpath(deps) sourceFiles(buildFile.path.toFile().absolutePath) output = outputJar + noIncrementalKotlin = true }.compile(context = context) if (! result.success) { throw KobaltException("Couldn't compile ${originalFile.realPath}:\n" diff --git a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt index 2aa3156d..168027ad 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/apt/AptPlugin.kt @@ -91,7 +91,7 @@ class AptPlugin @Inject constructor(val dependencyManager: DependencyManager, va val dependencies = dependencyManager.calculateDependencies(project, context) val info = CompilerActionInfo(sourceDir.absolutePath, dependencies, listOf(javaFile.absolutePath), listOf("java"), File(sourceDir, "generated"), - listOf(), listOf(), context.forceRecompile) + listOf(), listOf(), context.internalContext.forceRecompile) val results = compilerUtils.invokeCompiler(project, context, javaCompiler, info) } diff --git a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt index 59348d44..4d8a0f85 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/kotlin/KotlinCompiler.kt @@ -223,7 +223,7 @@ class KotlinCompiler @Inject constructor( System.setProperty("kotlin.incremental.compilation.experimental", "true") val result = - if (cliArgs.noIncrementalKotlin) { + if (cliArgs.noIncrementalKotlin || Kobalt.context?.internalContext?.noIncrementalKotlin ?: false) { log(2, " Kotlin incremental compilation is disabled") val duration = benchmarkMillis { K2JVMCompiler().exec(collector, Services.Builder().build(), args) @@ -383,7 +383,7 @@ class KotlinCompiler @Inject constructor( emptyList() } val info = CompilerActionInfo(project?.directory, dependencies, sourceFiles, listOf("kt"), outputDir, args, - friendPaths, context?.forceRecompile ?: false) + friendPaths, context?.internalContext?.forceRecompile ?: false) return jvmCompiler.doCompile(project, context, compilerAction, info, if (context != null) compilerUtils.sourceCompilerFlags(project, context, info) else emptyList()) @@ -396,6 +396,7 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){ var source = arrayListOf() var output: File by Delegates.notNull() val args = arrayListOf() + var noIncrementalKotlin = false fun sourceFiles(s: String) = source.add(s) @@ -408,7 +409,11 @@ class KConfiguration @Inject constructor(val compiler: KotlinCompiler){ fun compilerArgs(s: List) = args.addAll(s) fun compile(project: Project? = null, context: KobaltContext? = null) : TaskResult { - return compiler.compile(project, context, dependencies, classpath, source, output, args) + val saved = context?.internalContext?.noIncrementalKotlin ?: false + if (context != null) context.internalContext.noIncrementalKotlin = noIncrementalKotlin + val result = compiler.compile(project, context, dependencies, classpath, source, output, args) + if (context != null) context.internalContext.noIncrementalKotlin = saved + return result } }