1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-25 07:57:12 -07:00

Always compile the build files with Kotlin incremental compilation disabled.

This commit is contained in:
Cedric Beust 2017-03-10 12:39:44 -08:00
parent 187593b9b1
commit 1f3f666d93
6 changed files with 23 additions and 8 deletions

View file

@ -19,7 +19,6 @@ import java.io.File
class KobaltContext(val args: Args) {
lateinit var variant: Variant
val profiles = arrayListOf<String>()
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
}

View file

@ -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)
})

View file

@ -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)

View file

@ -138,11 +138,13 @@ class ParsedBuildFile(val buildFile: BuildFile, val context: KobaltContext, val
val kotlinDeps = dependencyManager.calculateDependencies(null, context)
val deps: List<String> = 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"

View file

@ -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)
}

View file

@ -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<String>()
}
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<String>()
var output: File by Delegates.notNull()
val args = arrayListOf<String>()
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<String>) = 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
}
}