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

Make T an alias for Task instead of Target, move T.* operations to Task.* #3356

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
14 changes: 7 additions & 7 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[this.type] = 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,11 +30,11 @@ 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 =
T.workspace / Constants.bspDir / s"${Constants.serverName}-${BuildInfo.millVersion}.resources"
Task.workspace / Constants.bspDir / s"${Constants.serverName}-${BuildInfo.millVersion}.resources"
os.write.over(
cpFile,
libUrls.mkString("\n"),
Expand All @@ -50,10 +50,10 @@ 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 {
T.log.errorStream.println("BSP/startSession: Starting BSP session")
: Command[BspServerResult] = Task.command {
Task.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}")
Task.log.errorStream.println(s"BSP/startSession: Finished BSP session, result: ${res}")
res
}

Expand Down
2 changes: 1 addition & 1 deletion bsp/worker/src/mill/bsp/worker/BspTestReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import java.io.{PrintWriter, StringWriter}
* to log testing events.
* @param arguments compilation arguments as part of the BSP context,
* in case special arguments need to be passed to
* the compiler before running the test task.
* the compiler before running the test Task.
*/
private class BspTestReporter(
client: BuildClient,
Expand Down
22 changes: 11 additions & 11 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ import ch.epfl.scala.bsp4j.{
}
import ch.epfl.scala.bsp4j
import com.google.gson.JsonObject
import mill.T
import mill.{Task, T}
import mill.api.{DummyTestReporter, Result, Strict}
import mill.define.Segment.Label
import mill.define.{Args, Discover, ExternalModule, Task}
import mill.define.{Args, Discover, ExternalModule}
import mill.eval.Evaluator
import mill.main.MainModule
import mill.scalalib.{JavaModule, SemanticDbJavaModule, TestModule}
Expand Down Expand Up @@ -303,13 +303,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 @@ -327,7 +327,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 @@ -366,7 +366,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 @@ -405,7 +405,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 @@ -435,8 +435,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 @@ -457,7 +457,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 @@ -516,7 +516,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, T}
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 { (classesPathTask(), m.javacOptions(), m.bspCompileClasspath()) }
Task.anon { (classesPathTask(), m.javacOptions(), m.bspCompileClasspath()) }
}
) {
// We ignore all non-JavaModule
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, T}
import mill.bsp.worker.Utils.sanitizeUri
import mill.scalalib.JavaModule

Expand Down Expand Up @@ -50,7 +50,7 @@ private trait MillJvmBuildServer extends JvmBuildServer { this: MillBuildServer
targetIds = _ => targetIds,
tasks = {
case m: JavaModule =>
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, T, 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 @@ -5,6 +5,7 @@ import mill.api.Result
import scalalib._
import mill.contrib.artifactory.ArtifactoryPublishModule.checkArtifactoryCreds
import mill.define.{ExternalModule, Task}
import mill.define.Command

trait ArtifactoryPublishModule extends PublishModule {
def artifactoryUri: String
Expand All @@ -27,15 +28,15 @@ 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,
artifactorySnapshotUri,
checkArtifactoryCreds(credentials)(),
readTimeout,
connectTimeout,
T.log
Task.log
).publish(artifacts.map { case (a, b) => (a.path, b) }, artifactInfo)
}
}
Expand All @@ -59,9 +60,9 @@ object ArtifactoryPublishModule extends ExternalModule {
publishArtifacts: mill.main.Tasks[PublishModule.PublishData],
readTimeout: Int = 60000,
connectTimeout: Int = 5000
) = T.command {
): Command[Unit] = Task.command {

val artifacts = T.sequence(publishArtifacts.value)().map {
val artifacts = Task.sequence(publishArtifacts.value)().map {
case data @ PublishModule.PublishData(_, _) => data.withConcretePath
}
new ArtifactoryPublisher(
Expand All @@ -70,17 +71,17 @@ object ArtifactoryPublishModule extends ExternalModule {
checkArtifactoryCreds(credentials)(),
readTimeout,
connectTimeout,
T.log
Task.log
).publishAll(
artifacts: _*
)
}

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")
password <- T.env.get("ARTIFACTORY_PASSWORD")
username <- Task.env.get("ARTIFACTORY_USERNAME")
password <- Task.env.get("ARTIFACTORY_PASSWORD")
} yield {
Result.Success(s"$username:$password")
}).getOrElse(
Expand Down
2 changes: 1 addition & 1 deletion contrib/bintray/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import mill.contrib.bintray.BintrayPublishModule
object mymodule extends BintrayPublishModule {
def bintrayOwner = "owner"
def bintrayRepo = "repo"
def bintrayPackage = T {...}
def bintrayPackage = Task {...}

...
}
Expand Down
21 changes: 11 additions & 10 deletions contrib/bintray/src/mill/contrib/bintray/BintrayPublishModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import mill.api.Result
import scalalib._
import mill.contrib.bintray.BintrayPublishModule.checkBintrayCreds
import mill.define.{ExternalModule, Task}
import mill.define.{Command, Target}

trait BintrayPublishModule extends PublishModule {

def bintrayOwner: String

def bintrayRepo: String

def bintrayPackage = T { artifactId() }
def bintrayPackage: Target[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,15 +37,15 @@ 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,
checkBintrayCreds(credentials)(),
release,
readTimeout,
connectTimeout,
T.log
Task.log
).publish(bintrayPublishArtifacts())
}
}
Expand All @@ -69,25 +70,25 @@ object BintrayPublishModule extends ExternalModule {
publishArtifacts: mill.main.Tasks[BintrayPublishData],
readTimeout: Int = 60000,
connectTimeout: Int = 5000
) = T.command {
): Command[Unit] = Task.command {
new BintrayPublisher(
bintrayOwner,
bintrayRepo,
checkBintrayCreds(credentials)(),
release,
readTimeout,
connectTimeout,
T.log
Task.log
).publishAll(
T.sequence(publishArtifacts.value)(): _*
Task.sequence(publishArtifacts.value)(): _*
)
}

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")
password <- T.env.get("BINTRAY_PASSWORD")
username <- Task.env.get("BINTRAY_USERNAME")
password <- Task.env.get("BINTRAY_PASSWORD")
} yield {
Result.Success(s"$username:$password")
}).getOrElse(
Expand Down
2 changes: 1 addition & 1 deletion contrib/bloop/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import mill.scalalib._
import mill.contrib.bloop.Bloop

object MyModule extends ScalaModule with Bloop.Module {
def myTask = T { bloop.config() }
def myTask = Task { bloop.config() }
}
----

Expand Down
Loading