mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Incremental compilations.
This commit is contained in:
parent
cb1aaf6a75
commit
267fa4c12d
5 changed files with 74 additions and 8 deletions
|
@ -10,4 +10,4 @@ import com.beust.kobalt.api.Project
|
|||
* if they differ, the task gets run.
|
||||
* @param task The task to run.
|
||||
*/
|
||||
class IncrementalTaskInfo(val inputChecksum: String, val outputChecksum: String?, val task: (Project) -> TaskResult)
|
||||
class IncrementalTaskInfo(val inputChecksum: String?, val outputChecksum: String?, val task: (Project) -> TaskResult)
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.Features
|
||||
import com.beust.kobalt.IncrementalTaskInfo
|
||||
import com.beust.kobalt.KobaltException
|
||||
import com.beust.kobalt.TaskResult
|
||||
import com.beust.kobalt.api.*
|
||||
import com.beust.kobalt.api.annotation.ExportedProjectProperty
|
||||
import com.beust.kobalt.api.annotation.IncrementalTask
|
||||
import com.beust.kobalt.api.annotation.Task
|
||||
import com.beust.kobalt.maven.DepFactory
|
||||
import com.beust.kobalt.maven.DependencyManager
|
||||
import com.beust.kobalt.maven.LocalRepo
|
||||
import com.beust.kobalt.maven.Md5
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import com.beust.kobalt.misc.KobaltExecutors
|
||||
import com.beust.kobalt.misc.log
|
||||
|
@ -61,7 +64,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
override fun apply(project: Project, context: KobaltContext) {
|
||||
super.apply(project, context)
|
||||
project.projectProperties.put(DEPENDENT_PROJECTS, projects())
|
||||
taskContributor.addVariantTasks(this, project, context, "compile", runTask = { taskCompile(project) })
|
||||
taskContributor.addVariantTasks(this, project, context, "compile", runTask = { doTaskCompile(project) })
|
||||
}
|
||||
|
||||
@Task(name = TASK_TEST, description = "Run the tests",
|
||||
|
@ -164,8 +167,19 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
|||
return false
|
||||
}
|
||||
|
||||
@Task(name = JvmCompilerPlugin.TASK_COMPILE, description = "Compile the project")
|
||||
fun taskCompile(project: Project) : TaskResult {
|
||||
@IncrementalTask(name = JvmCompilerPlugin.TASK_COMPILE, description = "Compile the project")
|
||||
fun taskCompile(project: Project) : IncrementalTaskInfo {
|
||||
val inputChecksum = Md5.toMd5Directories(project.sourceDirectories.map {
|
||||
File(project.directory, it)
|
||||
})
|
||||
return IncrementalTaskInfo(
|
||||
inputChecksum = inputChecksum,
|
||||
outputChecksum = "1",
|
||||
task = { project -> doTaskCompile(project) }
|
||||
)
|
||||
}
|
||||
|
||||
private fun doTaskCompile(project: Project) : TaskResult {
|
||||
// Set up the source files now that we have the variant
|
||||
sourceDirectories.addAll(context.variant.sourceDirectories(project))
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import javax.inject.Inject
|
|||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
public class TaskManager @Inject constructor(val args: Args) {
|
||||
public class TaskManager @Inject constructor(val args: Args, val incrementalManager: IncrementalManager) {
|
||||
private val runBefore = TreeMultimap.create<String, String>()
|
||||
private val alwaysRunAfter = TreeMultimap.create<String, String>()
|
||||
|
||||
|
@ -248,7 +248,40 @@ public class TaskManager @Inject constructor(val args: Args) {
|
|||
{ project ->
|
||||
val iit = method.invoke(plugin, project) as IncrementalTaskInfo
|
||||
// TODO: compare the checksums with the previous run
|
||||
iit.task(project)
|
||||
val taskName = project.name + ":" + ta.name
|
||||
var upToDate = false
|
||||
incrementalManager.inputChecksumFor(taskName)?.let { inputChecksum ->
|
||||
if (inputChecksum == iit.inputChecksum) {
|
||||
incrementalManager.outputChecksumFor(taskName)?.let { outputChecksum ->
|
||||
if (outputChecksum == iit.outputChecksum) {
|
||||
upToDate = true
|
||||
} else {
|
||||
log(2, " INC- Incremental task ${ta.name} output is out of date, running it")
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log(2, " INC- Incremental task ${ta.name} input is out of date, running it")
|
||||
}
|
||||
}
|
||||
if (! upToDate) {
|
||||
val result = iit.task(project)
|
||||
if (result.success) {
|
||||
log(2, " INC- Incremental task ${ta.name} done running, saving checksums")
|
||||
iit.inputChecksum?.let {
|
||||
incrementalManager.saveInputChecksum(taskName, it)
|
||||
log(2, " INC- input $it saved")
|
||||
}
|
||||
iit.outputChecksum?.let {
|
||||
incrementalManager.saveOutputChecksum(taskName, it)
|
||||
log(2, " INC- output $it saved")
|
||||
}
|
||||
}
|
||||
result
|
||||
} else {
|
||||
log(2, " INC- Incremental task ${ta.name} is up to date, not running it")
|
||||
TaskResult()
|
||||
}
|
||||
})
|
||||
|
||||
class PluginDynamicTask(val plugin: IPlugin, val task: DynamicTask)
|
||||
|
@ -334,7 +367,7 @@ class TaskWorker(val tasks: List<PluginTask>, val dryRun: Boolean) : IWorker<Plu
|
|||
override fun call() : TaskResult2<PluginTask> {
|
||||
if (tasks.size > 0) {
|
||||
tasks[0].let {
|
||||
log(1, AsciiArt.taskColor(AsciiArt.horizontalSingleLine + " ${it.project.name}:${it.name}"))
|
||||
log(2, AsciiArt.taskColor(AsciiArt.horizontalSingleLine + " ${it.project.name}:${it.name}"))
|
||||
}
|
||||
}
|
||||
var success = true
|
||||
|
|
|
@ -1,11 +1,29 @@
|
|||
package com.beust.kobalt.maven
|
||||
|
||||
import com.beust.kobalt.misc.KFiles
|
||||
import java.io.File
|
||||
import java.security.MessageDigest
|
||||
import javax.xml.bind.DatatypeConverter
|
||||
|
||||
public class Md5 {
|
||||
companion object {
|
||||
fun toMd5Directories(directories: List<File>) : String {
|
||||
MessageDigest.getInstance("MD5").let { md5 ->
|
||||
directories.forEach { file ->
|
||||
KFiles.findRecursively(file).map {
|
||||
File(file, it)
|
||||
}.filter {
|
||||
it.isFile
|
||||
}.forEach {
|
||||
val bytes = it.readBytes()
|
||||
md5.update(bytes, 0, bytes.size)
|
||||
}
|
||||
}
|
||||
val result = DatatypeConverter.printHexBinary(md5.digest()).toLowerCase()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun toMd5(file: File) = MessageDigest.getInstance("MD5").let { md5 ->
|
||||
file.forEachBlock { bytes, size ->
|
||||
md5.update(bytes, 0, size)
|
||||
|
@ -14,3 +32,4 @@ public class Md5 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class KFiles {
|
|||
}
|
||||
|
||||
companion object {
|
||||
private const val KOBALT_DOT_DIR : String = ".kobalt"
|
||||
internal const val KOBALT_DOT_DIR : String = ".kobalt"
|
||||
const val KOBALT_DIR : String = "kobalt"
|
||||
const val KOBALT_BUILD_DIR = "kobaltBuild"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue