Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put back withPromptPaused, but make it private[mill] #3635

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ object Deps {
Seq(Play_3_0, Play_2_9, Play_2_8, Play_2_7, Play_2_6).map(p => (p.playBinVersion, p)).toMap

val acyclic = ivy"com.lihaoyi:::acyclic:0.3.12"
val ammoniteVersion = "3.0.0"
val ammoniteVersion = "3.0.0-2-6342755f"
val asmTree = ivy"org.ow2.asm:asm-tree:9.7"
val bloopConfig = ivy"ch.epfl.scala::bloop-config:1.5.5"

Expand Down
1 change: 1 addition & 0 deletions main/api/src/mill/api/Logger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ trait Logger {
private[mill] def clearPromptStatuses(): Unit = ()
private[mill] def removePromptLine(key: Seq[String]): Unit = ()
private[mill] def removePromptLine(): Unit = ()
private[mill] def withPromptPaused[T](t: => T): T = t

/**
* @since Mill 0.10.5
Expand Down
15 changes: 8 additions & 7 deletions main/eval/src/mill/eval/EvaluatorCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ private[mill] trait EvaluatorCore extends GroupEvaluator {
def evaluateTerminals(
terminals: Seq[Terminal],
forkExecutionContext: mill.api.Ctx.Fork.Impl,
serial: Boolean
exclusive: Boolean
) = {
implicit val taskExecutionContext =
if (serial) ExecutionContexts.RunNow else forkExecutionContext
if (exclusive) ExecutionContexts.RunNow else forkExecutionContext
// We walk the task graph in topological order and schedule the futures
// to run asynchronously. During this walk, we store the scheduled futures
// in a dictionary. When scheduling each future, we are guaranteed that the
Expand Down Expand Up @@ -147,7 +147,7 @@ private[mill] trait EvaluatorCore extends GroupEvaluator {
tickerContext = GroupEvaluator.dynamicTickerPrefix.value,
verboseKeySuffix = verboseKeySuffix,
message = tickerPrefix,
noPrefix = serial
noPrefix = exclusive
)

val res = evaluateGroupCached(
Expand All @@ -161,7 +161,8 @@ private[mill] trait EvaluatorCore extends GroupEvaluator {
logger = contextLogger,
classToTransitiveClasses,
allTransitiveClassMethods,
forkExecutionContext
forkExecutionContext,
exclusive
)

if (failFast && res.newResults.values.exists(_.result.asSuccess.isEmpty))
Expand Down Expand Up @@ -205,7 +206,7 @@ private[mill] trait EvaluatorCore extends GroupEvaluator {
val (_, tasksTransitive0) = Plan.plan(Agg.from(tasks0.map(_.task)))

val tasksTransitive = tasksTransitive0.toSet
val (tasks, leafSerialCommands) = terminals0.partition {
val (tasks, leafExclusiveCommands) = terminals0.partition {
case Terminal.Labelled(t, _) =>
if (tasksTransitive.contains(t)) true
else t match {
Expand All @@ -220,10 +221,10 @@ private[mill] trait EvaluatorCore extends GroupEvaluator {
evaluateTerminals(
tasks,
ec,
serial = false
exclusive = false
)

evaluateTerminals(leafSerialCommands, ec, serial = true)
evaluateTerminals(leafExclusiveCommands, ec, exclusive = true)

logger.clearPromptStatuses()
val finishedOptsMap = terminals0
Expand Down
5 changes: 3 additions & 2 deletions main/eval/src/mill/eval/EvaluatorImpl.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mill.eval

import mill.api.{CompileProblemReporter, Strict, TestReporter, Val}
import mill.api.{CompileProblemReporter, Strict, SystemStreams, TestReporter, Val}
import mill.api.Strict.Agg
import mill.define._
import mill.util._
Expand Down Expand Up @@ -30,7 +30,8 @@ private[mill] case class EvaluatorImpl(
methodCodeHashSignatures: Map[String, Int],
override val disableCallgraph: Boolean,
override val allowPositionalCommandArgs: Boolean,
val systemExit: Int => Nothing
val systemExit: Int => Nothing,
val exclusiveSystemStreams: SystemStreams
) extends Evaluator with EvaluatorCore {
import EvaluatorImpl._

Expand Down
47 changes: 33 additions & 14 deletions main/eval/src/mill/eval/GroupEvaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private[mill] trait GroupEvaluator {
def methodCodeHashSignatures: Map[String, Int]
def disableCallgraph: Boolean
def systemExit: Int => Nothing
def exclusiveSystemStreams: SystemStreams

lazy val constructorHashSignatures: Map[String, Seq[(String, Int)]] = methodCodeHashSignatures
.toSeq
Expand All @@ -55,7 +56,8 @@ private[mill] trait GroupEvaluator {
logger: ColorLogger,
classToTransitiveClasses: Map[Class[_], IndexedSeq[Class[_]]],
allTransitiveClassMethods: Map[Class[_], Map[String, Method]],
executionContext: mill.api.Ctx.Fork.Api
executionContext: mill.api.Ctx.Fork.Api,
exclusive: Boolean
): GroupEvaluator.Results = {

val targetLabel = terminal match {
Expand Down Expand Up @@ -141,7 +143,8 @@ private[mill] trait GroupEvaluator {
zincProblemReporter,
testReporter,
logger,
executionContext
executionContext,
exclusive
)
GroupEvaluator.Results(newResults, newEvaluated.toSeq, null, inputsHash, -1)

Expand Down Expand Up @@ -197,7 +200,8 @@ private[mill] trait GroupEvaluator {
zincProblemReporter,
testReporter,
logger,
executionContext
executionContext,
exclusive
)
}

Expand Down Expand Up @@ -239,7 +243,8 @@ private[mill] trait GroupEvaluator {
reporter: Int => Option[CompileProblemReporter],
testReporter: TestReporter,
logger: mill.api.Logger,
executionContext: mill.api.Ctx.Fork.Api
executionContext: mill.api.Ctx.Fork.Api,
exclusive: Boolean
): (Map[Task[_], TaskResult[(Val, Int)]], mutable.Buffer[Task[_]]) = {

def computeAll() = {
Expand Down Expand Up @@ -286,19 +291,33 @@ private[mill] trait GroupEvaluator {
override def jobs: Int = effectiveThreadCount
}

os.dynamicPwdFunction.withValue(() => makeDest()) {
mill.api.SystemStreams.withStreams(multiLogger.systemStreams) {
try task.evaluate(args).map(Val(_))
catch {
case f: Result.Failing[Val] => f
case NonFatal(e) =>
Result.Exception(
e,
new OuterStack(new Exception().getStackTrace.toIndexedSeq)
)
def wrap[T](t: => T): T = {

val (streams, destFunc) =
if (exclusive) (exclusiveSystemStreams, () => workspace)
else (multiLogger.systemStreams, () => makeDest())

os.dynamicPwdFunction.withValue(destFunc) {
SystemStreams.withStreams(streams) {
if (exclusive) {
logger.reportKey(Seq(counterMsg))
logger.withPromptPaused { t }
} else t
}
}
}

wrap {
try task.evaluate(args).map(Val(_))
catch {
case f: Result.Failing[Val] => f
case NonFatal(e) =>
Result.Exception(
e,
new OuterStack(new Exception().getStackTrace.toIndexedSeq)
)
}
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion main/util/src/mill/util/MultiLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ class MultiLogger(
logger2.setPromptLeftHeader(s)
}

private[mill] override def withPromptPaused[T](t: => T): T = {
logger1.withPromptPaused(logger2.withPromptPaused(t))
}

override def enableTicker: Boolean = logger1.enableTicker || logger2.enableTicker

override def subLogger(path: os.Path, key: String, message: String): Logger = {
private[mill] override def subLogger(path: os.Path, key: String, message: String): Logger = {
new MultiLogger(
colored,
logger1.subLogger(path, key, message),
Expand Down
7 changes: 6 additions & 1 deletion main/util/src/mill/util/PrefixLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ class PrefixLogger(
private[mill] override def setPromptLeftHeader(s: String): Unit = logger0.setPromptLeftHeader(s)
override def enableTicker = logger0.enableTicker

override def subLogger(path: os.Path, subKeySuffix: String, message: String): Logger = {
private[mill] override def subLogger(
path: os.Path,
subKeySuffix: String,
message: String
): Logger = {
new PrefixLogger(
logger0,
key :+ subKeySuffix,
Expand All @@ -109,6 +113,7 @@ class PrefixLogger(
message
)
}
private[mill] override def withPromptPaused[T](t: => T): T = logger0.withPromptPaused(t)
}

object PrefixLogger {
Expand Down
22 changes: 22 additions & 0 deletions main/util/src/mill/util/PromptLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private[mill] class PromptLogger(

@volatile var stopped = false
@volatile var paused = false
@volatile var pauseNoticed = false

val promptUpdaterThread = new Thread(() =>
while (!stopped) {
Expand All @@ -69,6 +70,8 @@ private[mill] class PromptLogger(
refreshPrompt()
}
}
} else {
pauseNoticed = true
}
}
)
Expand Down Expand Up @@ -127,6 +130,25 @@ private[mill] class PromptLogger(
}

def systemStreams = streamManager.systemStreams

private[mill] override def withPromptPaused[T](t: => T): T = {
if (!enableTicker) t
else {
pauseNoticed = false
paused = true
try {
// After the prompt gets paused, wait until the `promptUpdaterThread` marks
// `pauseNoticed = true`, so we can be sure it's done printing out prompt updates for
// now and we can proceed with running `t` without any last updates slipping through
while (!pauseNoticed) Thread.sleep(1)
// Clear the prompt so the code in `t` has a blank terminal to work with
systemStreams0.err.write(AnsiNav.clearScreen(0).getBytes)
systemStreams0.err.flush()
t

} finally paused = false
}
}
}

private[mill] object PromptLogger {
Expand Down
1 change: 1 addition & 0 deletions main/util/src/mill/util/ProxyLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ProxyLogger(logger: Logger) extends Logger {
private[mill] override def removePromptLine(key: Seq[String]): Unit = logger.removePromptLine(key)
private[mill] override def removePromptLine(): Unit = logger.removePromptLine()
private[mill] override def setPromptLeftHeader(s: String): Unit = logger.setPromptLeftHeader(s)
private[mill] override def withPromptPaused[T](t: => T): T = logger.withPromptPaused(t)

override def enableTicker = logger.enableTicker
}
5 changes: 3 additions & 2 deletions runner/src/mill/runner/MillBuildBootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mill.runner
import mill.util.{ColorLogger, PrefixLogger, Watchable}
import mill.main.BuildInfo
import mill.main.client.CodeGenConstants._
import mill.api.{PathRef, Val, internal}
import mill.api.{PathRef, SystemStreams, Val, internal}
import mill.eval.Evaluator
import mill.main.RunScript
import mill.resolve.SelectMode
Expand Down Expand Up @@ -356,7 +356,8 @@ class MillBuildBootstrap(
methodCodeHashSignatures = methodCodeHashSignatures,
disableCallgraph = disableCallgraph,
allowPositionalCommandArgs = allowPositionalCommandArgs,
systemExit = systemExit
systemExit = systemExit,
exclusiveSystemStreams = SystemStreams.original
)
}

Expand Down
51 changes: 24 additions & 27 deletions scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill
package scalalib

import mill.api.{DummyInputStream, JarManifest, PathRef, Result, SystemStreams, internal}
import mill.api.{DummyInputStream, JarManifest, PathRef, Result, internal}
import mill.main.BuildInfo
import mill.util.{Jvm, Util}
import mill.util.Jvm.createJar
Expand Down Expand Up @@ -437,22 +437,21 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
Result.Failure("console needs to be run with the -i/--interactive flag")
} else {
val useJavaCp = "-usejavacp"
SystemStreams.withStreams(SystemStreams.original) {
Jvm.runSubprocess(
mainClass =
if (ZincWorkerUtil.isDottyOrScala3(scalaVersion()))
"dotty.tools.repl.Main"
else
"scala.tools.nsc.MainGenericRunner",
classPath = runClasspath().map(_.path) ++ scalaCompilerClasspath().map(
_.path
),
jvmArgs = forkArgs(),
envArgs = forkEnv(),
mainArgs = Seq(useJavaCp) ++ consoleScalacOptions().filterNot(Set(useJavaCp)),
workingDir = forkWorkingDir()
)
}

Jvm.runSubprocess(
mainClass =
if (ZincWorkerUtil.isDottyOrScala3(scalaVersion()))
"dotty.tools.repl.Main"
else
"scala.tools.nsc.MainGenericRunner",
classPath = runClasspath().map(_.path) ++ scalaCompilerClasspath().map(
_.path
),
jvmArgs = forkArgs(),
envArgs = forkEnv(),
mainArgs = Seq(useJavaCp) ++ consoleScalacOptions().filterNot(Set(useJavaCp)),
workingDir = forkWorkingDir()
)
Result.Success(())
}
}
Expand Down Expand Up @@ -511,16 +510,14 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer =>
} else {
val mainClass = ammoniteMainClass()
T.log.debug(s"Using ammonite main class: ${mainClass}")
SystemStreams.withStreams(SystemStreams.original) {
Jvm.runSubprocess(
mainClass = mainClass,
classPath = ammoniteReplClasspath().map(_.path),
jvmArgs = forkArgs(),
envArgs = forkEnv(),
mainArgs = replOptions,
workingDir = forkWorkingDir()
)
}
Jvm.runSubprocess(
mainClass = mainClass,
classPath = ammoniteReplClasspath().map(_.path),
jvmArgs = forkArgs(),
envArgs = forkEnv(),
mainArgs = replOptions,
workingDir = forkWorkingDir()
)
Result.Success(())
}

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 @@ -101,7 +101,8 @@ class UnitTester(
methodCodeHashSignatures = Map(),
disableCallgraph = false,
allowPositionalCommandArgs = false,
systemExit = i => ???
systemExit = i => ???,
exclusiveSystemStreams = new SystemStreams(outStream, errStream, inStream)
)

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