Skip to content

Commit 31d41c0

Browse files
authored
Add selective.resolveChanged to further help debugging selective test execution (#4358)
1 parent 018a64e commit 31d41c0

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

example/fundamentals/out-dir/1-out-files/build.mill

+2-3
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ out/mill-server
243243

244244
> cat out/mill-build/methodCodeHashSignatures.dest/current/spanningInvalidationTree.json
245245
{
246-
"call scala.runtime.BoxesRunTime.boxToInteger(int)java.lang.Integer": {},
247-
"call scala.Predef$#println(java.lang.Object)void": {
246+
...
248247
"def build_.package_$foo$#<init>(build_.package_)void": {
249248
"call build_.package_$foo$!<init>(build_.package_)void": {
250249
"def build_.package_#foo$lzycompute$1()void": {
@@ -254,7 +253,7 @@ out/mill-server
254253
}
255254
}
256255
}
257-
}
256+
...
258257
}
259258

260259
*/

example/large/selective/9-selective-execution/build.mill

+8-1
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,18 @@ Test run bar.BarTests finished: 0 failed, 0 ignored, 1 total, ...
135135
// ```
136136
//
137137
// For a more detailed report of how the changed inputs resulted in the selected tasks
138-
// being chosen, you can also use `selective.resolveTree` to print out the selected tasks
138+
// being chosen, you can also use `selective.resolveChanged` to print out the upstream
139+
// input tasks that Mill found had changed and will cause downstream tasks to be selected,
140+
// or `selective.resolveTree` to print out the selected tasks
139141
// as a JSON tree illustrating the relationships between the invalidated inputs (at the root
140142
// of the tree) and the selected tasks (at the leaves of the tree)
141143
//
142144

143145
/** Usage
144146

147+
> mill selective.resolveChanged __.test
148+
bar.sources
149+
145150
> mill selective.resolveTree __.test
146151
{
147152
"bar.sources": {
@@ -176,6 +181,8 @@ Test run bar.BarTests finished: 0 failed, 0 ignored, 1 total, ...
176181
}
177182
}
178183

184+
185+
179186
*/
180187

181188
// Similarly, if we make a change `qux/`, using selective execution will only run tests

example/package.mill

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ object `package` extends RootModule with Module {
212212
trait ExampleCrossModule extends build.integration.IntegrationTestModule {
213213
// disable scalafix because these example modules don't have sources causing it to misbehave
214214
def testRepoSourceRoot: T[PathRef] = Task.Source(millSourcePath)
215-
def testRepoRoot: T[PathRef] = Task{ testRepoSourceRoot() }
215+
def testRepoRoot: T[PathRef] = Task { testRepoSourceRoot() }
216216

217217
def sources0 = Task.Sources(millSourcePath)
218218
def sources = Task {

main/src/mill/main/SelectiveExecution.scala

+8-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private[mill] object SelectiveExecution {
113113

114114
case class ChangedTasks(
115115
resolved: Seq[NamedTask[_]],
116-
changedRootTasks: Set[Task[_]],
116+
changedRootTasks: Set[NamedTask[_]],
117117
downstreamTasks: Seq[NamedTask[_]],
118118
results: Map[Task[_], Evaluator.TaskResult[Val]]
119119
)
@@ -142,7 +142,7 @@ private[mill] object SelectiveExecution {
142142

143143
ChangedTasks(
144144
tasks,
145-
changedRootTasks,
145+
changedRootTasks.collect { case n: NamedTask[_] => n },
146146
downstreamTasks.collect { case n: NamedTask[_] => n },
147147
results
148148
)
@@ -160,6 +160,12 @@ private[mill] object SelectiveExecution {
160160
}
161161
}
162162

163+
def resolveChanged(evaluator: Evaluator, tasks: Seq[String]): Either[String, Seq[String]] = {
164+
for (changedTasks <- SelectiveExecution.computeChangedTasks(evaluator, tasks)) yield {
165+
changedTasks.changedRootTasks.map(_.ctx.segments.render).toSeq.sorted
166+
}
167+
}
168+
163169
def resolveTree(evaluator: Evaluator, tasks: Seq[String]): Either[String, ujson.Value] = {
164170
for (changedTasks <- SelectiveExecution.computeChangedTasks(evaluator, tasks)) yield {
165171
val taskSet = changedTasks.downstreamTasks.toSet[Task[_]]

main/src/mill/main/SelectiveExecutionModule.scala

+14
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ trait SelectiveExecutionModule extends mill.define.Module {
6262
}
6363
}
6464

65+
/**
66+
* Similar to [[resolve]], but prints the _changed upstream tasks_ rather than
67+
* the _selected downstream tasks_.
68+
*/
69+
def resolveChanged(evaluator: Evaluator, tasks: String*): Command[Seq[String]] =
70+
Task.Command(exclusive = true) {
71+
SelectiveExecution.resolveChanged(evaluator, tasks) match {
72+
case Left(err) => Result.Failure(err)
73+
case Right(success) =>
74+
success.foreach(println)
75+
Result.Success(success)
76+
}
77+
}
78+
6579
/**
6680
* Run after [[prepare]], selectively executes the tasks in [[tasks]] that are
6781
* affected by any changes to the task inputs or task implementations since [[prepare]]

0 commit comments

Comments
 (0)