diff --git a/contrib/scoverage/src/ScoverageReport.scala b/contrib/scoverage/src/ScoverageReport.scala index fb85ec88cd1..c852c915368 100644 --- a/contrib/scoverage/src/ScoverageReport.scala +++ b/contrib/scoverage/src/ScoverageReport.scala @@ -4,6 +4,7 @@ import mill.contrib.scoverage.api.ScoverageReportWorkerApi.ReportType import mill.define.{Command, Module, Task} import mill.eval.Evaluator import mill.main.RunScript +import mill.util.SelectMode import mill.{PathRef, T} import os.Path @@ -84,7 +85,7 @@ trait ScoverageReport extends Module { mill.main.ResolveTasks, evaluator, Seq(sources), - multiSelect = false + SelectMode.Single ) match { case Left(err) => throw new Exception(err) case Right(tasks) => tasks.asInstanceOf[Seq[Task[Seq[PathRef]]]] @@ -93,7 +94,7 @@ trait ScoverageReport extends Module { mill.main.ResolveTasks, evaluator, Seq(dataTargets), - multiSelect = false + SelectMode.Single ) match { case Left(err) => throw new Exception(err) case Right(tasks) => tasks.asInstanceOf[Seq[Task[PathRef]]] diff --git a/main/src/mill/main/MainModule.scala b/main/src/mill/main/MainModule.scala index 59671f6bb03..e907f0b69ea 100644 --- a/main/src/mill/main/MainModule.scala +++ b/main/src/mill/main/MainModule.scala @@ -6,27 +6,51 @@ import mill.T import mill.api.{Ctx, PathRef, Result} import mill.define.{Command, NamedTask, Task} import mill.eval.Evaluator -import mill.util.{PrintLogger, Watched} +import mill.util.SelectMode.Multi +import mill.util.{PrintLogger, SelectMode, Watched} import os.Path import pprint.{Renderer, Truncated} object MainModule { + @deprecated( + "use resolveTasks(Evaluator, Seq[String], SelectMode) instead", + "mill after 0.10.0-M3" + ) def resolveTasks[T]( evaluator: Evaluator, targets: Seq[String], multiSelect: Boolean - )(f: List[NamedTask[Any]] => T) = { - RunScript.resolveTasks(mill.main.ResolveTasks, evaluator, targets, multiSelect) match { + )(f: List[NamedTask[Any]] => T): Result[T] = + resolveTasks(evaluator, targets, if (multiSelect) SelectMode.Multi else SelectMode.Single)(f) + + def resolveTasks[T]( + evaluator: Evaluator, + targets: Seq[String], + selectMode: SelectMode + )(f: List[NamedTask[Any]] => T): Result[T] = { + RunScript.resolveTasks(mill.main.ResolveTasks, evaluator, targets, selectMode) match { case Left(err) => Result.Failure(err) case Right(tasks) => Result.Success(f(tasks)) } } + + @deprecated( + "use evaluateTasks(Evaluator, Seq[String], SelectMode) instead", + "mill after 0.10.0-M3" + ) def evaluateTasks[T]( evaluator: Evaluator, targets: Seq[String], multiSelect: Boolean - )(f: Seq[(Any, Option[ujson.Value])] => T) = { - RunScript.evaluateTasks(evaluator, targets, multiSelect) match { + )(f: Seq[(Any, Option[ujson.Value])] => T): Result[Watched[Unit]] = + evaluateTasks(evaluator, targets, if (multiSelect) SelectMode.Multi else SelectMode.Single)(f) + + def evaluateTasks[T]( + evaluator: Evaluator, + targets: Seq[String], + selectMode: SelectMode + )(f: Seq[(Any, Option[ujson.Value])] => T): Result[Watched[Unit]] = { + RunScript.evaluateTasks(evaluator, targets, selectMode) match { case Left(err) => Result.Failure(err) case Right((watched, Left(err))) => Result.Failure(err, Some(Watched((), watched))) case Right((watched, Right(res))) => @@ -61,7 +85,7 @@ trait MainModule extends mill.Module { mill.main.ResolveMetadata, evaluator, targets, - multiSelect = true + SelectMode.Multi ) resolved match { @@ -91,7 +115,7 @@ trait MainModule extends mill.Module { mill.main.ResolveTasks, evaluator, targets, - multiSelect = true + SelectMode.Multi ) match { case Left(err) => Left(err) case Right(rs) => @@ -111,7 +135,7 @@ trait MainModule extends mill.Module { mill.main.ResolveTasks, evaluator, List(src, dest), - multiSelect = true + SelectMode.Multi ) resolved match { @@ -151,7 +175,7 @@ trait MainModule extends mill.Module { * Displays metadata about the given task without actually running it. */ def inspect(evaluator: Evaluator, targets: String*): Command[String] = mill.T.command { - MainModule.resolveTasks(evaluator, targets, multiSelect = true) { tasks => + MainModule.resolveTasks(evaluator, targets, SelectMode.Multi) { tasks => val output = new StringBuilder for { task <- tasks @@ -184,7 +208,7 @@ trait MainModule extends mill.Module { if (evaluator.effectiveThreadCount > 1) evaluator.copy(threadCount = Some(1)) else evaluator, targets = targets, - multiSelect = true + SelectMode.Multi ) { res => res.flatMap(_._2) } @@ -197,7 +221,7 @@ trait MainModule extends mill.Module { MainModule.evaluateTasks( evaluator = evaluator, targets = targets, - multiSelect = true + SelectMode.Multi ) { res => res.flatMap(_._2) } @@ -219,7 +243,7 @@ trait MainModule extends mill.Module { } ), targets, - multiSelect = false + SelectMode.Separated ) { res => for (json <- res.flatMap(_._2)) { T.log.outputStream.println(json.render(indent = 4)) @@ -255,7 +279,7 @@ trait MainModule extends mill.Module { mill.main.ResolveSegments, evaluator, targets, - multiSelect = true + SelectMode.Multi ).map( _.map { segments => Evaluator.resolveDestPaths(rootDir, segments).out @@ -328,7 +352,7 @@ trait MainModule extends mill.Module { mill.main.ResolveTasks, evaluator, targets, - multiSelect = true + SelectMode.Multi ) match { case Left(err) => Result.Failure(err) case Right(rs) => planTasks match { diff --git a/main/src/mill/main/MainScopts.scala b/main/src/mill/main/MainScopts.scala index 6a017bed045..7d83331b6f8 100644 --- a/main/src/mill/main/MainScopts.scala +++ b/main/src/mill/main/MainScopts.scala @@ -1,6 +1,7 @@ package mill.main import mill.eval.Evaluator +import mill.util.SelectMode case class Tasks[T](value: Seq[mill.define.NamedTask[T]]) @@ -14,7 +15,7 @@ object Tasks { mill.main.ResolveTasks, Evaluator.currentEvaluator.get, s, - multiSelect = false + SelectMode.Single ).map(x => Tasks(x.asInstanceOf[Seq[mill.define.NamedTask[T]]])), alwaysRepeatable = false, allowEmpty = false