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

Use Task instead of T when constructing targets and other tasks #3565

Merged
merged 14 commits into from
Sep 18, 2024
8 changes: 4 additions & 4 deletions bsp/src/mill/bsp/BSP.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill.bsp

import mill.api.{Ctx, PathRef}
import mill.{Agg, T}
import mill.{Agg, T, Task}
import mill.define.{Command, Discover, ExternalModule}
import mill.main.BuildInfo
import mill.eval.Evaluator
Expand All @@ -12,7 +12,7 @@ object BSP extends ExternalModule with CoursierModule {

lazy val millDiscover: Discover = Discover[this.type]

private def bspWorkerLibs: T[Agg[PathRef]] = T {
private def bspWorkerLibs: T[Agg[PathRef]] = Task {
millProjectModule("mill-bsp-worker", repositoriesTask())
}

Expand All @@ -30,7 +30,7 @@ object BSP extends ExternalModule with CoursierModule {
* reason, the message and stacktrace of the exception will be
* printed to stdout.
*/
def install(jobs: Int = 1): Command[(PathRef, ujson.Value)] = T.command {
def install(jobs: Int = 1): Command[(PathRef, ujson.Value)] = Task.Command {
// we create a file containing the additional jars to load
val libUrls = bspWorkerLibs().map(_.path.toNIO.toUri.toURL).iterator.toSeq
val cpFile =
Expand All @@ -50,7 +50,7 @@ object BSP extends ExternalModule with CoursierModule {
* @return The server result, indicating if mill should re-run this command or just exit.
*/
def startSession(allBootstrapEvaluators: Evaluator.AllBootstrapEvaluators)
: Command[BspServerResult] = T.command {
: Command[BspServerResult] = Task.Command {
T.log.errorStream.println("BSP/startSession: Starting BSP session")
val res = BspContext.bspServerHandle.runSession(allBootstrapEvaluators.value)
T.log.errorStream.println(s"BSP/startSession: Finished BSP session, result: ${res}")
Expand Down
19 changes: 9 additions & 10 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package mill.bsp.worker
import ch.epfl.scala.bsp4j
import ch.epfl.scala.bsp4j._
import com.google.gson.JsonObject
import mill.T
import mill.api.{DummyTestReporter, Result, Strict}
import mill.bsp.BspServerResult
import mill.bsp.worker.Utils.{makeBuildTarget, outputPaths, sanitizeUri}
Expand Down Expand Up @@ -230,13 +229,13 @@ private class MillBuildServer(
targetIds = _ => sourcesParams.getTargets.asScala.toSeq,
tasks = {
case module: MillBuildRootModule =>
T.task {
Task.Anon {
module.scriptSources().map(p => sourceItem(p.path, false)) ++
module.sources().map(p => sourceItem(p.path, false)) ++
module.generatedSources().map(p => sourceItem(p.path, true))
}
case module: JavaModule =>
T.task {
Task.Anon {
module.sources().map(p => sourceItem(p.path, false)) ++
module.generatedSources().map(p => sourceItem(p.path, true))
}
Expand All @@ -256,7 +255,7 @@ private class MillBuildServer(
completable(s"buildtargetInverseSources ${p}") { state =>
val tasksEvaluators = state.bspModulesById.iterator.collect {
case (id, (m: JavaModule, ev)) =>
T.task {
Task.Anon {
val src = m.allSourceFiles()
val found = src.map(sanitizeUri).contains(
p.getTextDocument.getUri
Expand Down Expand Up @@ -295,7 +294,7 @@ private class MillBuildServer(
targetIds = _ => p.getTargets.asScala.toSeq,
tasks = {
case m: JavaModule =>
T.task {
Task.Anon {
(
m.defaultResolver().resolveDeps(
m.transitiveCompileIvyDeps() ++ m.transitiveIvyDeps(),
Expand Down Expand Up @@ -334,7 +333,7 @@ private class MillBuildServer(
hint = "buildTargetDependencyModules",
targetIds = _ => params.getTargets.asScala.toSeq,
tasks = { case m: JavaModule =>
T.task { (m.transitiveCompileIvyDeps(), m.transitiveIvyDeps(), m.unmanagedClasspath()) }
Task.Anon { (m.transitiveCompileIvyDeps(), m.transitiveIvyDeps(), m.unmanagedClasspath()) }
}
) {
case (
Expand Down Expand Up @@ -364,8 +363,8 @@ private class MillBuildServer(
s"buildTargetResources ${p}",
targetIds = _ => p.getTargets.asScala.toSeq,
tasks = {
case m: JavaModule => T.task { m.resources() }
case _ => T.task { Nil }
case m: JavaModule => Task.Anon { m.resources() }
case _ => Task.Anon { Nil }
}
) {
case (ev, state, id, m, resources) =>
Expand All @@ -387,7 +386,7 @@ private class MillBuildServer(
case (m: SemanticDbJavaModule, ev) if clientWantsSemanticDb =>
(m.compiledClassesAndSemanticDbFiles, ev)
case (m: JavaModule, ev) => (m.compile, ev)
case (m, ev) => T.task {
case (m, ev) => Task.Anon {
Result.Failure(
s"Don't know how to compile non-Java target ${m.bspBuildTarget.displayName}"
)
Expand Down Expand Up @@ -446,7 +445,7 @@ private class MillBuildServer(
}.get

val args = params.getArguments.getOrElse(Seq.empty[String])
val runTask = module.run(T.task(Args(args)))
val runTask = module.run(Task.Anon(Args(args)))
val runResult = ev.evaluate(
Strict.Agg(runTask),
Utils.getBspLoggedReporterPool(runParams.getOriginId, state.bspIdByModule, client),
Expand Down
4 changes: 2 additions & 2 deletions bsp/worker/src/mill/bsp/worker/MillJavaBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ch.epfl.scala.bsp4j.{
JavacOptionsParams,
JavacOptionsResult
}
import mill.T
import mill.Task
import mill.bsp.worker.Utils.sanitizeUri
import mill.scalalib.{JavaModule, SemanticDbJavaModule}

Expand All @@ -26,7 +26,7 @@ private trait MillJavaBuildServer extends JavaBuildServer { this: MillBuildServe
sem.bspCompiledClassesAndSemanticDbFiles
case _ => m.bspCompileClassesPath
}
T.task {
Task.Anon {
(
classesPathTask(),
m.javacOptions() ++ m.mandatoryJavacOptions(),
Expand Down
4 changes: 2 additions & 2 deletions bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ch.epfl.scala.bsp4j.{
JvmTestEnvironmentParams,
JvmTestEnvironmentResult
}
import mill.T
import mill.Task
import mill.bsp.worker.Utils.sanitizeUri
import mill.scalalib.api.CompilationResult
import mill.scalalib.{JavaModule, TestModule}
Expand Down Expand Up @@ -55,7 +55,7 @@ private trait MillJvmBuildServer extends JvmBuildServer { this: MillBuildServer
case m: TestModule => m.getTestEnvironmentVars()
case _ => m.compile
}
T.task {
Task.Anon {
(
m.runClasspath(),
m.forkArgs(),
Expand Down
14 changes: 7 additions & 7 deletions bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ch.epfl.scala.bsp4j.{
ScalacOptionsParams,
ScalacOptionsResult
}
import mill.{Agg, T}
import mill.{Agg, Task}
import mill.bsp.worker.Utils.sanitizeUri
import mill.util.Jvm
import mill.scalalib.{JavaModule, ScalaModule, TestModule, UnresolvedPath}
Expand All @@ -35,13 +35,13 @@ private trait MillScalaBuildServer extends ScalaBuildServer { this: MillBuildSer
case m: JavaModule =>
val scalacOptionsTask = m match {
case m: ScalaModule => m.allScalacOptions
case _ => T.task { Seq.empty[String] }
case _ => Task.Anon { Seq.empty[String] }
}

val compileClasspathTask =
if (enableJvmCompileClasspathProvider) {
// We have a dedicated request for it
T.task { Agg.empty[UnresolvedPath] }
Task.Anon { Agg.empty[UnresolvedPath] }
} else {
m.bspCompileClasspath
}
Expand All @@ -53,7 +53,7 @@ private trait MillScalaBuildServer extends ScalaBuildServer { this: MillBuildSer
m.bspCompileClassesPath
}

T.task {
Task.Anon {
(scalacOptionsTask(), compileClasspathTask(), classesPathTask())
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ private trait MillScalaBuildServer extends ScalaBuildServer { this: MillBuildSer
hint = "buildTarget/scalaMainClasses",
targetIds = _ => p.getTargets.asScala.toSeq,
tasks = { case m: JavaModule =>
T.task((m.zincWorker().worker(), m.compile(), m.forkArgs(), m.forkEnv()))
Task.Anon((m.zincWorker().worker(), m.compile(), m.forkArgs(), m.forkEnv()))
}
) {
case (ev, state, id, m: JavaModule, (worker, compile, forkArgs, forkEnv)) =>
Expand All @@ -112,9 +112,9 @@ private trait MillScalaBuildServer extends ScalaBuildServer { this: MillBuildSer
targetIds = _ => p.getTargets.asScala.toSeq,
tasks = {
case m: TestModule =>
T.task(Some((m.runClasspath(), m.testFramework(), m.testClasspath())))
Task.Anon(Some((m.runClasspath(), m.testFramework(), m.testClasspath())))
case _ =>
T.task(None)
Task.Anon(None)
}
) {
case (ev, state, id, m: TestModule, Some((classpath, testFramework, testClasspath))) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait ArtifactoryPublishModule extends PublishModule {
artifactorySnapshotUri: String = artifactorySnapshotUri,
readTimeout: Int = 60000,
connectTimeout: Int = 5000
): define.Command[Unit] = T.command {
): define.Command[Unit] = Task.Command {
val PublishModule.PublishData(artifactInfo, artifacts) = publishArtifacts()
new ArtifactoryPublisher(
artifactoryUri,
Expand Down Expand Up @@ -59,7 +59,7 @@ object ArtifactoryPublishModule extends ExternalModule {
publishArtifacts: mill.main.Tasks[PublishModule.PublishData],
readTimeout: Int = 60000,
connectTimeout: Int = 5000
) = T.command {
) = Task.Command {

val artifacts = T.sequence(publishArtifacts.value)().map {
case data @ PublishModule.PublishData(_, _) => data.withConcretePath
Expand All @@ -76,7 +76,7 @@ object ArtifactoryPublishModule extends ExternalModule {
)
}

private def checkArtifactoryCreds(credentials: String): Task[String] = T.task {
private def checkArtifactoryCreds(credentials: String): Task[String] = Task.Anon {
if (credentials.isEmpty) {
(for {
username <- T.env.get("ARTIFACTORY_USERNAME")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ trait BintrayPublishModule extends PublishModule {

def bintrayRepo: String

def bintrayPackage = T { artifactId() }
def bintrayPackage: T[String] = Task { artifactId() }

def bintrayPublishArtifacts: T[BintrayPublishData] = T {
def bintrayPublishArtifacts: T[BintrayPublishData] = Task {
val PublishModule.PublishData(artifactInfo, artifacts) = publishArtifacts()
BintrayPublishData(artifactInfo, artifacts, bintrayPackage())
}
Expand All @@ -36,7 +36,7 @@ trait BintrayPublishModule extends PublishModule {
release: Boolean = true,
readTimeout: Int = 60000,
connectTimeout: Int = 5000
): define.Command[Unit] = T.command {
): define.Command[Unit] = Task.Command {
new BintrayPublisher(
bintrayOwner,
bintrayRepo,
Expand Down Expand Up @@ -69,7 +69,7 @@ object BintrayPublishModule extends ExternalModule {
publishArtifacts: mill.main.Tasks[BintrayPublishData],
readTimeout: Int = 60000,
connectTimeout: Int = 5000
) = T.command {
) = Task.Command {
new BintrayPublisher(
bintrayOwner,
bintrayRepo,
Expand All @@ -83,7 +83,7 @@ object BintrayPublishModule extends ExternalModule {
)
}

private def checkBintrayCreds(credentials: String): Task[String] = T.task {
private def checkBintrayCreds(credentials: String): Task[String] = Task.Anon {
if (credentials.isEmpty) {
(for {
username <- T.env.get("BINTRAY_USERNAME")
Expand Down
Loading
Loading