Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Dec 16, 2024
1 parent 7ecd4a5 commit feefd0b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions main/eval/src/mill/eval/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ trait Evaluator extends AutoCloseable {
def rootModule: BaseModule
def effectiveThreadCount: Int
def outPath: os.Path
def selectiveExecution: Boolean = false
def externalOutPath: os.Path
def pathsResolver: EvaluatorPathsResolver
def methodCodeHashSignatures: Map[String, Int] = Map.empty
Expand Down
9 changes: 6 additions & 3 deletions main/eval/src/mill/eval/EvaluatorImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ private[mill] case class EvaluatorImpl(
val systemExit: Int => Nothing,
val exclusiveSystemStreams: SystemStreams,
protected[eval] val chromeProfileLogger: ChromeProfileLogger,
protected[eval] val profileLogger: ProfileLogger
protected[eval] val profileLogger: ProfileLogger,
override val selectiveExecution: Boolean = false
) extends Evaluator with EvaluatorCore {
import EvaluatorImpl._

Expand Down Expand Up @@ -93,7 +94,8 @@ private[mill] object EvaluatorImpl {
disableCallgraph: Boolean,
allowPositionalCommandArgs: Boolean,
systemExit: Int => Nothing,
exclusiveSystemStreams: SystemStreams
exclusiveSystemStreams: SystemStreams,
selectiveExecution: Boolean
) = new EvaluatorImpl(
home,
workspace,
Expand All @@ -114,7 +116,8 @@ private[mill] object EvaluatorImpl {
systemExit,
exclusiveSystemStreams,
chromeProfileLogger = new ChromeProfileLogger(outPath / millChromeProfile),
profileLogger = new ProfileLogger(outPath / millProfile)
profileLogger = new ProfileLogger(outPath / millProfile),
selectiveExecution = selectiveExecution
)

class EvalOrThrow(evaluator: Evaluator, exceptionFactory: Evaluator.Results => Throwable)
Expand Down
3 changes: 2 additions & 1 deletion main/src/mill/main/MainModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ object MainModule {
RunScript.evaluateTasksNamed(
evaluator.withBaseLogger(redirectLogger),
targets,
Separated
Separated,
selectiveExecution = evaluator.selectiveExecution
) match {
case Left(err) => Result.Failure(err)
case Right((watched, Left(err))) =>
Expand Down
49 changes: 26 additions & 23 deletions main/src/mill/main/RunScript.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,47 @@ object RunScript {
): Either[
String,
(Seq[Watchable], Either[String, Seq[(Any, Option[(TaskName, ujson.Value)])]])
] = {
] = mill.eval.Evaluator.currentEvaluator.withValue(evaluator) {
val enableSelective = selectiveExecution && os.exists(evaluator.outPath / OutFiles.millSelectiveExecution)
val selectedTargetsOrErr =
if (selectiveExecution && os.exists(evaluator.outPath / OutFiles.millSelectiveExecution)) {
if (enableSelective) {
SelectiveExecution.resolve0(evaluator, scriptArgs).map(_.flatMap(Array("+", _)).drop(1))
} else {
Right(scriptArgs.toArray)
}

selectedTargetsOrErr.flatMap { resolvedTaskNames =>
val resolved = mill.eval.Evaluator.currentEvaluator.withValue(evaluator) {
Resolve.Tasks.resolve(
if (enableSelective && resolvedTaskNames.isEmpty) Right((Nil, Right(Nil)))
else {
val resolved = Resolve.Tasks.resolve(
evaluator.rootModule,
resolvedTaskNames,
selectMode,
evaluator.allowPositionalCommandArgs
)
}

resolved.map { t =>
val evaluated = evaluateNamed0(evaluator, Agg.from(t))
if (selectiveExecution) {
for (res <- evaluated._2) {
val (results, terminals, _) = res
val allInputHashes = results
.iterator
.collect {
case (t: InputImpl[_], TaskResult(Result.Success(Val(value)), _)) =>
(terminals(t).render, value.##)
}
.toMap
SelectiveExecution.saveMetadata(
evaluator,
SelectiveExecution.Metadata(allInputHashes, evaluator.methodCodeHashSignatures)
)

resolved.map { t =>
val evaluated = evaluateNamed0(evaluator, Agg.from(t))
if (selectiveExecution) {
for (res <- evaluated._2) {
val (results, terminals, _) = res
val allInputHashes = results
.iterator
.collect {
case (t: InputImpl[_], TaskResult(Result.Success(Val(value)), _)) =>
(terminals(t).render, value.##)
}
.toMap
SelectiveExecution.saveMetadata(
evaluator,
SelectiveExecution.Metadata(allInputHashes, evaluator.methodCodeHashSignatures)
)
}
}
val (ws, either) = evaluated
(ws, either.map { case (r, t, v) => v })
}
val (ws, either) = evaluated
(ws, either.map { case (r, t, v) => v })
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion runner/src/mill/runner/MillBuildBootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ class MillBuildBootstrap(
disableCallgraph = disableCallgraph,
allowPositionalCommandArgs = allowPositionalCommandArgs,
systemExit = systemExit,
exclusiveSystemStreams = streams0
exclusiveSystemStreams = streams0,
selectiveExecution = selectiveExecution
)
}

Expand Down
3 changes: 2 additions & 1 deletion testkit/src/mill/testkit/UnitTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class UnitTester(
disableCallgraph = false,
allowPositionalCommandArgs = false,
systemExit = i => ???,
exclusiveSystemStreams = new SystemStreams(outStream, errStream, inStream)
exclusiveSystemStreams = new SystemStreams(outStream, errStream, inStream),
selectiveExecution = false
)

def apply(args: String*): Either[Result.Failing[_], UnitTester.Result[Seq[_]]] = {
Expand Down

0 comments on commit feefd0b

Please sign in to comment.