mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Accidentally submitted the sequential runner in the parallel one.
This commit is contained in:
parent
94db51b569
commit
05b45e4f23
1 changed files with 52 additions and 64 deletions
|
@ -1,15 +1,13 @@
|
||||||
package com.beust.kobalt.internal
|
package com.beust.kobalt.internal
|
||||||
|
|
||||||
import com.beust.kobalt.Args
|
import com.beust.kobalt.Args
|
||||||
import com.beust.kobalt.AsciiArt
|
|
||||||
import com.beust.kobalt.TaskResult
|
import com.beust.kobalt.TaskResult
|
||||||
import com.beust.kobalt.api.*
|
import com.beust.kobalt.api.ITask
|
||||||
import com.beust.kobalt.misc.Strings
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.misc.kobaltError
|
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.google.common.collect.ListMultimap
|
import com.google.common.collect.ListMultimap
|
||||||
import com.google.common.collect.TreeMultimap
|
import com.google.common.collect.TreeMultimap
|
||||||
import java.util.*
|
import java.util.concurrent.Callable
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the projects in parallel.
|
* Build the projects in parallel.
|
||||||
|
@ -25,78 +23,68 @@ class ParallelProjectRunner(val tasksByNames: (Project) -> ListMultimap<String,
|
||||||
: BaseProjectRunner() {
|
: BaseProjectRunner() {
|
||||||
override fun runProjects(taskInfos: List<TaskManager.TaskInfo>, projects: List<Project>)
|
override fun runProjects(taskInfos: List<TaskManager.TaskInfo>, projects: List<Project>)
|
||||||
: TaskManager .RunTargetResult {
|
: TaskManager .RunTargetResult {
|
||||||
var result = TaskResult()
|
class ProjectTask(val project: Project, val dryRun: Boolean) : Callable<TaskResult2<ProjectTask>> {
|
||||||
val failedProjects = hashSetOf<String>()
|
override fun toString() = "[ProjectTask " + project.name + "]"
|
||||||
val messages = Collections.synchronizedList(arrayListOf<TaskManager.ProfilerInfo>())
|
override fun hashCode() = project.hashCode()
|
||||||
|
override fun equals(other: Any?) : Boolean =
|
||||||
|
if (other is ProjectTask) other.project.name == project.name
|
||||||
|
else false
|
||||||
|
|
||||||
fun runProjectListeners(project: Project, context: KobaltContext, start: Boolean,
|
override fun call(): TaskResult2<ProjectTask> {
|
||||||
status: ProjectBuildStatus = ProjectBuildStatus.SUCCESS) {
|
|
||||||
context.pluginInfo.buildListeners.forEach {
|
|
||||||
if (start) it.projectStart(project, context) else it.projectEnd(project, context, status)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val context = Kobalt.context!!
|
|
||||||
projects.forEach { project ->
|
|
||||||
AsciiArt.logBox("Building ${project.name}")
|
|
||||||
|
|
||||||
// Does the current project depend on any failed projects?
|
|
||||||
val fp = project.dependsOn.filter {
|
|
||||||
failedProjects.contains(it.name)
|
|
||||||
}.map {
|
|
||||||
it.name
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fp.size > 0) {
|
|
||||||
log(2, "Marking project ${project.name} as skipped")
|
|
||||||
failedProjects.add(project.name)
|
|
||||||
runProjectListeners(project, context, false, ProjectBuildStatus.SKIPPED)
|
|
||||||
kobaltError("Not building project ${project.name} since it depends on failed "
|
|
||||||
+ Strings.pluralize(fp.size, "project")
|
|
||||||
+ " " + fp.joinToString(","))
|
|
||||||
} else {
|
|
||||||
runProjectListeners(project, context, true)
|
|
||||||
|
|
||||||
// There can be multiple tasks by the same name (e.g. PackagingPlugin and AndroidPlugin both
|
|
||||||
// define "install"), so use a multimap
|
|
||||||
val tasksByNames = tasksByNames(project)
|
val tasksByNames = tasksByNames(project)
|
||||||
|
|
||||||
log(3, "Tasks:")
|
|
||||||
tasksByNames.keys().forEach {
|
|
||||||
log(3, " $it: " + tasksByNames.get(it))
|
|
||||||
}
|
|
||||||
|
|
||||||
val graph = createTaskGraph(project.name, taskInfos, tasksByNames,
|
val graph = createTaskGraph(project.name, taskInfos, tasksByNames,
|
||||||
dependsOn, reverseDependsOn, runBefore, runAfter, alwaysRunAfter,
|
dependsOn, reverseDependsOn, runBefore, runAfter, alwaysRunAfter,
|
||||||
{ task: ITask -> task.name },
|
{ task: ITask -> task.name },
|
||||||
{ task: ITask -> task.plugin.accept(project) })
|
{ task: ITask -> task.plugin.accept(project) })
|
||||||
|
var lastResult = TaskResult()
|
||||||
//
|
while (graph.freeNodes.any()) {
|
||||||
// Now that we have a full graph, run it
|
val toProcess = graph.freeNodes
|
||||||
//
|
toProcess.forEach { node ->
|
||||||
log(2, "About to run graph:\n ${graph.dump()} ")
|
val tasks = tasksByNames[node.name]
|
||||||
|
tasks.forEach { task ->
|
||||||
val factory = object : IThreadWorkerFactory<ITask> {
|
log(1, "===== " + project.name + ":" + task.name)
|
||||||
override fun createWorkers(nodes: Collection<ITask>)
|
val tr = if (dryRun) TaskResult2(true, null, task) else task.call()
|
||||||
= nodes.map { TaskWorker(listOf(it), args.dryRun, pluginInfo) }
|
if (lastResult.success) {
|
||||||
|
lastResult = tr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
graph.freeNodes.forEach { graph.removeNode(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val executor = DynamicGraphExecutor(graph, factory, 5)
|
return TaskResult2(lastResult.success, lastResult.errorMessage, this)
|
||||||
val thisResult = executor.run()
|
}
|
||||||
if (! thisResult.success) {
|
|
||||||
log(2, "Marking project ${project.name} as failed")
|
}
|
||||||
failedProjects.add(project.name)
|
|
||||||
|
val factory = object : IThreadWorkerFactory<ProjectTask> {
|
||||||
|
override fun createWorkers(nodes: Collection<ProjectTask>): List<IWorker<ProjectTask>> {
|
||||||
|
val result = nodes.map { it ->
|
||||||
|
object: IWorker<ProjectTask> {
|
||||||
|
override val priority: Int
|
||||||
|
get() = 0
|
||||||
|
|
||||||
|
override fun call(): TaskResult2<ProjectTask> {
|
||||||
|
val tr = it.call()
|
||||||
|
return tr
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
runProjectListeners(project, context, false,
|
val projectGraph = DynamicGraph<ProjectTask>().apply {
|
||||||
if (thisResult.success) ProjectBuildStatus.SUCCESS else ProjectBuildStatus.FAILED)
|
projects.forEach { project ->
|
||||||
|
project.dependsOn.forEach {
|
||||||
if (result.success) {
|
addEdge(ProjectTask(project, args.dryRun), ProjectTask(it, args.dryRun))
|
||||||
result = thisResult
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TaskManager.RunTargetResult(result, messages)
|
val taskResult = DynamicGraphExecutor(projectGraph, factory, 5).run()
|
||||||
|
|
||||||
|
return TaskManager.RunTargetResult(taskResult, emptyList())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue