mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Introduced --noIncremental.
This commit is contained in:
parent
1ae9baa97d
commit
a9455c92f6
3 changed files with 46 additions and 30 deletions
|
@ -41,6 +41,9 @@ class Args {
|
||||||
@Parameter(names = arrayOf("--log"), description = "Define the log level (1-3)")
|
@Parameter(names = arrayOf("--log"), description = "Define the log level (1-3)")
|
||||||
var log: Int = 1
|
var log: Int = 1
|
||||||
|
|
||||||
|
@Parameter(names = arrayOf("--noIncremental"), description = "Turn off incremental builds")
|
||||||
|
var noIncremental: Boolean = false
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val DEFAULT_SERVER_PORT = 1234
|
const val DEFAULT_SERVER_PORT = 1234
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.IncrementalTaskInfo
|
import com.beust.kobalt.IncrementalTaskInfo
|
||||||
import com.beust.kobalt.TaskResult
|
import com.beust.kobalt.TaskResult
|
||||||
import com.beust.kobalt.Variant
|
import com.beust.kobalt.Variant
|
||||||
|
@ -9,6 +10,8 @@ import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.GsonBuilder
|
import com.google.gson.GsonBuilder
|
||||||
|
import com.google.inject.Inject
|
||||||
|
import com.google.inject.Singleton
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileReader
|
import java.io.FileReader
|
||||||
import java.nio.charset.Charset
|
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>)
|
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.
|
* 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 {
|
companion object {
|
||||||
val BUILD_INFO_FILE = KFiles.joinDir(KFiles.KOBALT_DOT_DIR, "buildInfo.json")
|
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 upToDate = false
|
||||||
var taskOutputChecksum : String? = null
|
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")
|
logIncremental(LEVEL, "Previous incremental task was a success, not running $shortTaskName")
|
||||||
TaskResult()
|
upToDate = true
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// First, compare the input checksums
|
// First, compare the input checksums
|
||||||
|
@ -119,33 +131,33 @@ class IncrementalManager(val fileName: String = IncrementalManager.BUILD_INFO_FI
|
||||||
project.projectExtra.isDirty = true
|
project.projectExtra.isDirty = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!upToDate) {
|
if (!upToDate) {
|
||||||
//
|
//
|
||||||
// The task is out of date, invoke the task on the IncrementalTaskInfo object
|
// The task is out of date, invoke the task on the IncrementalTaskInfo object
|
||||||
//
|
//
|
||||||
val result = iti.task(project)
|
val result = iti.task(project)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
logIncremental(LEVEL, "Incremental task $taskName done running, saving checksums")
|
logIncremental(LEVEL, "Incremental task $taskName done running, saving checksums")
|
||||||
iti.inputChecksum()?.let {
|
iti.inputChecksum()?.let {
|
||||||
saveInputChecksum(taskName, it)
|
saveInputChecksum(taskName, it)
|
||||||
logIncremental(LEVEL, " input checksum \"$it\" saved")
|
logIncremental(LEVEL, " input checksum \"$it\" saved")
|
||||||
}
|
}
|
||||||
// Important to rerun the checksum here since the output of the task might have changed it
|
// Important to rerun the checksum here since the output of the task might have changed it
|
||||||
iti.outputChecksum()?.let {
|
iti.outputChecksum()?.let {
|
||||||
saveOutputChecksum(taskName, it)
|
saveOutputChecksum(taskName, it)
|
||||||
logIncremental(LEVEL, " output checksum \"$it\" saved")
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
|
import com.beust.kobalt.Args
|
||||||
import org.testng.Assert
|
import org.testng.Assert
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -12,7 +13,7 @@ class IncrementalManagerTest {
|
||||||
fun shouldSave() {
|
fun shouldSave() {
|
||||||
val file = File.createTempFile("kobalt-", "")
|
val file = File.createTempFile("kobalt-", "")
|
||||||
println("File: $file")
|
println("File: $file")
|
||||||
val im = IncrementalManager(file.absolutePath)
|
val im = IncrementalManager(Args())//, file.absolutePath)
|
||||||
val v = im.inputChecksumFor(TASK)
|
val v = im.inputChecksumFor(TASK)
|
||||||
Assert.assertNull(v)
|
Assert.assertNull(v)
|
||||||
im.saveInputChecksum(TASK, "44")
|
im.saveInputChecksum(TASK, "44")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue