Skip to content

Commit

Permalink
Fix issue #2958 - deduplicate (anonymous) tasks in result (#2959)
Browse files Browse the repository at this point in the history
Anonymous tasks can be defined as `val` or `def`. This is in contrast to
named targets, which always need to be defined as `def`.

Also, anonymous tasks end up in the terminal group of the target that's
using them.

If the same anonymous task is used in multiple targets, it also ends up
multiple time in the task results. When a `Evaluator.Results` is
created, this clashes, due to the use of a `Strict.Agg` for
`Evalutor.Results.evaluated`.

This change deduplicates the results before constructing the
`Evaluator.Results`.

Pull request: #2959
  • Loading branch information
lefou authored Jan 10, 2024
1 parent 554c84f commit 8eb07d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion main/eval/src/mill/eval/EvaluatorCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ private[mill] trait EvaluatorCore extends GroupEvaluator {

EvaluatorCore.Results(
goals.indexed.map(results(_).map(_._1).result),
finishedOptsMap.map(_._2).flatMap(_.toSeq.flatMap(_.newEvaluated)),
// result of flatMap may contain non-distinct entries,
// so we manually clean it up before converting to a `Strict.Agg`
// see https://github.com/com-lihaoyi/mill/issues/2958
Strict.Agg.from(
finishedOptsMap.values.flatMap(_.toSeq.flatMap(_.newEvaluated)).iterator.distinct
),
transitive,
getFailing(sortedGroups, results),
results.map { case (k, v) => (k, v.map(_._1)) }
Expand Down
18 changes: 17 additions & 1 deletion main/eval/test/src/mill/eval/TaskTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package mill.eval

import utest._
import mill.T
import mill.define.Worker
import mill.define.{Module, Worker}
import mill.util.{TestEvaluator, TestUtil}
import utest.framework.TestPath

Expand Down Expand Up @@ -118,6 +118,18 @@ trait TaskTests extends TestSuite {
superBuildTargetOverrideWithInputCount += 1
superBuildTargetOverrideWithInputCount
}

// Reproduction of issue https://github.com/com-lihaoyi/mill/issues/2958
object repro2958 extends Module {
val task1 = T.task { "task1" }
def task2 = T { task1() }
def task3 = T { task1() }
def command() = T.command {
val t2 = task2()
val t3 = task3()
s"${t2},${t3}"
}
}
}

def withEnv(f: (Build, TestEvaluator) => Unit)(implicit tp: TestPath): Unit
Expand Down Expand Up @@ -241,7 +253,11 @@ trait TaskTests extends TestSuite {
check.apply(build.superBuildTargetOverrideWithInput) ==> Right((3, 0))
}
}
"duplicateTaskInResult-issue2958" - withEnv { (build, check) =>
check.apply(build.repro2958.command()) ==> Right(("task1,task1", 3))
}
}

}

object SeqTaskTests extends TaskTests {
Expand Down

0 comments on commit 8eb07d7

Please sign in to comment.