Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Oct 11, 2024
1 parent 365635e commit cc5c735
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
4 changes: 4 additions & 0 deletions main/eval/src/mill/eval/EvaluatorImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ private[mill] case class EvaluatorImpl(
override def evalOrThrow(exceptionFactory: Evaluator.Results => Throwable)
: Evaluator.EvalOrThrow =
new EvalOrThrow(this, exceptionFactory)

override def withEvaluator[T](t: => T): T = {
mill.eval.Evaluator.currentEvaluator.withValue(this) { t }
}
}

private[mill] object EvaluatorImpl {
Expand Down
8 changes: 5 additions & 3 deletions main/eval/src/mill/eval/GroupEvaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import scala.util.hashing.MurmurHash3
* with a single [[Terminal]].
*/
private[mill] trait GroupEvaluator {
def withEvaluator[T](t: => T): T
def home: os.Path
def workspace: os.Path
def outPath: os.Path
Expand Down Expand Up @@ -296,10 +297,11 @@ private[mill] trait GroupEvaluator {

os.dynamicPwdFunction.withValue(destFunc) {
SystemStreams.withStreams(streams) {
if (exclusive) {
if (!exclusive) t
else {
logger.reportKey(Seq(counterMsg))
logger.withPromptPaused { t }
} else t
withEvaluator { logger.withPromptPaused { t } }
}
}
}
}
Expand Down
15 changes: 7 additions & 8 deletions main/src/mill/main/RunScript.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ object RunScript {
String,
(Seq[Watchable], Either[String, Seq[(Any, Option[(TaskName, ujson.Value)])]])
] = {
val resolved = mill.eval.Evaluator.currentEvaluator.withValue(evaluator) {
Resolve.Tasks.resolve(
evaluator.rootModule,
scriptArgs,
selectMode,
evaluator.allowPositionalCommandArgs
)
}
val resolved = Resolve.Tasks.resolve(
evaluator.rootModule,
scriptArgs,
selectMode,
evaluator.allowPositionalCommandArgs
)

for (targets <- resolved) yield evaluateNamed(evaluator, Agg.from(targets))
}

Expand Down
4 changes: 1 addition & 3 deletions testkit/src/mill/testkit/UnitTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ class UnitTester(
)

def apply(args: String*): Either[Result.Failing[_], UnitTester.Result[Seq[_]]] = {
mill.eval.Evaluator.currentEvaluator.withValue(evaluator) {
Resolve.Tasks.resolve(evaluator.rootModule, args, SelectMode.Separated)
} match {
Resolve.Tasks.resolve(evaluator.rootModule, args, SelectMode.Separated) match {
case Left(err) => Left(Result.Failure(err))
case Right(resolved) => apply(resolved)
}
Expand Down

0 comments on commit cc5c735

Please sign in to comment.