Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Sep 26, 2024
1 parent c4df445 commit c987d9e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 22 deletions.
6 changes: 6 additions & 0 deletions main/eval/src/mill/eval/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import mill.api.{CompileProblemReporter, DummyTestReporter, Result, TestReporter
import mill.api.Strict.Agg
import mill.define.{BaseModule, Segments, Task}
import mill.eval.Evaluator.{Results, formatFailing}
import mill.main.client.lock.Lock
import mill.util.{ColorLogger, MultiBiMap}

import scala.annotation.nowarn
Expand Down Expand Up @@ -31,6 +32,11 @@ trait Evaluator {
}
def disableCallgraphInvalidation: Boolean = false

def outPathLockOpt: Option[Lock]
def delayedOutPathLockOpt: Option[Lock]
def withOutPathLockOpt(lockOpt: Option[Lock]): Evaluator
def withDelayedOutPathLockOpt(lockOpt: Option[Lock]): Evaluator

@deprecated(
"Binary compatibility shim. Use overload with parameter serialCommandExec=false instead",
"Mill 0.12.0-RC1"
Expand Down
2 changes: 2 additions & 0 deletions main/eval/src/mill/eval/EvaluatorCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import scala.util.Using
private[mill] trait EvaluatorCore extends GroupEvaluator {

def baseLogger: ColorLogger
def outPathLockOpt: Option[Lock]
def delayedOutPathLockOpt: Option[Lock]

/**
* @param goals The tasks that need to be evaluated
Expand Down
6 changes: 6 additions & 0 deletions main/eval/src/mill/eval/EvaluatorImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private[mill] case class EvaluatorImpl(
workspace: os.Path,
outPath: os.Path,
outPathLockOpt: Option[Lock],
delayedOutPathLockOpt: Option[Lock],
externalOutPath: os.Path,
override val rootModule: mill.define.BaseModule,
baseLogger: ColorLogger,
Expand All @@ -44,6 +45,11 @@ private[mill] case class EvaluatorImpl(
override def withFailFast(newFailFast: Boolean): Evaluator =
this.copy(failFast = newFailFast)

override def withOutPathLockOpt(lockOpt: Option[Lock]): Evaluator =
copy(outPathLockOpt = lockOpt)
override def withDelayedOutPathLockOpt(lockOpt: Option[Lock]): Evaluator =
copy(delayedOutPathLockOpt = lockOpt)

override def plan(goals: Agg[Task[_]]): (MultiBiMap[Terminal, Task[_]], Agg[Task[_]]) = {
Plan.plan(goals)
}
Expand Down
2 changes: 0 additions & 2 deletions main/eval/src/mill/eval/GroupEvaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import mill.api.Strict.Agg
import mill.api._
import mill.define._
import mill.eval.Evaluator.TaskResult
import mill.main.client.lock.Lock
import mill.util._

import java.lang.reflect.Method
Expand All @@ -23,7 +22,6 @@ private[mill] trait GroupEvaluator {
def home: os.Path
def workspace: os.Path
def outPath: os.Path
def outPathLockOpt: Option[Lock]
def externalOutPath: os.Path
def rootModule: mill.define.BaseModule
def classLoaderSigHash: Int
Expand Down
21 changes: 13 additions & 8 deletions main/src/mill/main/RunScript.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ 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 =
mill.eval.Evaluator.currentEvaluator.withValue(
evaluator
.withOutPathLockOpt(evaluator.delayedOutPathLockOpt)
.withDelayedOutPathLockOpt(None)
) {
Resolve.Tasks.resolve(
evaluator.rootModule,
scriptArgs,
selectMode,
evaluator.allowPositionalCommandArgs
)
}
for (targets <- resolved) yield evaluateNamed(evaluator, Agg.from(targets))
}

Expand Down
24 changes: 15 additions & 9 deletions runner/src/mill/runner/MillBuildBootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MillBuildBootstrap(
projectRoot: os.Path,
output: os.Path,
outputLockOpt: Option[Lock],
delayedOutputLockOpt: Option[Lock],
home: os.Path,
keepGoing: Boolean,
imports: Seq[String],
Expand All @@ -57,14 +58,12 @@ class MillBuildBootstrap(
def evaluate(): Watching.Result[RunnerState] = CliImports.withValue(imports) {
val runnerState = evaluateRec(0)

Using.resource(logger.waitForLock(outputLockOpt.getOrElse(Lock.dummy()))) { _ =>
for ((frame, depth) <- runnerState.frames.zipWithIndex) {
os.write.over(
recOut(output, depth) / millRunnerState,
upickle.default.write(frame.loggedData, indent = 4),
createFolders = true
)
}
for ((frame, depth) <- runnerState.frames.zipWithIndex) {
os.write.over(
recOut(output, depth) / millRunnerState,
upickle.default.write(frame.loggedData, indent = 4),
createFolders = true
)
}

Watching.Result(
Expand Down Expand Up @@ -314,7 +313,13 @@ class MillBuildBootstrap(
assert(nestedState.frames.forall(_.evaluator.isDefined))

val (evaled, evalWatched, moduleWatches) = Evaluator.allBootstrapEvaluators.withValue(
Evaluator.AllBootstrapEvaluators(Seq(evaluator) ++ nestedState.frames.flatMap(_.evaluator))
Evaluator.AllBootstrapEvaluators(
(Seq(evaluator) ++ nestedState.frames.flatMap(_.evaluator)).map { ev =>
ev
.withOutPathLockOpt(ev.delayedOutPathLockOpt)
.withDelayedOutPathLockOpt(None)
}
)
) {
evaluateWithWatches(rootModule, evaluator, targetsAndParams)
}
Expand Down Expand Up @@ -351,6 +356,7 @@ class MillBuildBootstrap(
projectRoot,
recOut(output, depth),
outputLockOpt,
delayedOutputLockOpt,
recOut(output, depth),
rootModule,
PrefixLogger(logger, "", tickerContext = bootLogPrefix),
Expand Down
7 changes: 4 additions & 3 deletions runner/src/mill/runner/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ object MillMain {
val outLockOpt =
if (config.noBuildLock.value) None
else Some(Lock.file((out / OutFiles.millLock).toString))
val useFineGrainedLock = bspContext.nonEmpty
val delayLock = bspContext.nonEmpty
var repeatForBsp = true
var loopRes: (Boolean, RunnerState) = (false, RunnerState.empty)
while (repeatForBsp) {
Expand All @@ -241,13 +241,14 @@ object MillMain {

Using.resource(
logger.waitForLock(
outLockOpt.filter(_ => !useFineGrainedLock).getOrElse(Lock.dummy())
outLockOpt.filter(_ => !delayLock).getOrElse(Lock.dummy())
)
) { _ =>
new MillBuildBootstrap(
projectRoot = WorkspaceRoot.workspaceRoot,
output = out,
outputLockOpt = if (useFineGrainedLock) outLockOpt else None,
outputLockOpt = None,
delayedOutputLockOpt = if (delayLock) outLockOpt else None,
home = config.home,
keepGoing = config.keepGoing.value,
imports = config.imports,
Expand Down
1 change: 1 addition & 0 deletions testkit/src/mill/testkit/UnitTester.scala
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class UnitTester(
module.millSourcePath,
outPath,
None,
None,
outPath,
module,
logger,
Expand Down

0 comments on commit c987d9e

Please sign in to comment.