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

Introduced --noIncremental.

This commit is contained in:
Cedric Beust 2016-03-31 23:17:59 -08:00
parent 1ae9baa97d
commit a9455c92f6
3 changed files with 46 additions and 30 deletions

View file

@ -41,6 +41,9 @@ class Args {
@Parameter(names = arrayOf("--log"), description = "Define the log level (1-3)")
var log: Int = 1
@Parameter(names = arrayOf("--noIncremental"), description = "Turn off incremental builds")
var noIncremental: Boolean = false
companion object {
const val DEFAULT_SERVER_PORT = 1234
}

View file

@ -1,5 +1,6 @@
package com.beust.kobalt.internal
import com.beust.kobalt.Args
import com.beust.kobalt.IncrementalTaskInfo
import com.beust.kobalt.TaskResult
import com.beust.kobalt.Variant
@ -9,6 +10,8 @@ import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.inject.Inject
import com.google.inject.Singleton
import java.io.File
import java.io.FileReader
import java.nio.charset.Charset
@ -21,10 +24,13 @@ data class TaskInfo(val taskName: String, var inputChecksum: String? = null, var
class BuildInfo(var tasks: List<TaskInfo>)
/**
* Manage the file .kobalt/build-info.kt, which keeps track of input and output checksums to manage
* Manage the file .kobalt/buildInfo.json, which keeps track of input and output checksums to manage
* incremental builds.
*/
class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FILE) {
@Singleton
class IncrementalManager @Inject constructor(val args: Args) {
val fileName = IncrementalManager.BUILD_INFO_FILE
companion object {
val BUILD_INFO_FILE = KFiles.joinDir(KFiles.KOBALT_DOT_DIR, "buildInfo.json")
}
@ -85,12 +91,18 @@ class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FI
var upToDate = false
var taskOutputChecksum : String? = null
if (iti.context.previousTaskWasIncrementalSuccess(project.name)) {
if (args.noIncremental) {
//
// If the previous task was an incremental success, no need to run
// If the user turned off incremental builds, always run this task
//
logIncremental(LEVEL, "Incremental builds are turned off, running $taskName")
upToDate = false
} else if (iti.context.previousTaskWasIncrementalSuccess(project.name)) {
//
// If the previous task was an incremental success, no need to run this task
//
logIncremental(LEVEL, "Previous incremental task was a success, not running $shortTaskName")
TaskResult()
upToDate = true
} else {
//
// First, compare the input checksums
@ -119,33 +131,33 @@ class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FI
project.projectExtra.isDirty = true
}
}
}
if (!upToDate) {
//
// The task is out of date, invoke the task on the IncrementalTaskInfo object
//
val result = iti.task(project)
if (result.success) {
logIncremental(LEVEL, "Incremental task $taskName done running, saving checksums")
iti.inputChecksum()?.let {
saveInputChecksum(taskName, it)
logIncremental(LEVEL, " input checksum \"$it\" saved")
}
// Important to rerun the checksum here since the output of the task might have changed it
iti.outputChecksum()?.let {
saveOutputChecksum(taskName, it)
logIncremental(LEVEL, " output checksum \"$it\" saved")
}
if (!upToDate) {
//
// The task is out of date, invoke the task on the IncrementalTaskInfo object
//
val result = iti.task(project)
if (result.success) {
logIncremental(LEVEL, "Incremental task $taskName done running, saving checksums")
iti.inputChecksum()?.let {
saveInputChecksum(taskName, it)
logIncremental(LEVEL, " input checksum \"$it\" saved")
}
// Important to rerun the checksum here since the output of the task might have changed it
iti.outputChecksum()?.let {
saveOutputChecksum(taskName, it)
logIncremental(LEVEL, " output checksum \"$it\" saved")
}
result
} else {
//
// Identical input and output checksums, don't run the task
//
logIncremental(LEVEL, "Incremental task \"$taskName\" is up to date, not running it")
iti.context.setIncrementalSuccess(project.name)
TaskResult()
}
result
} else {
//
// Identical input and output checksums, don't run the task
//
logIncremental(LEVEL, "Incremental task \"$taskName\" is up to date, not running it")
iti.context.setIncrementalSuccess(project.name)
TaskResult()
}
}
}

View file

@ -1,5 +1,6 @@
package com.beust.kobalt.internal
import com.beust.kobalt.Args
import org.testng.Assert
import org.testng.annotations.Test
import java.io.File
@ -12,7 +13,7 @@ class IncrementalManagerTest {
fun shouldSave() {
val file = File.createTempFile("kobalt-", "")
println("File: $file")
val im = IncrementalManager(file.absolutePath)
val im = IncrementalManager(Args())//, file.absolutePath)
val v = im.inputChecksumFor(TASK)
Assert.assertNull(v)
im.saveInputChecksum(TASK, "44")