diff --git a/bsp/src/mill/bsp/BSP.scala b/bsp/src/mill/bsp/BSP.scala index 3442ee7e6af..e0056953674 100644 --- a/bsp/src/mill/bsp/BSP.scala +++ b/bsp/src/mill/bsp/BSP.scala @@ -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 @@ -10,9 +10,9 @@ import mill.scalalib.CoursierModule object BSP extends ExternalModule with CoursierModule { - lazy val millDiscover: Discover[this.type] = Discover[this.type] + 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()) } @@ -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"), @@ -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 } diff --git a/bsp/worker/src/mill/bsp/worker/BspTestReporter.scala b/bsp/worker/src/mill/bsp/worker/BspTestReporter.scala index 746886b2121..25dcd9c1d15 100644 --- a/bsp/worker/src/mill/bsp/worker/BspTestReporter.scala +++ b/bsp/worker/src/mill/bsp/worker/BspTestReporter.scala @@ -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, diff --git a/bsp/worker/src/mill/bsp/worker/MillBuildServer.scala b/bsp/worker/src/mill/bsp/worker/MillBuildServer.scala index acaa2a0ebcb..1d9a9688b80 100644 --- a/bsp/worker/src/mill/bsp/worker/MillBuildServer.scala +++ b/bsp/worker/src/mill/bsp/worker/MillBuildServer.scala @@ -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} @@ -90,7 +90,7 @@ private class MillBuildServer( ) extends ExternalModule with BuildServer { - lazy val millDiscover: Discover[this.type] = Discover[this.type] + val millDiscover: Discover[this.type] = Discover[this.type] private[worker] var cancellator: Boolean => Unit = shutdownBefore => () private[worker] var onSessionEnd: Option[BspServerResult => Unit] = None @@ -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)) } @@ -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 @@ -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(), @@ -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 ( @@ -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) => @@ -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}" ) @@ -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), diff --git a/bsp/worker/src/mill/bsp/worker/MillJavaBuildServer.scala b/bsp/worker/src/mill/bsp/worker/MillJavaBuildServer.scala index 4e43072beb5..8a6b7a63291 100644 --- a/bsp/worker/src/mill/bsp/worker/MillJavaBuildServer.scala +++ b/bsp/worker/src/mill/bsp/worker/MillJavaBuildServer.scala @@ -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} @@ -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 diff --git a/bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala b/bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala index b358ddcc28e..13476f2de49 100644 --- a/bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala +++ b/bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala @@ -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 @@ -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(), diff --git a/bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala b/bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala index a34a6ab037a..291393b12be 100644 --- a/bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala +++ b/bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala @@ -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} @@ -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 } @@ -53,7 +53,7 @@ private trait MillScalaBuildServer extends ScalaBuildServer { this: MillBuildSer m.bspCompileClassesPath } - T.task { + Task.anon { (scalacOptionsTask(), compileClasspathTask(), classesPathTask()) } } @@ -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)) => @@ -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))) => diff --git a/contrib/artifactory/src/mill/contrib/artifactory/ArtifactoryPublishModule.scala b/contrib/artifactory/src/mill/contrib/artifactory/ArtifactoryPublishModule.scala index 1c2234edc5d..e777ad74af1 100644 --- a/contrib/artifactory/src/mill/contrib/artifactory/ArtifactoryPublishModule.scala +++ b/contrib/artifactory/src/mill/contrib/artifactory/ArtifactoryPublishModule.scala @@ -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 @@ -27,7 +28,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, @@ -35,7 +36,7 @@ trait ArtifactoryPublishModule extends PublishModule { checkArtifactoryCreds(credentials)(), readTimeout, connectTimeout, - T.log + Task.log ).publish(artifacts.map { case (a, b) => (a.path, b) }, artifactInfo) } } @@ -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( @@ -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( diff --git a/contrib/bintray/readme.adoc b/contrib/bintray/readme.adoc index 1028b1c3544..e7909b1d4b3 100644 --- a/contrib/bintray/readme.adoc +++ b/contrib/bintray/readme.adoc @@ -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 {...} ... } diff --git a/contrib/bintray/src/mill/contrib/bintray/BintrayPublishModule.scala b/contrib/bintray/src/mill/contrib/bintray/BintrayPublishModule.scala index 91cfd99164c..bcaf7bb9be2 100644 --- a/contrib/bintray/src/mill/contrib/bintray/BintrayPublishModule.scala +++ b/contrib/bintray/src/mill/contrib/bintray/BintrayPublishModule.scala @@ -5,6 +5,7 @@ import mill.api.Result import scalalib._ import mill.contrib.bintray.BintrayPublishModule.checkBintrayCreds import mill.define.{ExternalModule, Task} +import mill.define.Command trait BintrayPublishModule extends PublishModule { @@ -12,9 +13,9 @@ trait BintrayPublishModule extends PublishModule { def bintrayRepo: String - def bintrayPackage = T { artifactId() } + def bintrayPackage: Task[String] = Task { artifactId() } - def bintrayPublishArtifacts: T[BintrayPublishData] = T { + def bintrayPublishArtifacts: T[BintrayPublishData] = Task { val PublishModule.PublishData(artifactInfo, artifacts) = publishArtifacts() BintrayPublishData(artifactInfo, artifacts, bintrayPackage()) } @@ -36,7 +37,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, @@ -44,7 +45,7 @@ trait BintrayPublishModule extends PublishModule { release, readTimeout, connectTimeout, - T.log + Task.log ).publish(bintrayPublishArtifacts()) } } @@ -69,7 +70,7 @@ 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, @@ -77,17 +78,17 @@ object BintrayPublishModule extends ExternalModule { 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( diff --git a/contrib/bloop/readme.adoc b/contrib/bloop/readme.adoc index ac47565b5e6..109f559f63c 100644 --- a/contrib/bloop/readme.adoc +++ b/contrib/bloop/readme.adoc @@ -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() } } ---- diff --git a/contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala b/contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala index 88bd29fbddc..8c4801ff02e 100644 --- a/contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala +++ b/contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala @@ -27,8 +27,8 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { * Generates bloop configuration files reflecting the build, * under pwd/.bloop. */ - def install() = T.command { - val res = T.traverse(computeModules)(_.bloop.writeConfigFile())() + def install() = Task.command { + val res = Task.traverse(computeModules)(_.bloop.writeConfigFile())() val written = res.map(_._2).map(_.path) // Make bloopDir if it doesn't exists if (!os.exists(bloopDir)) { @@ -61,7 +61,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { def linkerMode: T[Option[BloopConfig.LinkerMode]] = None object bloop extends MillModule { - def config = T { + def config = Task { new BloopOps(self).bloop.config() } } @@ -85,18 +85,18 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { override def millOuterCtx = jm.millOuterCtx object bloop extends MillModule { - def config = T { outer.bloopConfig(jm) } + def config = Task { outer.bloopConfig(jm)() } - def writeConfigFile(): Command[(String, PathRef)] = T.command { + def writeConfigFile(): Command[(String, PathRef)] = Task.command { os.makeDir.all(bloopDir) val path = bloopConfigPath(jm) _root_.bloop.config.write(config(), path.toNIO) - T.log.info(s"Wrote $path") + Task.log.info(s"Wrote $path") name(jm) -> PathRef(path) } @deprecated("Use writeConfigFile instead.", "Mill after 0.10.9") - def writeConfig: Target[(String, PathRef)] = T { + def writeConfig: Task[(String, PathRef)] = Task { writeConfigFile()() } } @@ -138,8 +138,8 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { * that does not get invalidated upon sourcefile change. Mainly called * from module#sources in bloopInstall */ - def moduleSourceMap = T.input { - val sources = T.traverse(computeModules) { m => + def moduleSourceMap = Task.input { + val sources = Task.traverse(computeModules) { m => m.allSources.map { paths => name(m) -> paths.map(_.path) } @@ -170,7 +170,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { val scalaConfig = module match { case s: ScalaModule => - T.task { + Task.anon { Some( BloopConfig.Scala( organization = s.scalaOrganization(), @@ -183,7 +183,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { ) ) } - case _ => T.task(None) + case _ => Task.anon(None) } // ////////////////////////////////////////////////////////////////////////// @@ -192,17 +192,17 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { def jsLinkerMode(m: JavaModule): Task[Config.LinkerMode] = (m.asBloop match { - case Some(bm) => T.task(bm.linkerMode()) - case None => T.task(None) + case Some(bm) => Task.anon(bm.linkerMode()) + case None => Task.anon(None) }).map(_.getOrElse(Config.LinkerMode.Debug)) // ////////////////////////////////////////////////////////////////////////// // Classpath // ////////////////////////////////////////////////////////////////////////// - val classpath = T.task { - val transitiveCompileClasspath = T.traverse(module.transitiveModuleCompileModuleDeps)(m => - T.task { m.localCompileClasspath().map(_.path) ++ Agg(classes(m)) } + val classpath = Task.anon { + val transitiveCompileClasspath = Task.traverse(module.transitiveModuleCompileModuleDeps)(m => + Task.anon { m.localCompileClasspath().map(_.path) ++ Agg(classes(m)) } )().flatten module.resolvedIvyDeps().map(_.path) ++ @@ -210,20 +210,20 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { module.localCompileClasspath().map(_.path) } - val runtimeClasspath = T.task { + val runtimeClasspath = Task.anon { module.transitiveModuleDeps.map(classes) ++ module.resolvedRunIvyDeps().map(_.path) ++ module.unmanagedClasspath().map(_.path) } val compileResources = - T.task(module.compileResources().map(_.path.toNIO).toList) + Task.anon(module.compileResources().map(_.path.toNIO).toList) val runtimeResources = - T.task(compileResources() ++ module.resources().map(_.path.toNIO).toList) + Task.anon(compileResources() ++ module.resources().map(_.path.toNIO).toList) val platform: Task[BloopConfig.Platform] = module match { case m: ScalaJSModule => - T.task { + Task.anon { BloopConfig.Platform.Js( BloopConfig.JsConfig.empty.copy( version = m.scalaJSVersion(), @@ -244,7 +244,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { ) } case m: ScalaNativeModule => - T.task { + Task.anon { BloopConfig.Platform.Native( BloopConfig.NativeConfig.empty.copy( version = m.scalaNativeVersion(), @@ -268,10 +268,10 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { ) } case _ => - T.task { + Task.anon { BloopConfig.Platform.Jvm( BloopConfig.JvmConfig( - home = T.env.get("JAVA_HOME").map(s => os.Path(s).toNIO), + home = Task.env.get("JAVA_HOME").map(s => os.Path(s).toNIO), options = { // See https://github.com/scalacenter/bloop/issues/1167 val forkArgs = module.forkArgs().toList @@ -296,7 +296,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { val testConfig = module match { case m: TestModule => - T.task { + Task.anon { Some( BloopConfig.Test( frameworks = Seq(m.testFramework()) @@ -309,7 +309,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { ) ) } - case _ => T.task(None) + case _ => Task.anon(None) } // ////////////////////////////////////////////////////////////////////////// @@ -387,7 +387,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { gatherTask.unsafeRun() } - val bloopResolution: Task[BloopConfig.Resolution] = T.task { + val bloopResolution: Task[BloopConfig.Resolution] = Task.anon { val repos = module.repositoriesTask() // same as input of resolvedIvyDeps val allIvyDeps = module.transitiveIvyDeps() ++ module.transitiveCompileIvyDeps() @@ -399,7 +399,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { // Tying up // ////////////////////////////////////////////////////////////////////////// - val project = T.task { + val project = Task.anon { val mSources = moduleSourceMap() .get(name(module)) .toSeq @@ -434,7 +434,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { ) } - T.task { + Task.anon { BloopConfig.File( version = BloopConfig.File.LatestVersion, project = project() @@ -442,5 +442,5 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule { } } - lazy val millDiscover: Discover[this.type] = Discover[this.type] + val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala b/contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala index 7fcd0b078e5..797e8b7a743 100644 --- a/contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala +++ b/contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala @@ -10,6 +10,8 @@ import os.Path import upickle.default._ import utest._ import bloop.config.Config.Platform.Jvm +import mill.define.Discover + import scala.util.Properties.isWin object BloopTests extends TestSuite { @@ -81,6 +83,7 @@ object BloopTests extends TestSuite { override def skipBloop: Boolean = true } + val millDiscover: Discover[this.type] = Discover[this.type] } def readBloopConf(jsonFile: String) = diff --git a/contrib/buildinfo/src/mill/contrib/buildinfo/BuildInfo.scala b/contrib/buildinfo/src/mill/contrib/buildinfo/BuildInfo.scala index 094f54749ea..6851f93ded3 100644 --- a/contrib/buildinfo/src/mill/contrib/buildinfo/BuildInfo.scala +++ b/contrib/buildinfo/src/mill/contrib/buildinfo/BuildInfo.scala @@ -1,6 +1,6 @@ package mill.contrib.buildinfo -import mill.T +import mill.{Task, T} import mill.api.PathRef import mill.scalalib.{JavaModule, ScalaModule} import mill.scalanativelib.ScalaNativeModule @@ -37,15 +37,15 @@ trait BuildInfo extends JavaModule { def resources: T[Seq[PathRef]] = if (buildInfoStaticCompiled) super.resources - else T.sources { super.resources() ++ Seq(buildInfoResources()) } + else Task.sources { super.resources() ++ Seq(buildInfoResources()) } - def buildInfoResources = T { + def buildInfoResources = Task { val p = new java.util.Properties for (v <- buildInfoMembers()) p.setProperty(v.key, v.value) val subPath = os.SubPath(buildInfoPackageName.replace('.', '/')) val stream = os.write.outputStream( - T.dest / subPath / s"$buildInfoObjectName.buildinfo.properties", + Task.dest / subPath / s"$buildInfoObjectName.buildinfo.properties", createFolders = true ) @@ -54,16 +54,16 @@ trait BuildInfo extends JavaModule { s"mill.contrib.buildinfo.BuildInfo for ${buildInfoPackageName}.${buildInfoObjectName}" ) stream.close() - PathRef(T.dest) + PathRef(Task.dest) } private def isScala = this.isInstanceOf[ScalaModule] - override def generatedSources = T { + override def generatedSources = Task { super.generatedSources() ++ buildInfoSources() } - def buildInfoSources = T { + def buildInfoSources = Task { if (buildInfoMembers().isEmpty) Nil else { val code = if (buildInfoStaticCompiled) BuildInfo.staticCompiledCodegen( @@ -82,11 +82,11 @@ trait BuildInfo extends JavaModule { val ext = if (isScala) "scala" else "java" os.write( - T.dest / buildInfoPackageName.split('.') / s"${buildInfoObjectName}.$ext", + Task.dest / buildInfoPackageName.split('.') / s"${buildInfoObjectName}.$ext", code, createFolders = true ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } } } diff --git a/contrib/buildinfo/test/src/mill/contrib/buildinfo/BuildInfoTests.scala b/contrib/buildinfo/test/src/mill/contrib/buildinfo/BuildInfoTests.scala index 2291242882c..54f73c141d5 100644 --- a/contrib/buildinfo/test/src/mill/contrib/buildinfo/BuildInfoTests.scala +++ b/contrib/buildinfo/test/src/mill/contrib/buildinfo/BuildInfoTests.scala @@ -1,6 +1,7 @@ package mill.contrib.buildinfo import mill._ +import mill.define.Discover import mill.util.TestEvaluator import mill.util.TestUtil import os.Path @@ -20,6 +21,8 @@ object BuildInfoTests extends TestSuite { def scalaVersion = scalaVersionString def buildInfoPackageName = "foo" def buildInfoMembers = Seq.empty[BuildInfo.Value] + + val millDiscover: Discover[this.type] = Discover[this.type] } object BuildInfoPlain extends BuildInfoModule with scalalib.ScalaModule { @@ -28,6 +31,8 @@ object BuildInfoTests extends TestSuite { def buildInfoMembers = Seq( BuildInfo.Value("scalaVersion", scalaVersion()) ) + + val millDiscover: Discover[this.type] = Discover[this.type] } object BuildInfoScalaJS extends BuildInfoModule with scalajslib.ScalaJSModule { @@ -37,6 +42,8 @@ object BuildInfoTests extends TestSuite { def buildInfoMembers = Seq( BuildInfo.Value("scalaVersion", scalaVersion()) ) + + val millDiscover: Discover[this.type] = Discover[this.type] } object BuildInfoComment extends BuildInfoModule with scalalib.ScalaModule { @@ -54,6 +61,8 @@ object BuildInfoTests extends TestSuite { comment = "a helpful comment explaining what scalaVersion\nis all about" ) ) + + val millDiscover: Discover[this.type] = Discover[this.type] } object BuildInfoStatic extends BuildInfoModule with scalalib.ScalaModule { @@ -63,6 +72,8 @@ object BuildInfoTests extends TestSuite { def buildInfoMembers = Seq( BuildInfo.Value("scalaVersion", scalaVersion()) ) + + val millDiscover: Discover[this.type] = Discover[this.type] } object BuildInfoSettings extends BuildInfoModule with scalalib.ScalaModule { @@ -72,6 +83,8 @@ object BuildInfoTests extends TestSuite { def buildInfoMembers = Seq( BuildInfo.Value("scalaVersion", scalaVersion()) ) + + val millDiscover: Discover[this.type] = Discover[this.type] } object BuildInfoJava extends BuildInfoModule { @@ -80,6 +93,8 @@ object BuildInfoTests extends TestSuite { def buildInfoMembers = Seq( BuildInfo.Value("scalaVersion", "not-provided-for-java-modules") ) + + val millDiscover: Discover[this.type] = Discover[this.type] } object BuildInfoJavaStatic extends BuildInfoModule { @@ -89,6 +104,8 @@ object BuildInfoTests extends TestSuite { def buildInfoMembers = Seq( BuildInfo.Value("scalaVersion", "not-provided-for-java-modules") ) + + val millDiscover: Discover[this.type] = Discover[this.type] } val testModuleSourcesPath: Path = @@ -169,7 +186,7 @@ object BuildInfoTests extends TestSuite { "run" - workspaceTest(BuildInfoPlain, "scala") { eval => val runResult = eval.outPath / "hello-mill" val Right((result, evalCount)) = - eval.apply(BuildInfoPlain.run(T.task(Args(runResult.toString)))) + eval.apply(BuildInfoPlain.run(Task.anon(Args(runResult.toString)))) assert( os.exists(runResult), @@ -188,7 +205,7 @@ object BuildInfoTests extends TestSuite { val runResult = eval.outPath / "hello-mill" val Right((result2, evalCount2)) = - eval.apply(BuildInfoStatic.run(T.task(Args(runResult.toString)))) + eval.apply(BuildInfoStatic.run(Task.anon(Args(runResult.toString)))) assert(os.exists(buildInfoSourcePath(eval))) assert(!os.exists(buildInfoResourcePath(eval))) @@ -199,7 +216,7 @@ object BuildInfoTests extends TestSuite { "java" - workspaceTest(BuildInfoJava, "java") { eval => val runResult = eval.outPath / "hello-mill" val Right((result, evalCount)) = - eval.apply(BuildInfoJava.run(T.task(Args(runResult.toString)))) + eval.apply(BuildInfoJava.run(Task.anon(Args(runResult.toString)))) assert( os.exists(runResult), @@ -211,7 +228,7 @@ object BuildInfoTests extends TestSuite { val runResult = eval.outPath / "hello-mill" val generatedSrc = eval.outPath / "buildInfoSources.dest" / "foo" / "BuildInfo.java" val Right((result, evalCount)) = - eval.apply(BuildInfoJavaStatic.run(T.task(Args(runResult.toString)))) + eval.apply(BuildInfoJavaStatic.run(Task.anon(Args(runResult.toString)))) assert( os.exists(runResult), diff --git a/contrib/codeartifact/src/mill/contrib/codeartifact/CodeartifactPublishModule.scala b/contrib/codeartifact/src/mill/contrib/codeartifact/CodeartifactPublishModule.scala index bd1dbd34464..7b3b220f2dd 100644 --- a/contrib/codeartifact/src/mill/contrib/codeartifact/CodeartifactPublishModule.scala +++ b/contrib/codeartifact/src/mill/contrib/codeartifact/CodeartifactPublishModule.scala @@ -17,7 +17,7 @@ trait CodeartifactPublishModule extends PublishModule { readTimeout: Int = 60000, connectTimeout: Int = 5000 ): define.Command[Unit] = - T.command { + Task.command { val PublishModule.PublishData(artifactInfo, artifacts) = publishArtifacts() @@ -27,7 +27,7 @@ trait CodeartifactPublishModule extends PublishModule { credentials, readTimeout, connectTimeout, - T.log + Task.log ).publish(artifacts.map { case (a, b) => (a.path, b) }, artifactInfo) } } @@ -41,8 +41,8 @@ object CodeartifactPublishModule extends ExternalModule { readTimeout: Int = 60000, connectTimeout: Int = 5000 ) = - T.command { - val artifacts = T.sequence(publishArtifacts.value)().map { + Task.command { + val artifacts = Task.sequence(publishArtifacts.value)().map { case data @ PublishModule.PublishData(_, _) => data.withConcretePath } new CodeartifactPublisher( @@ -51,7 +51,7 @@ object CodeartifactPublishModule extends ExternalModule { credentials, readTimeout, connectTimeout, - T.log + Task.log ).publishAll( artifacts: _* ) diff --git a/contrib/docker/src/mill/contrib/docker/DockerModule.scala b/contrib/docker/src/mill/contrib/docker/DockerModule.scala index 90e0c0943f7..548a6cd86f9 100644 --- a/contrib/docker/src/mill/contrib/docker/DockerModule.scala +++ b/contrib/docker/src/mill/contrib/docker/DockerModule.scala @@ -98,7 +98,7 @@ trait DockerModule { outer: JavaModule => */ def executable: T[String] = "docker" - def dockerfile: T[String] = T { + def dockerfile: T[String] = Task { val jarName = assembly().path.last val labelRhs = labels() .map { case (k, v) => @@ -137,7 +137,7 @@ trait DockerModule { outer: JavaModule => |ENTRYPOINT [$quotedEntryPointArgs]""".stripMargin } - private def pullAndHash = T.input { + private def pullAndHash = Task.input { def imageHash() = os.proc(executable(), "images", "--no-trunc", "--quiet", baseImage()) .call(stderr = os.Inherit).out.text().trim @@ -149,15 +149,15 @@ trait DockerModule { outer: JavaModule => (pullBaseImage(), imageHash()) } - final def build = T { - val dest = T.dest + final def build = Task { + val dest = Task.dest val asmPath = outer.assembly().path os.copy(asmPath, dest / asmPath.last) os.write(dest / "Dockerfile", dockerfile()) - val log = T.log + val log = Task.log val tagArgs = tags().flatMap(t => List("-t", t)) @@ -187,7 +187,7 @@ trait DockerModule { outer: JavaModule => tags() } - final def push() = T.command { + final def push() = Task.command { val tags = build() tags.foreach(t => os.proc(executable(), "push", t).call(stdout = os.Inherit, stderr = os.Inherit) diff --git a/contrib/docker/test/src/mill/contrib/docker/DockerModuleTest.scala b/contrib/docker/test/src/mill/contrib/docker/DockerModuleTest.scala index 3fe71603886..d07a13a61e2 100644 --- a/contrib/docker/test/src/mill/contrib/docker/DockerModuleTest.scala +++ b/contrib/docker/test/src/mill/contrib/docker/DockerModuleTest.scala @@ -1,6 +1,7 @@ package mill package contrib.docker +import mill.define.Discover import mill.scalalib.JavaModule import mill.util.{TestEvaluator, TestUtil} import os.Path @@ -41,6 +42,8 @@ object DockerModuleTest extends TestSuite { override def executable = testExecutable override def jvmOptions = Seq("-Xmx1024M") } + + val millDiscover: Discover[this.type] = Discover[this.type] } val testArtifactName = "mill-docker-contrib-test" diff --git a/contrib/flyway/readme.adoc b/contrib/flyway/readme.adoc index e1f6e85cec9..daf3677242c 100644 --- a/contrib/flyway/readme.adoc +++ b/contrib/flyway/readme.adoc @@ -40,4 +40,4 @@ mill foo.flywayMigrate CAUTION: You should never hard-code credentials or check them into a version control system. You should write some code to populate the settings for flyway instead. -For example `def flywayPassword = T.input(T.ctx.env("FLYWAY_PASSWORD"))` +For example `def flywayPassword = Task.input(Task.ctx.env("FLYWAY_PASSWORD"))` diff --git a/contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala b/contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala index d8202c58342..4a586be0d42 100644 --- a/contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala +++ b/contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala @@ -10,7 +10,7 @@ import org.flywaydb.core.internal.configuration.{ConfigUtils => flyway} import org.flywaydb.core.internal.info.MigrationInfoDumper import scala.jdk.CollectionConverters._ -import mill.{Agg, T} +import mill.{Agg, T, Task} import mill.api.PathRef import mill.define.Command import mill.scalalib.{Dep, JavaModule} @@ -22,13 +22,13 @@ trait FlywayModule extends JavaModule { def flywayUrl: T[String] def flywayUser: T[String] = T("") def flywayPassword: T[String] = T("") - def flywayFileLocations: T[Seq[PathRef]] = T { + def flywayFileLocations: T[Seq[PathRef]] = Task { resources().map(pr => PathRef(pr.path / "db" / "migration", pr.quick)) } def flywayDriverDeps: T[Agg[Dep]] - def jdbcClasspath = T { + def jdbcClasspath = Task { defaultResolver().resolveDeps(flywayDriverDeps()) } @@ -37,7 +37,7 @@ trait FlywayModule extends JavaModule { .filter(_.nonEmpty) .map(key -> _) - def flywayInstance = T.worker { + def flywayInstance = Task.worker { val jdbcClassloader = new URLClassLoader(jdbcClasspath().map(_.path.toIO.toURI.toURL).toArray) val configProps = Map(flyway.URL -> flywayUrl()) ++ @@ -53,19 +53,19 @@ trait FlywayModule extends JavaModule { .load } - def flywayMigrate(): Command[MigrateResult] = T.command { + def flywayMigrate(): Command[MigrateResult] = Task.command { flywayInstance().migrate() } - def flywayClean(): Command[CleanResult] = T.command { + def flywayClean(): Command[CleanResult] = Task.command { flywayInstance().clean() } - def flywayBaseline(): Command[BaselineResult] = T.command { + def flywayBaseline(): Command[BaselineResult] = Task.command { flywayInstance().baseline() } - def flywayInfo(): Command[String] = T.command { + def flywayInfo(): Command[String] = Task.command { val info = flywayInstance().info val current = info.current val currentSchemaVersion = @@ -74,7 +74,7 @@ trait FlywayModule extends JavaModule { val out = s"""Schema version: ${currentSchemaVersion} |${MigrationInfoDumper.dumpToAsciiTable(info.all)}""".stripMargin - T.log.outputStream.println(out) + Task.log.outputStream.println(out) out } } diff --git a/contrib/flyway/test/src/mill/contrib/flyway/BuildTest.scala b/contrib/flyway/test/src/mill/contrib/flyway/BuildTest.scala index a7022941ff2..624f09a123b 100644 --- a/contrib/flyway/test/src/mill/contrib/flyway/BuildTest.scala +++ b/contrib/flyway/test/src/mill/contrib/flyway/BuildTest.scala @@ -1,6 +1,7 @@ package mill.contrib.flyway import mill._ +import mill.define.Discover import mill.scalalib._ import mill.util.{TestEvaluator, TestUtil} import utest.{TestSuite, Tests, assert, _} @@ -9,13 +10,15 @@ object BuildTest extends TestSuite { object Build extends TestUtil.BaseModule { object build extends FlywayModule { - override def resources = T.sources(os.pwd / "contrib" / "flyway" / "test" / "resources") + override def resources = Task.sources(os.pwd / "contrib" / "flyway" / "test" / "resources") def h2 = ivy"com.h2database:h2:2.1.214" def flywayUrl = "jdbc:h2:mem:test_db;DB_CLOSE_DELAY=-1" def flywayDriverDeps = Agg(h2) } + + val millDiscover: Discover[this.type] = Discover[this.type] } def tests = Tests { diff --git a/contrib/gitlab/readme.adoc b/contrib/gitlab/readme.adoc index f188f58932d..43c3256e1a2 100644 --- a/contrib/gitlab/readme.adoc +++ b/contrib/gitlab/readme.adoc @@ -54,7 +54,7 @@ personal access token, then deploy token and lastly ci job token. Default search . Workspace file `.gitlab/deploy-token` . Environment variable `CI_JOB_TOKEN` -Items 1-4 are *personal access tokens*, 5-8 *deploy tokens* and 9 is *job token*. Workspace in items 4 and 8 refers to directory where `build.sc` is (`T.workspace` in mill terms). +Items 1-4 are *personal access tokens*, 5-8 *deploy tokens* and 9 is *job token*. Workspace in items 4 and 8 refers to directory where `build.sc` is (`Task.workspace` in mill terms). Because contents of `$CI_JOB_TOKEN` is checked publishing should just work when run in Gitlab CI/CD pipeline. If you want something else than default lookup configuration can be overridden. There are different ways of configuring token resolving. @@ -127,9 +127,9 @@ import mill.api.Result.Success override def gitlabHeaders( props: Map[String, String] // System properties - ): Task[GitlabAuthHeaders] = T.task { + ): Task[GitlabAuthHeaders] = Task.anon { // This uses default lookup and ads custom headers - val access = tokenLookup.resolveGitlabToken(T.env, props, T.workspace) + val access = tokenLookup.resolveGitlabToken(Task.env, props, Task.workspace) val accessHeader = access.fold(_ => Seq.empty[(String, String)], _.headers) Success( GitlabAuthHeaders( @@ -162,7 +162,7 @@ import $ivy.`com.lihaoyi::mill-contrib-gitlab:` import mill.contrib.gitlab._ // DON'T DO THIS -def repositoriesTask = T.task { +def repositoriesTask = Task.anon { super.repositoriesTask() ++ Seq( MavenRepository("https://gitlab.local/api/v4/projects/42/packages/maven", Some(Authentication(Seq(("Private-Token", "<>")))))) @@ -184,7 +184,7 @@ object myPackageRepository extends GitlabMavenRepository { } object myModule extends ScalaModule { - def repositoriesTask = T.task { + def repositoriesTask = Task.anon { super.repositoriesTask() ++ Seq( MavenRepository("https://oss.sonatype.org/content/repositories/releases"), diff --git a/contrib/gitlab/src/mill/contrib/gitlab/GitlabMavenRepository.scala b/contrib/gitlab/src/mill/contrib/gitlab/GitlabMavenRepository.scala index 8ac1907a4f1..d36ff35bb94 100644 --- a/contrib/gitlab/src/mill/contrib/gitlab/GitlabMavenRepository.scala +++ b/contrib/gitlab/src/mill/contrib/gitlab/GitlabMavenRepository.scala @@ -2,19 +2,18 @@ package mill.contrib.gitlab import coursier.core.Authentication import coursier.maven.MavenRepository -import mill.T +import mill.{Task, T} import mill.api.Result import mill.api.Result.{Failure, Success} -import mill.define.Task trait GitlabMavenRepository { def tokenLookup: GitlabTokenLookup = new GitlabTokenLookup {} // For token discovery def gitlabRepository: GitlabPackageRepository // For package discovery - def mavenRepository: Task[MavenRepository] = T.task { + def mavenRepository: Task[MavenRepository] = Task.anon { - val gitlabAuth = tokenLookup.resolveGitlabToken(T.env, sys.props.toMap, T.workspace) + val gitlabAuth = tokenLookup.resolveGitlabToken(Task.env, sys.props.toMap, Task.workspace) .map(auth => Authentication(auth.headers)) .map(auth => MavenRepository(gitlabRepository.url(), Some(auth))) diff --git a/contrib/gitlab/src/mill/contrib/gitlab/GitlabPublishModule.scala b/contrib/gitlab/src/mill/contrib/gitlab/GitlabPublishModule.scala index 2efd3035ba6..8ed37acaf62 100644 --- a/contrib/gitlab/src/mill/contrib/gitlab/GitlabPublishModule.scala +++ b/contrib/gitlab/src/mill/contrib/gitlab/GitlabPublishModule.scala @@ -16,8 +16,8 @@ trait GitlabPublishModule extends PublishModule { outer => def gitlabHeaders( systemProps: Map[String, String] = sys.props.toMap - ): Task[GitlabAuthHeaders] = T.task { - val auth = tokenLookup.resolveGitlabToken(T.env, systemProps, T.workspace) + ): Task[GitlabAuthHeaders] = Task.anon { + val auth = tokenLookup.resolveGitlabToken(Task.env, systemProps, Task.workspace) auth match { case Left(msg) => Failure( @@ -30,19 +30,19 @@ trait GitlabPublishModule extends PublishModule { outer => def publishGitlab( readTimeout: Int = 60000, connectTimeout: Int = 5000 - ): define.Command[Unit] = T.command { + ): define.Command[Unit] = Task.command { val gitlabRepo = publishRepository val PublishModule.PublishData(artifactInfo, artifacts) = publishArtifacts() if (skipPublish) { - T.log.info(s"SkipPublish = true, skipping publishing of $artifactInfo") + Task.log.info(s"SkipPublish = true, skipping publishing of $artifactInfo") } else { val uploader = new GitlabUploader(gitlabHeaders()(), readTimeout, connectTimeout) new GitlabPublisher( uploader.upload, gitlabRepo, - T.log + Task.log ).publish(artifacts.map { case (a, b) => (a.path, b) }, artifactInfo) } @@ -58,11 +58,11 @@ object GitlabPublishModule extends ExternalModule { publishArtifacts: mill.main.Tasks[PublishModule.PublishData], readTimeout: Int = 60000, connectTimeout: Int = 5000 - ): Command[Unit] = T.command { + ): Command[Unit] = Task.command { val repo = ProjectRepository(gitlabRoot, projectId) val auth = GitlabAuthHeaders.privateToken(personalToken) - val artifacts = T.sequence(publishArtifacts.value)().map { + val artifacts = Task.sequence(publishArtifacts.value)().map { case data @ PublishModule.PublishData(_, _) => data.withConcretePath } val uploader = new GitlabUploader(auth, readTimeout, connectTimeout) @@ -70,7 +70,7 @@ object GitlabPublishModule extends ExternalModule { new GitlabPublisher( uploader.upload, repo, - T.log + Task.log ).publishAll( artifacts: _* ) diff --git a/contrib/gitlab/test/src/mill/contrib/gitlab/GitlabModuleTests.scala b/contrib/gitlab/test/src/mill/contrib/gitlab/GitlabModuleTests.scala index e583fb8abde..22a494f9420 100644 --- a/contrib/gitlab/test/src/mill/contrib/gitlab/GitlabModuleTests.scala +++ b/contrib/gitlab/test/src/mill/contrib/gitlab/GitlabModuleTests.scala @@ -1,7 +1,8 @@ package mill.contrib.gitlab -import mill.T +import mill.{T, Task} import mill.api.Result.Failure +import mill.define.Discover import mill.scalalib.publish.PomSettings import mill.util.{TestEvaluator, TestUtil} import utest.framework.TestPath @@ -23,6 +24,8 @@ object GitlabModuleTests extends TestSuite { override def publishVersion: T[String] = "0.0.1" override def tokenLookup: GitlabTokenLookup = emptyLookup + + val millDiscover: Discover[this.type] = Discover[this.type] } // GitlabMavenRepository does not need to be a module, but it needs to be invoked from one. @@ -32,6 +35,8 @@ object GitlabModuleTests extends TestSuite { InstanceRepository("https://gl.local") override def tokenLookup = emptyLookup + + val millDiscover: Discover[this.type] = Discover[this.type] } def testModule[T]( diff --git a/contrib/jmh/src/mill/contrib/jmh/JmhModule.scala b/contrib/jmh/src/mill/contrib/jmh/JmhModule.scala index d950fe586c7..6923ba832a3 100644 --- a/contrib/jmh/src/mill/contrib/jmh/JmhModule.scala +++ b/contrib/jmh/src/mill/contrib/jmh/JmhModule.scala @@ -36,22 +36,22 @@ trait JmhModule extends JavaModule { def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.openjdk.jmh:jmh-core:${jmhCoreVersion()}") def runJmh(args: String*) = - T.command { + Task.command { val (_, resources) = generateBenchmarkSources() Jvm.runSubprocess( "org.openjdk.jmh.Main", classPath = (runClasspath() ++ generatorDeps()).map(_.path) ++ Seq(compileGeneratedSources().path, resources), mainArgs = args, - workingDir = T.ctx().dest + workingDir = Task.ctx().dest ) } def listJmhBenchmarks(args: String*) = runJmh(("-l" +: args): _*) def compileGeneratedSources = - T { - val dest = T.ctx().dest + Task { + val dest = Task.ctx().dest val (sourcesDir, _) = generateBenchmarkSources() val sources = os.walk(sourcesDir).filter(os.isFile) @@ -70,8 +70,8 @@ trait JmhModule extends JavaModule { // returns sources and resources directories def generateBenchmarkSources = - T { - val dest = T.ctx().dest + Task { + val dest = Task.ctx().dest val sourcesDir = dest / "jmh_sources" val resourcesDir = dest / "jmh_resources" @@ -95,7 +95,7 @@ trait JmhModule extends JavaModule { (sourcesDir, resourcesDir) } - def generatorDeps = T { + def generatorDeps = Task { defaultResolver().resolveDeps( Agg(ivy"org.openjdk.jmh:jmh-generator-bytecode:${jmhGeneratorByteCodeVersion()}") ) diff --git a/contrib/jmh/test/src/mill/contrib/jmh/JmhModuleTest.scala b/contrib/jmh/test/src/mill/contrib/jmh/JmhModuleTest.scala index fb944fee27e..a425a65003a 100644 --- a/contrib/jmh/test/src/mill/contrib/jmh/JmhModuleTest.scala +++ b/contrib/jmh/test/src/mill/contrib/jmh/JmhModuleTest.scala @@ -1,6 +1,7 @@ package mill package contrib.jmh +import mill.define.Discover import mill.eval.EvaluatorPaths import mill.scalalib.ScalaModule import mill.util.{TestEvaluator, TestUtil} @@ -15,6 +16,8 @@ object JmhModuleTest extends TestSuite { override def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) override def jmhCoreVersion = "1.35" override def millSourcePath = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.') + + val millDiscover: Discover[this.type] = Discover[this.type] } val testModuleSourcesPath: Path = diff --git a/contrib/playlib/readme.adoc b/contrib/playlib/readme.adoc index eb567faa77a..5b2cdff2d4e 100644 --- a/contrib/playlib/readme.adoc +++ b/contrib/playlib/readme.adoc @@ -43,8 +43,8 @@ import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._ object core extends PlayModule { // config - override def scalaVersion = T { "2.13.12" } - override def playVersion = T { "2.8.20" } + override def scalaVersion = Task { "2.13.12" } + override def playVersion = Task { "2.8.20" } object test extends PlayTests } @@ -117,8 +117,8 @@ import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._ object core extends PlayApiModule { // config - override def scalaVersion = T { "2.13.12" } - override def playVersion = T { "2.8.20" } + override def scalaVersion = Task { "2.13.12" } + override def playVersion = Task { "2.8.20" } object test extends PlayTests } @@ -154,12 +154,12 @@ import $ivy.`com.lihaoyi::mill-contrib-playlib:$MILL_VERSION`, mill.playlib._ object core extends PlayApiModule { // config - override def scalaVersion = T{ "2.13.12" } - override def playVersion = T{ "2.8.20" } + override def scalaVersion = Task { "2.13.12" } + override def playVersion = Task { "2.8.20" } object test extends PlayTests - override def ivyDeps = T{ super.ivyDeps() ++ Agg(ws(), filters()) } + override def ivyDeps = Task { super.ivyDeps() ++ Agg(ws(), filters()) } } ---- @@ -195,8 +195,8 @@ import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._ object core extends PlayModule { // config - override def scalaVersion = T { "2.13.12" } - override def playVersion = T { "2.8.20" } + override def scalaVersion = Task { "2.13.12" } + override def playVersion = Task { "2.8.20" } object test extends PlayTests } @@ -235,8 +235,8 @@ import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._ object root extends RootModule with PlayModule { // config - override def scalaVersion = T { "2.13.12" } - override def playVersion = T { "2.8.20" } + override def scalaVersion = Task { "2.13.12" } + override def playVersion = Task { "2.8.20" } object test extends PlayTests } @@ -277,8 +277,8 @@ import mill._ import $ivy.`com.lihaoyi::mill-contrib-playlib:`, mill.playlib._ object app extends ScalaModule with RouterModule { - def playVersion = T{ "2.8.20" } - def scalaVersion = T { "2.13.12" } + def playVersion = Task { "2.8.20" } + def scalaVersion = Task { "2.13.12" } } ---- diff --git a/contrib/playlib/src/mill/playlib/Dependencies.scala b/contrib/playlib/src/mill/playlib/Dependencies.scala index a91503498ff..dc1b8a49599 100644 --- a/contrib/playlib/src/mill/playlib/Dependencies.scala +++ b/contrib/playlib/src/mill/playlib/Dependencies.scala @@ -1,20 +1,20 @@ package mill.playlib -import mill.{Agg, T} +import mill.{Agg, T, Task} import mill.scalalib._ private[playlib] trait Dependencies extends ScalaModule with Version { - def core = T { component("play") } - def guice = T { component("play-guice") } - def server = T { component("play-server") } - def logback = T { component("play-logback") } - def evolutions = T { component("play-jdbc-evolutions") } - def jdbc = T { component("play-jdbc") } - def filters = T { component("filters-helpers") } - def ws = T { component("play-ahc-ws") } - def caffeine = T { component("play-caffeine-cache") } + def core = Task { component("play")() } + def guice = Task { component("play-guice")() } + def server = Task { component("play-server")() } + def logback = Task { component("play-logback")() } + def evolutions = Task { component("play-jdbc-evolutions")() } + def jdbc = Task { component("play-jdbc")() } + def filters = Task { component("filters-helpers")() } + def ws = Task { component("play-ahc-ws")() } + def caffeine = Task { component("play-caffeine-cache")() } - override def ivyDeps = T { + override def ivyDeps = Task { super.ivyDeps() ++ Agg( core(), guice(), diff --git a/contrib/playlib/src/mill/playlib/Layout.scala b/contrib/playlib/src/mill/playlib/Layout.scala index 54a7a08b07e..7c2cd9008bc 100644 --- a/contrib/playlib/src/mill/playlib/Layout.scala +++ b/contrib/playlib/src/mill/playlib/Layout.scala @@ -1,13 +1,13 @@ package mill.playlib -import mill.T +import mill.{Task, T} import mill.scalalib._ private[playlib] trait Layout extends JavaModule { - def conf = T.sources { millSourcePath / "conf" } - def app = T.sources { millSourcePath / "app" } + def conf = Task.sources { millSourcePath / "conf" } + def app = Task.sources { millSourcePath / "app" } - override def sources = T.sources { app() } - override def resources = T.sources { conf() } + override def sources = Task.sources { app() } + override def resources = Task.sources { conf() } } diff --git a/contrib/playlib/src/mill/playlib/PlayModule.scala b/contrib/playlib/src/mill/playlib/PlayModule.scala index 9984dde87c2..11820d5c2b5 100644 --- a/contrib/playlib/src/mill/playlib/PlayModule.scala +++ b/contrib/playlib/src/mill/playlib/PlayModule.scala @@ -1,13 +1,12 @@ package mill.playlib -import mill.define.Task import mill.playlib.api.Versions import mill.scalalib._ -import mill.{Agg, Args, T} +import mill.{Agg, Args, T, Task} trait PlayApiModule extends Dependencies with Router with Server { trait PlayTests extends ScalaTests with TestModule.ScalaTest { - override def ivyDeps = T { + override def ivyDeps = Task { val scalatestPlusPlayVersion = playMinorVersion() match { case Versions.PLAY_2_6 => "3.1.3" case Versions.PLAY_2_7 => "4.0.3" @@ -17,14 +16,14 @@ trait PlayApiModule extends Dependencies with Router with Server { } Agg(ivy"org.scalatestplus.play::scalatestplus-play::${scalatestPlusPlayVersion}") } - override def sources = T.sources { millSourcePath } + override def sources = Task.sources { millSourcePath } } - def start(args: Task[Args] = T.task(Args())) = T.command { run(args) } + def start(args: Task[Args] = Task.anon(Args())) = Task.command { run(args)() } } trait PlayModule extends PlayApiModule with Static with Twirl { - override def twirlVersion = T { + override def twirlVersion = Task { playMinorVersion() match { case "2.6" => "1.3.16" case "2.7" => "1.4.2" diff --git a/contrib/playlib/src/mill/playlib/RouteCompilerWorker.scala b/contrib/playlib/src/mill/playlib/RouteCompilerWorker.scala index a093a2aa5db..41480ea82ba 100644 --- a/contrib/playlib/src/mill/playlib/RouteCompilerWorker.scala +++ b/contrib/playlib/src/mill/playlib/RouteCompilerWorker.scala @@ -3,7 +3,7 @@ package mill.playlib import mill.api.{Ctx, PathRef, Result} import mill.playlib.api.{RouteCompilerType, RouteCompilerWorkerApi} import mill.scalalib.api.CompilationResult -import mill.{Agg, T} +import mill.{Agg, T, Task} private[playlib] class RouteCompilerWorker extends AutoCloseable { @@ -58,7 +58,7 @@ private[playlib] class RouteCompilerWorker extends AutoCloseable { dest.toIO ) match { case null => - Result.Success(CompilationResult(T.dest / "zinc", PathRef(T.dest))) + Result.Success(CompilationResult(Task.dest / "zinc", PathRef(Task.dest))) case err => Result.Failure(err) } } diff --git a/contrib/playlib/src/mill/playlib/RouteCompilerWorkerModule.scala b/contrib/playlib/src/mill/playlib/RouteCompilerWorkerModule.scala index b4928e6b35a..c3ca9794a17 100644 --- a/contrib/playlib/src/mill/playlib/RouteCompilerWorkerModule.scala +++ b/contrib/playlib/src/mill/playlib/RouteCompilerWorkerModule.scala @@ -1,10 +1,10 @@ package mill.playlib -import mill.{Module, T} +import mill.{Module, T, Task} import mill.define.{Discover, ExternalModule, Worker} trait RouteCompilerWorkerModule extends Module { - def routeCompilerWorker: Worker[RouteCompilerWorker] = T.worker { + def routeCompilerWorker: Worker[RouteCompilerWorker] = Task.worker { new RouteCompilerWorker() } } @@ -12,5 +12,5 @@ trait RouteCompilerWorkerModule extends Module { private[playlib] object RouteCompilerWorkerModule extends ExternalModule with RouteCompilerWorkerModule { - lazy val millDiscover: Discover[this.type] = Discover[this.type] + val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/contrib/playlib/src/mill/playlib/Router.scala b/contrib/playlib/src/mill/playlib/Router.scala index 411bdb39fb7..db1fe5c0ef6 100644 --- a/contrib/playlib/src/mill/playlib/Router.scala +++ b/contrib/playlib/src/mill/playlib/Router.scala @@ -1,7 +1,7 @@ package mill.playlib -import mill.T +import mill.{Task, T} private[playlib] trait Router extends RouterModule with Layout { - override def routes = T { conf() } + override def routes = Task { conf() } } diff --git a/contrib/playlib/src/mill/playlib/RouterModule.scala b/contrib/playlib/src/mill/playlib/RouterModule.scala index a89e21ef453..d8113c76a73 100644 --- a/contrib/playlib/src/mill/playlib/RouterModule.scala +++ b/contrib/playlib/src/mill/playlib/RouterModule.scala @@ -5,13 +5,13 @@ import mill.util.Util.millProjectModule import mill.playlib.api.RouteCompilerType import mill.scalalib._ import mill.scalalib.api._ -import mill.{Agg, T} +import mill.{Agg, T, Task} trait RouterModule extends ScalaModule with Version { - def routes: T[Seq[PathRef]] = T.sources { millSourcePath / "routes" } + def routes: T[Seq[PathRef]] = Task.sources { millSourcePath / "routes" } - def routeFiles = T { + def routeFiles = Task { val paths = routes().flatMap(file => os.walk(file.path)) val routeFiles = paths.filter(_.ext == "routes") ++ paths.filter(_.last == "routes") routeFiles.map(f => PathRef(f)) @@ -45,7 +45,7 @@ trait RouterModule extends ScalaModule with Version { */ def generatorType: RouteCompilerType = RouteCompilerType.InjectedGenerator - def routerClasspath: T[Agg[PathRef]] = T { + def routerClasspath: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps( playMinorVersion() match { case "2.6" | "2.7" | "2.8" => @@ -60,8 +60,8 @@ trait RouterModule extends ScalaModule with Version { protected val routeCompilerWorker: RouteCompilerWorkerModule = RouteCompilerWorkerModule - def compileRouter: T[CompilationResult] = T.persistent { - T.log.debug(s"compiling play routes with ${playVersion()} worker") + def compileRouter: T[CompilationResult] = Task.persistent { + Task.log.debug(s"compiling play routes with ${playVersion()} worker") routeCompilerWorker.routeCompilerWorker().compile( routerClasspath = playRouterToolsClasspath(), files = routeFiles().map(_.path), @@ -70,11 +70,11 @@ trait RouterModule extends ScalaModule with Version { reverseRouter = generateReverseRouter, namespaceReverseRouter = namespaceReverseRouter, generatorType = generatorType, - dest = T.dest + dest = Task.dest ) } - def playRouteCompilerWorkerClasspath = T { + def playRouteCompilerWorkerClasspath = Task { millProjectModule( s"mill-contrib-playlib-worker-${playMinorVersion()}", repositoriesTask(), @@ -85,15 +85,15 @@ trait RouterModule extends ScalaModule with Version { ) } - def playRouterToolsClasspath = T { + def playRouterToolsClasspath = Task { playRouteCompilerWorkerClasspath() ++ routerClasspath() } - def routerClasses = T { + def routerClasses = Task { Seq(compileRouter().classes) } - override def generatedSources = T { + override def generatedSources = Task { super.generatedSources() ++ routerClasses() } } diff --git a/contrib/playlib/src/mill/playlib/Server.scala b/contrib/playlib/src/mill/playlib/Server.scala index 66947e0e0eb..7cb0be3857c 100644 --- a/contrib/playlib/src/mill/playlib/Server.scala +++ b/contrib/playlib/src/mill/playlib/Server.scala @@ -1,26 +1,26 @@ package mill.playlib import mill.scalalib._ -import mill.{Agg, T} +import mill.{Agg, T, Task} private[playlib] trait Server extends ScalaModule with Version { - def nettyServer = T { component("play-netty-server") } + def nettyServer = Task { component("play-netty-server")() } - def akkaHttpServer = T { component("play-akka-http-server") } + def akkaHttpServer = Task { component("play-akka-http-server")() } - def pekkoHttpServer = T { component("play-pekko-http-server") } + def pekkoHttpServer = Task { component("play-pekko-http-server")() } - def playServerProvider = T { + def playServerProvider = Task { if (playVersion().startsWith("2.")) akkaHttpServer() else pekkoHttpServer() } - override def runIvyDeps = T { + override def runIvyDeps = Task { super.runIvyDeps() ++ Agg(playServerProvider()) } - override def mainClass = T { Some("play.core.server.ProdServerStart") } + override def mainClass = Task { Some("play.core.server.ProdServerStart") } } diff --git a/contrib/playlib/src/mill/playlib/Static.scala b/contrib/playlib/src/mill/playlib/Static.scala index fe6e9ccd259..b3d15143c04 100644 --- a/contrib/playlib/src/mill/playlib/Static.scala +++ b/contrib/playlib/src/mill/playlib/Static.scala @@ -6,32 +6,32 @@ import java.nio.file.attribute.BasicFileAttributes import java.util import mill.scalalib.{Lib, ScalaModule} -import mill.{PathRef, T} +import mill.{PathRef, T, Task} trait Static extends ScalaModule { /** * project resources including configuration, webjars and static assets */ - override def resources = T.sources { + override def resources = Task.sources { super.resources() :+ webJarResources() :+ staticAssets() } /** * Resource base path of packaged assets (path they will appear in in the jar) */ - def assetsPath = T { "public" } + def assetsPath = Task { "public" } /** * Directories to include assets from */ - def assetSources = T.sources { millSourcePath / assetsPath() } + def assetSources = Task.sources { millSourcePath / assetsPath() } /* Collected static assets for the project */ - def staticAssets = T { - val toPath = os.Path(assetsPath(), T.dest) + def staticAssets = Task { + val toPath = os.Path(assetsPath(), Task.dest) assetSources().foreach { pathRef => val fromPath = pathRef.path if (os.isDir(fromPath)) { @@ -40,20 +40,20 @@ trait Static extends ScalaModule { } } } - PathRef(T.dest) + PathRef(Task.dest) } /** * webjar dependencies - created from transitive ivy deps */ - def webJarDeps = T { + def webJarDeps = Task { transitiveIvyDeps().filter(_.dep.module.organization.value == "org.webjars") } /** * jar files of web jars */ - def webJars = T { + def webJars = Task { Lib.resolveDependencies( repositoriesTask(), webJarDeps() @@ -63,9 +63,9 @@ trait Static extends ScalaModule { /** * webjar resources extracted from their source jars with version from path removed */ - def webJarResources = T { - extractWebJars(webJars().toSeq, os.Path(assetsPath(), T.dest) / "lib") - PathRef(T.dest) + def webJarResources = Task { + extractWebJars(webJars().toSeq, os.Path(assetsPath(), Task.dest) / "lib") + PathRef(Task.dest) } private def extractWebJars(jars: Seq[PathRef], webJarBase: os.Path): Unit = { diff --git a/contrib/playlib/src/mill/playlib/Twirl.scala b/contrib/playlib/src/mill/playlib/Twirl.scala index d8fffc0b03a..7c8f71a5abd 100644 --- a/contrib/playlib/src/mill/playlib/Twirl.scala +++ b/contrib/playlib/src/mill/playlib/Twirl.scala @@ -1,13 +1,13 @@ package mill.playlib -import mill.T +import mill.{Task, T} import mill.twirllib._ trait Twirl extends TwirlModule with Layout { - override def twirlSources = T.sources { app() } + override def twirlSources = Task.sources { app() } - override def twirlImports = T { + override def twirlImports = Task { super.twirlImports() ++ Seq( "models._", "controllers._", @@ -19,9 +19,9 @@ trait Twirl extends TwirlModule with Layout { ) } - def twirlOutput = T { Seq(compileTwirl().classes) } + def twirlOutput = Task { Seq(compileTwirl().classes) } - override def generatedSources = T { + override def generatedSources = Task { super.generatedSources() ++ twirlOutput() } } diff --git a/contrib/playlib/src/mill/playlib/Version.scala b/contrib/playlib/src/mill/playlib/Version.scala index d70ae9ae726..0758476bd9e 100644 --- a/contrib/playlib/src/mill/playlib/Version.scala +++ b/contrib/playlib/src/mill/playlib/Version.scala @@ -1,6 +1,6 @@ package mill.playlib -import mill.T +import mill.{Task, T} import mill.define.Module import mill.scalalib._ @@ -8,15 +8,15 @@ private[playlib] trait Version extends Module { def playVersion: T[String] - private[playlib] def playMinorVersion: T[String] = T { + private[playlib] def playMinorVersion: T[String] = Task { playVersion().split('.').take(2).mkString(".") } - private[playlib] def playOrganization: T[String] = T.task { + private[playlib] def playOrganization: T[String] = Task { if (playVersion().startsWith("2.")) "com.typesafe.play" else "org.playframework" } - private[playlib] def component(id: String) = T.task { + private[playlib] def component(id: String) = Task.anon { ivy"${playOrganization()}::$id::${playVersion()}" } } diff --git a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala index 94b97961334..c0a8e8d7755 100644 --- a/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlayModuleTests.scala @@ -1,6 +1,7 @@ package mill package playlib +import mill.define.Discover import mill.util.TestUtil.{test => _, _} import utest.{TestSuite, Tests, assert, _} @@ -13,8 +14,10 @@ object PlayModuleTests extends TestSuite with PlayTestSuite { override def playVersion = crossPlayVersion override def scalaVersion = crossScalaVersion object test extends PlayTests - override def ivyDeps = T { super.ivyDeps() ++ Agg(ws()) } + override def ivyDeps = Task { super.ivyDeps() ++ Agg(ws()) } } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath: os.Path = os.pwd / "contrib" / "playlib" / "test" / "resources" / "playmulti" diff --git a/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala index a76becc7837..afcefce8381 100644 --- a/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlaySingleApiModuleTests.scala @@ -1,15 +1,18 @@ package mill.playlib -import mill.T +import mill.define.Discover +import mill.{T, Task} import mill.util.TestUtil -import utest.{TestSuite, Tests, assert, _} +import utest._ object PlaySingleApiModuleTests extends TestSuite with PlayTestSuite { object playsingleapi extends TestUtil.BaseModule with PlayApiModule with SingleModule { - override def playVersion = T { testPlay28 } - override def scalaVersion = T { "2.13.12" } + override def playVersion = Task { testPlay28 } + override def scalaVersion = Task { "2.13.12" } object test extends PlayTests + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath: os.Path = diff --git a/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala b/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala index 5a413b6f896..588659e379f 100644 --- a/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/PlaySingleModuleTests.scala @@ -1,15 +1,18 @@ package mill.playlib -import mill.T +import mill.define.Discover +import mill.{T, Task} import mill.util.TestUtil -import utest.{TestSuite, Tests, assert, _} +import utest._ object PlaySingleModuleTests extends TestSuite with PlayTestSuite { object playsingle extends TestUtil.BaseModule with PlayModule with SingleModule { - override def playVersion = T { testPlay28 } - override def scalaVersion = T { sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) } + override def playVersion = Task { testPlay28 } + override def scalaVersion = Task { sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) } object test extends PlayTests + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath: os.Path = os.pwd / "contrib" / "playlib" / "test" / "resources" / "playsingle" diff --git a/contrib/playlib/test/src/mill/playlib/RouterModuleTests.scala b/contrib/playlib/test/src/mill/playlib/RouterModuleTests.scala index 84b543c570a..9b8bfa7e9ed 100644 --- a/contrib/playlib/test/src/mill/playlib/RouterModuleTests.scala +++ b/contrib/playlib/test/src/mill/playlib/RouterModuleTests.scala @@ -1,7 +1,7 @@ package mill.playlib import mill.api.Result.Failure -import mill.define.Cross +import mill.define.{Cross, Discover} import mill.scalalib.ScalaModule import mill.util.TestUtil import utest.{TestSuite, Tests, assert, _} @@ -23,6 +23,8 @@ object RouterModuleTests extends TestSuite with PlayTestSuite { def playVersion = crossValue2 } + val millDiscover: Discover[this.type] = Discover[this.type] + } val resourcePath: os.Path = os.pwd / "contrib" / "playlib" / "test" / "resources" / "hello-world" diff --git a/contrib/playlib/worker/src-shared/mill/playlib/worker/RouteCompilerWorkerBase.scala b/contrib/playlib/worker/src-shared/mill/playlib/worker/RouteCompilerWorkerBase.scala index 5e63d242dfa..7c0bf03f178 100644 --- a/contrib/playlib/worker/src-shared/mill/playlib/worker/RouteCompilerWorkerBase.scala +++ b/contrib/playlib/worker/src-shared/mill/playlib/worker/RouteCompilerWorkerBase.scala @@ -67,8 +67,8 @@ protected[playlib] class RouteCompilerWorkerBase extends RouteCompilerWorkerApi ) ).foldLeft(seed) { case (Right(accFiles), Right(files)) => Right(accFiles ++ files) - case (Right(accFiles), Left(errors)) => Left(errors) - case (left @ Left(errors), _) => left + case (Right(_), Left(errors)) => Left(errors) + case (left @ Left(_), _) => left } } diff --git a/contrib/proguard/readme.adoc b/contrib/proguard/readme.adoc index ff429ad16cf..4ed395f8c40 100644 --- a/contrib/proguard/readme.adoc +++ b/contrib/proguard/readme.adoc @@ -25,15 +25,15 @@ import contrib.proguard._ object foo extends ScalaModule with Proguard { def scalaVersion = "2.13.8" - override def shrink: T[Boolean] = T { true } - override def optimize: T[Boolean] = T { false } - override def obfuscate: T[Boolean] = T { false } + override def shrink: T[Boolean] = Task { true } + override def optimize: T[Boolean] = Task { false } + override def obfuscate: T[Boolean] = Task { false } // https://github.com/Guardsquare/proguard/releases override def proguardVersion = T("7.3.2") // tell Proguard where to enter your app, so it can optimise outwards from there - override def entryPoint = T { + override def entryPoint = Task { s"""|-keep public class myProject.main.myApp { | public ReturnType main(ParamTypeA, ParamTypeB); |} diff --git a/contrib/proguard/src/mill/contrib/proguard/Proguard.scala b/contrib/proguard/src/mill/contrib/proguard/Proguard.scala index 7076abb70a5..0aa3f6ea41a 100644 --- a/contrib/proguard/src/mill/contrib/proguard/Proguard.scala +++ b/contrib/proguard/src/mill/contrib/proguard/Proguard.scala @@ -1,7 +1,7 @@ package mill.contrib.proguard import mill.java9rtexport.Export -import mill.T +import mill.{Task, T} import mill.Agg import mill.api.{Loose, PathRef} import mill.util.Jvm @@ -22,28 +22,28 @@ trait Proguard extends ScalaModule { * The version of proguard to download from Maven. * https://mvnrepository.com/artifact/com.guardsquare/proguard-base */ - def proguardVersion: T[String] = T { - T.log.error( + def proguardVersion: T[String] = Task { + Task.log.error( "Using default proguard version is deprecated. Please override target proguardVersion to specify the version." ) "7.2.2" } /** Run the "shrink" step in the proguard pipeline. Defaults to true. */ - def shrink: T[Boolean] = T { true } + def shrink: T[Boolean] = Task { true } /** Run the "optimize" step in the proguard pipeline. Defaults to true. */ - def optimize: T[Boolean] = T { true } + def optimize: T[Boolean] = Task { true } /** Run the "obfuscate" step in the proguard pipeline. Defaults to true. */ - def obfuscate: T[Boolean] = T { true } + def obfuscate: T[Boolean] = Task { true } /** * Run the "optimize" step in the proguard pipeline. Defaults to true. * * Note that this is required for Java 7 and above. */ - def preverify: T[Boolean] = T { true } + def preverify: T[Boolean] = Task { true } /** * The path to JAVA_HOME. @@ -53,22 +53,22 @@ trait Proguard extends ScalaModule { * Defaults to the `java.home` system property. * Keep in sync with [[java9RtJar]]- */ - def javaHome: T[PathRef] = T.input { + def javaHome: T[PathRef] = Task.input { PathRef(Path(sys.props("java.home"))) } - /** Specifies the input jar to proguard. Defaults to the output of the `assembly` task. */ - def inJar: T[PathRef] = T { assembly() } + /** Specifies the input jar to proguard. Defaults to the output of the `assembly` Task. */ + def inJar: T[PathRef] = Task { assembly() } /** * This needs to return the Java RT JAR if on Java 9 or above. * Keep in sync with [[javaHome]]. */ - def java9RtJar: T[Seq[PathRef]] = T { + def java9RtJar: T[Seq[PathRef]] = Task { if (mill.main.client.Util.isJava9OrAbove) { - val rt = T.dest / Export.rtJarName + val rt = Task.dest / Export.rtJarName if (!os.exists(rt)) { - T.log.outputStream.println( + Task.log.outputStream.println( s"Preparing Java runtime JAR; this may take a minute or two ..." ) Export.rtTo(rt.toIO, false) @@ -83,21 +83,21 @@ trait Proguard extends ScalaModule { * The library jars proguard requires * Defaults the jars under `javaHome`. */ - def libraryJars: T[Seq[PathRef]] = T { + def libraryJars: T[Seq[PathRef]] = Task { val javaJars = os.list(javaHome().path / "lib", sort = false).filter(_.ext == "jar").toSeq.map(PathRef(_)) javaJars ++ java9RtJar() } /** - * Run the proguard task. + * Run the proguard Task. * * The full command will be printed when run. * The stdout and stderr of the command are written to the `dest/` folder. * The output jar is written to `dest/our.jar`. */ - def proguard: T[PathRef] = T { - val outJar = T.dest / "out.jar" + def proguard: T[PathRef] = Task { + val outJar = Task.dest / "out.jar" val args = Seq[Shellable]( steps(), @@ -111,18 +111,18 @@ trait Proguard extends ScalaModule { additionalOptions() ).flatMap(_.value) - T.log.debug(s"Running: ${args.mkString(" ")}") -// T.log.debug(s"stdout: ${T.dest / "stdout.txt"}") -// T.log.debug(s"stderr: ${T.dest / "stderr.txt"}") + Task.log.debug(s"Running: ${args.mkString(" ")}") +// Task.log.debug(s"stdout: ${Task.dest / "stdout.txt"}") +// Task.log.debug(s"stderr: ${Task.dest / "stderr.txt"}") -// val result = os.proc(cmd).call(stdout = T.dest / "stdout.txt", stderr = T.dest / "stderr.txt") -// T.log.debug(s"result: ${result}") +// val result = os.proc(cmd).call(stdout = Task.dest / "stdout.txt", stderr = Task.dest / "stderr.txt") +// Task.log.debug(s"result: ${result}") Jvm.runSubprocess( mainClass = "proguard.ProGuard", classPath = proguardClasspath().map(_.path), mainArgs = args, - workingDir = T.dest + workingDir = Task.dest ) // the call above already throws an exception on a non-zero exit code, @@ -134,13 +134,13 @@ trait Proguard extends ScalaModule { * The location of the proguard jar files. * These are downloaded from JCenter and fed to `java -cp` */ - def proguardClasspath: T[Loose.Agg[PathRef]] = T { + def proguardClasspath: T[Loose.Agg[PathRef]] = Task { defaultResolver().resolveDeps( Agg(ivy"com.guardsquare:proguard-base:${proguardVersion()}") ) } - private def steps: T[Seq[String]] = T { + private def steps: T[Seq[String]] = Task { (if (optimize()) Seq() else Seq("-dontoptimize")) ++ (if (obfuscate()) Seq() else Seq("-dontobfuscate")) ++ (if (shrink()) Seq() else Seq("-dontshrink")) ++ @@ -154,7 +154,7 @@ trait Proguard extends ScalaModule { * Can be overridden to specify a different entrypoint, * or additional entrypoints can be specified with `additionalOptions`. */ - def entryPoint: T[String] = T { + def entryPoint: T[String] = Task { s"""|-keep public class ${finalMainClass()} { | public static void main(java.lang.String[]); |} @@ -166,8 +166,8 @@ trait Proguard extends ScalaModule { * * These are fed as-is to the proguard command. */ - def additionalOptions: T[Seq[String]] = T { - T.log.error( + def additionalOptions: T[Seq[String]] = Task { + Task.log.error( "Proguard is set to not warn about message: can't find referenced method 'void invoke()' in library class java.lang.invoke.MethodHandle" ) Seq[String]("-dontwarn java.lang.invoke.MethodHandle") diff --git a/contrib/proguard/test/src/mill/contrib/proguard/ProguardTests.scala b/contrib/proguard/test/src/mill/contrib/proguard/ProguardTests.scala index 940e96467ef..2604abd5e5c 100644 --- a/contrib/proguard/test/src/mill/contrib/proguard/ProguardTests.scala +++ b/contrib/proguard/test/src/mill/contrib/proguard/ProguardTests.scala @@ -1,7 +1,7 @@ package mill.contrib.proguard import mill._ -import mill.define.Target +import mill.define.{Discover, Target} import mill.util.Util.millProjectModule import mill.scalalib.ScalaModule import mill.util.TestEvaluator @@ -20,13 +20,14 @@ object ProguardTests extends TestSuite { override def scalaVersion: T[String] = T(sys.props.getOrElse("MILL_SCALA_2_13_VERSION", ???)) - def proguardContribClasspath = T { + def proguardContribClasspath = Task { millProjectModule("mill-contrib-proguard", repositoriesTask()) } - override def runClasspath: Target[Seq[PathRef]] = - T { super.runClasspath() ++ proguardContribClasspath() } + override def runClasspath: Task[Seq[PathRef]] = + Task { super.runClasspath() ++ proguardContribClasspath() } + val millDiscover: Discover[this.type] = Discover[this.type] } val testModuleSourcesPath: Path = diff --git a/contrib/scalapblib/readme.adoc b/contrib/scalapblib/readme.adoc index d2d9a9618a2..0130b6f97dd 100644 --- a/contrib/scalapblib/readme.adoc +++ b/contrib/scalapblib/readme.adoc @@ -75,6 +75,6 @@ object example extends ScalaPBModule { def scalaVersion = "2.12.6" def scalaPBVersion = "0.7.4" override def scalaPBAdditionalArgs = - Seq(s"--zio_out=${T.dest.toIO.getCanonicalPath}") + Seq(s"--zio_out=${Task.dest.toIO.getCanonicalPath}") } ---- diff --git a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala index c29ee3357e0..05bc1761832 100644 --- a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala +++ b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBModule.scala @@ -13,9 +13,9 @@ import scala.util.Using /** @see [[http://www.lihaoyi.com/mill/page/contrib-modules.html#scalapb ScalaPB Module]] */ trait ScalaPBModule extends ScalaModule { - override def generatedSources = T { super.generatedSources() :+ compileScalaPB() } + override def generatedSources = Task { super.generatedSources() :+ compileScalaPB() } - override def ivyDeps = T { + override def ivyDeps = Task { super.ivyDeps() ++ Agg(ivy"com.thesamet.scalapb::scalapb-runtime::${scalaPBVersion()}") ++ (if (!scalaPBGrpc()) Agg() @@ -24,16 +24,16 @@ trait ScalaPBModule extends ScalaModule { def scalaPBVersion: T[String] - def scalaPBFlatPackage: T[Boolean] = T { false } + def scalaPBFlatPackage: T[Boolean] = Task { false } - def scalaPBJavaConversions: T[Boolean] = T { false } + def scalaPBJavaConversions: T[Boolean] = Task { false } - def scalaPBGrpc: T[Boolean] = T { true } + def scalaPBGrpc: T[Boolean] = Task { true } - def scalaPBSingleLineToProtoString: T[Boolean] = T { false } + def scalaPBSingleLineToProtoString: T[Boolean] = Task { false } /** ScalaPB enables lenses by default, this option allows you to disable it. */ - def scalaPBLenses: T[Boolean] = T { true } + def scalaPBLenses: T[Boolean] = Task { true } def scalaPBSearchDeps: Boolean = false @@ -41,22 +41,22 @@ trait ScalaPBModule extends ScalaModule { * Additional arguments for scalaPBC. * * If you'd like to pass additional arguments to the ScalaPB compiler directly, - * you can override this task. + * you can override this Task. * * @see See [[http://www.lihaoyi.com/mill/page/contrib-modules.html#scalapb Configuration Options]] to * know more. * @return a sequence of Strings representing the additional arguments to append * (defaults to empty Seq[String]). */ - def scalaPBAdditionalArgs: T[Seq[String]] = T { Seq.empty[String] } + def scalaPBAdditionalArgs: T[Seq[String]] = Task { Seq.empty[String] } - def scalaPBProtocPath: T[Option[String]] = T { None } + def scalaPBProtocPath: T[Option[String]] = Task { None } - def scalaPBSources: T[Seq[PathRef]] = T.sources { + def scalaPBSources: T[Seq[PathRef]] = Task.sources { millSourcePath / "protobuf" } - def scalaPBOptions: T[String] = T { + def scalaPBOptions: T[String] = Task { ( (if (scalaPBFlatPackage()) Seq("flat_package") else Seq.empty) ++ (if (scalaPBJavaConversions()) Seq("java_conversions") else Seq.empty) ++ @@ -73,7 +73,7 @@ trait ScalaPBModule extends ScalaModule { ).mkString(",") } - def scalaPBClasspath: T[Loose.Agg[PathRef]] = T { + def scalaPBClasspath: T[Loose.Agg[PathRef]] = Task { resolveDependencies( Seq( coursier.LocalRepositories.ivy2Local, @@ -84,18 +84,18 @@ trait ScalaPBModule extends ScalaModule { ) } - def scalaPBIncludePath: T[Seq[PathRef]] = T.sources { Seq.empty[PathRef] } + def scalaPBIncludePath: T[Seq[PathRef]] = Task.sources { Seq.empty[PathRef] } - private def scalaDepsPBIncludePath = if (scalaPBSearchDeps) T { Seq(scalaPBUnpackProto()) } - else T { Seq.empty[PathRef] } + private def scalaDepsPBIncludePath = if (scalaPBSearchDeps) Task { Seq(scalaPBUnpackProto()) } + else Task { Seq.empty[PathRef] } - def scalaPBProtoClasspath: T[Agg[PathRef]] = T { + def scalaPBProtoClasspath: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps(transitiveCompileIvyDeps() ++ transitiveIvyDeps()) } - def scalaPBUnpackProto: T[PathRef] = T { + def scalaPBUnpackProto: T[PathRef] = Task { val cp = scalaPBProtoClasspath() - val dest = T.dest + val dest = Task.dest cp.iterator.foreach { ref => Using(new ZipInputStream(ref.path.getInputStream)) { zip => while ({ @@ -105,7 +105,7 @@ trait ScalaPBModule extends ScalaModule { if (entry.getName.endsWith(".proto")) { val protoDest = dest / os.SubPath(entry.getName) if (os.exists(protoDest)) - T.log.error(s"Warning: Overwriting ${dest} / ${os.SubPath(entry.getName)} ...") + Task.log.error(s"Warning: Overwriting ${dest} / ${os.SubPath(entry.getName)} ...") Using.resource(os.write.over.outputStream(protoDest, createFolders = true)) { os => IO.stream(zip, os) } @@ -122,7 +122,7 @@ trait ScalaPBModule extends ScalaModule { /* * options passing to ScalaPBC **except** `--scala_out=...`, `--proto_path=source_parent` and `source` */ - def scalaPBCompileOptions: T[Seq[String]] = T { + def scalaPBCompileOptions: T[Seq[String]] = Task { ScalaPBWorkerApi.scalaPBWorker().compileOptions( scalaPBProtocPath(), (scalaPBIncludePath() ++ scalaDepsPBIncludePath()).map(_.path), @@ -130,13 +130,13 @@ trait ScalaPBModule extends ScalaModule { ) } - def compileScalaPB: T[PathRef] = T.persistent { + def compileScalaPB: T[PathRef] = Task.persistent { ScalaPBWorkerApi.scalaPBWorker() .compile( scalaPBClasspath(), scalaPBSources().map(_.path), scalaPBOptions(), - T.dest, + Task.dest, scalaPBCompileOptions() ) } diff --git a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBWorker.scala b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBWorker.scala index 74ba7a5f763..49f87908ef8 100644 --- a/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBWorker.scala +++ b/contrib/scalapblib/src/mill/contrib/scalapblib/ScalaPBWorker.scala @@ -4,7 +4,7 @@ package contrib.scalapblib import java.io.File import mill.api.PathRef -import mill.T +import mill.{Task, T} import mill.define.{Discover, ExternalModule, Worker} class ScalaPBWorker extends AutoCloseable { @@ -126,6 +126,6 @@ trait ScalaPBWorkerApi { } object ScalaPBWorkerApi extends ExternalModule { - def scalaPBWorker: Worker[ScalaPBWorker] = T.worker { new ScalaPBWorker() } - lazy val millDiscover: Discover[this.type] = Discover[this.type] + def scalaPBWorker: Worker[ScalaPBWorker] = Task.worker { new ScalaPBWorker() } + val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala b/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala index 67ff48254a8..58a994fc05d 100644 --- a/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala +++ b/contrib/scalapblib/test/src/mill/contrib/scalapblib/TutorialTests.scala @@ -2,6 +2,7 @@ package mill.contrib.scalapblib import mill._ import mill.api.PathRef +import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} import utest.framework.TestPath import utest.{TestSuite, Tests, assert, _} @@ -26,27 +27,33 @@ object TutorialTests extends TestSuite { object core extends TutorialModule { override def scalaPBVersion = testScalaPbVersion } + + val millDiscover: Discover[this.type] = Discover[this.type] } object TutorialWithProtoc extends TutorialBase { object core extends TutorialModule { override def scalaPBProtocPath = Some("/dev/null") } + + val millDiscover: Discover[this.type] = Discover[this.type] } object TutorialWithAdditionalArgs extends TutorialBase { object core extends TutorialModule { - override def scalaPBAdditionalArgs = T { + override def scalaPBAdditionalArgs = Task { Seq( "--additional-test=..." ) } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object TutorialWithSpecificSources extends TutorialBase { object core extends TutorialModule { - override def scalaPBSources: T[Seq[PathRef]] = T.sources { + override def scalaPBSources: T[Seq[PathRef]] = Task.sources { millSourcePath / "protobuf" / "tutorial" / "Tutorial.proto" } @@ -55,6 +62,8 @@ object TutorialTests extends TestSuite { PathRef(millSourcePath / "protobuf" / "tutorial") ) } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath: os.Path = os.pwd / "contrib" / "scalapblib" / "test" / "protobuf" / "tutorial" diff --git a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala index 26b9068e53c..0d17fe27328 100644 --- a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala +++ b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageModule.scala @@ -60,11 +60,11 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => */ def scoverageVersion: T[String] - private def isScoverage2: Task[Boolean] = T.task { scoverageVersion().startsWith("2.") } + private def isScoverage2: Task[Boolean] = Task.anon { scoverageVersion().startsWith("2.") } - private def isScala3: Task[Boolean] = T.task { ZincWorkerUtil.isScala3(outer.scalaVersion()) } + private def isScala3: Task[Boolean] = Task.anon { ZincWorkerUtil.isScala3(outer.scalaVersion()) } - def scoverageRuntimeDeps: T[Agg[Dep]] = T { + def scoverageRuntimeDeps: T[Agg[Dep]] = Task { if (isScala3()) { Agg.empty } else { @@ -72,7 +72,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => } } - def scoveragePluginDeps: T[Agg[Dep]] = T { + def scoveragePluginDeps: T[Agg[Dep]] = Task { val sv = scoverageVersion() if (isScala3()) { Agg.empty @@ -90,7 +90,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => } } - private def checkVersions = T.task { + private def checkVersions = Task.anon { val sv = scalaVersion() val isSov2 = scoverageVersion().startsWith("2.") (sv.split('.'), isSov2) match { @@ -107,7 +107,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => } } - private def scoverageReporterIvyDeps: T[Agg[Dep]] = T { + private def scoverageReporterIvyDeps: T[Agg[Dep]] = Task { checkVersions() val sv = scoverageVersion() @@ -121,7 +121,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => // should be safe case "2" :: "13" :: c :: _ if Try(c.toInt).getOrElse(0) > 8 => val v = "2.13.8" - T.log.outputStream.println( + Task.log.outputStream.println( s"Detected an unsupported Scala version (${millScalaVersion}). Using Scala version ${v} to resolve scoverage ${sv} reporting API." ) v @@ -140,16 +140,16 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => } } - def scoverageToolsClasspath: T[Agg[PathRef]] = T { + def scoverageToolsClasspath: T[Agg[PathRef]] = Task { scoverageReportWorkerClasspath() ++ defaultResolver().resolveDeps(scoverageReporterIvyDeps()) } - def scoverageClasspath: T[Agg[PathRef]] = T { + def scoverageClasspath: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps(scoveragePluginDeps()) } - def scoverageReportWorkerClasspath: T[Agg[PathRef]] = T { + def scoverageReportWorkerClasspath: T[Agg[PathRef]] = Task { val isScov2 = isScoverage2() val workerArtifact = @@ -168,59 +168,59 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => trait ScoverageData extends ScalaModule { - def doReport(reportType: ReportType): Task[Unit] = T.task { + def doReport(reportType: ReportType): Task[Unit] = Task.anon { ScoverageReportWorker .scoverageReportWorker() .bridge(scoverageToolsClasspath()) - .report(reportType, allSources().map(_.path), Seq(data().path), T.workspace) + .report(reportType, allSources().map(_.path), Seq(data().path), Task.workspace) } /** * The persistent data dir used to store scoverage coverage data. * Use to store coverage data at compile-time and by the various report targets. */ - def data: T[PathRef] = T.persistent { + def data: T[PathRef] = Task.persistent { // via the persistent target, we ensure, the dest dir doesn't get cleared - PathRef(T.dest) + PathRef(Task.dest) } override def compileResources: T[Seq[PathRef]] = outer.compileResources - override def generatedSources: Target[Seq[PathRef]] = T { outer.generatedSources() } - override def allSources: Target[Seq[PathRef]] = T { outer.allSources() } + override def generatedSources: Task[Seq[PathRef]] = Task { outer.generatedSources() } + override def allSources: Task[Seq[PathRef]] = Task { outer.allSources() } override def moduleDeps: Seq[JavaModule] = outer.moduleDeps override def compileModuleDeps: Seq[JavaModule] = outer.compileModuleDeps - override def sources: T[Seq[PathRef]] = T.sources { outer.sources() } - override def resources: T[Seq[PathRef]] = T.sources { outer.resources() } - override def scalaVersion = T { outer.scalaVersion() } - override def repositoriesTask: Task[Seq[Repository]] = T.task { outer.repositoriesTask() } - override def compileIvyDeps: Target[Agg[Dep]] = T { outer.compileIvyDeps() } - override def ivyDeps: Target[Agg[Dep]] = - T { outer.ivyDeps() ++ outer.scoverageRuntimeDeps() } - override def unmanagedClasspath: Target[Agg[PathRef]] = T { outer.unmanagedClasspath() } + override def sources: T[Seq[PathRef]] = Task.sources { outer.sources() } + override def resources: T[Seq[PathRef]] = Task.sources { outer.resources() } + override def scalaVersion = Task { outer.scalaVersion() } + override def repositoriesTask: Task[Seq[Repository]] = Task.anon { outer.repositoriesTask() } + override def compileIvyDeps: Task[Agg[Dep]] = Task { outer.compileIvyDeps() } + override def ivyDeps: Task[Agg[Dep]] = + Task { outer.ivyDeps() ++ outer.scoverageRuntimeDeps() } + override def unmanagedClasspath: Task[Agg[PathRef]] = Task { outer.unmanagedClasspath() } /** Add the scoverage scalac plugin. */ - override def scalacPluginIvyDeps: Target[Loose.Agg[Dep]] = - T { outer.scalacPluginIvyDeps() ++ outer.scoveragePluginDeps() } + override def scalacPluginIvyDeps: Task[Loose.Agg[Dep]] = + Task { outer.scalacPluginIvyDeps() ++ outer.scoveragePluginDeps() } /** Add the scoverage specific plugin settings (`dataDir`). */ - override def scalacOptions: Target[Seq[String]] = - T { + override def scalacOptions: Task[Seq[String]] = + Task { val extras = if (isScala3()) { Seq(s"-coverage-out:${data().path.toIO.getPath()}") } else { val base = s"-P:scoverage:dataDir:${data().path.toIO.getPath()}" - if (isScoverage2()) Seq(base, s"-P:scoverage:sourceRoot:${T.workspace}") + if (isScoverage2()) Seq(base, s"-P:scoverage:sourceRoot:${Task.workspace}") else Seq(base) } outer.scalacOptions() ++ extras } - def htmlReport(): Command[Unit] = T.command { doReport(ReportType.Html) } - def xmlReport(): Command[Unit] = T.command { doReport(ReportType.Xml) } - def xmlCoberturaReport(): Command[Unit] = T.command { doReport(ReportType.XmlCobertura) } - def consoleReport(): Command[Unit] = T.command { doReport(ReportType.Console) } + def htmlReport(): Command[Unit] = Task.command { doReport(ReportType.Html)() } + def xmlReport(): Command[Unit] = Task.command { doReport(ReportType.Xml)() } + def xmlCoberturaReport(): Command[Unit] = Task.command { doReport(ReportType.XmlCobertura)() } + def consoleReport(): Command[Unit] = Task.command { doReport(ReportType.Console)() } override def skipIdea = true } @@ -232,7 +232,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule => * classes folder by the outer.scoverage classes folder and adding the * scoverage runtime dependency. */ - override def runClasspath: T[Seq[PathRef]] = T { + override def runClasspath: T[Seq[PathRef]] = Task { val outerClassesPath = outer.compile().classes val outerScoverageClassesPath = outer.scoverage.compile().classes (super.runClasspath().map { path => diff --git a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReport.scala b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReport.scala index 5dd757fcbbf..01095324f9d 100644 --- a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReport.scala +++ b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReport.scala @@ -1,10 +1,10 @@ package mill.contrib.scoverage import mill.contrib.scoverage.api.ScoverageReportWorkerApi.ReportType -import mill.define.{Command, Module, Task} +import mill.define.{Command, Module} import mill.eval.Evaluator import mill.resolve.{Resolve, SelectMode} -import mill.{PathRef, T} +import mill.{PathRef, T, Task} import os.Path /** @@ -53,7 +53,7 @@ trait ScoverageReport extends Module { evaluator: Evaluator, sources: String = "__.allSources", dataTargets: String = "__.scoverage.data" - ): Command[PathRef] = T.command { + ): Command[PathRef] = Task.command { reportTask(evaluator, ReportType.Html, sources, dataTargets)() } @@ -62,7 +62,7 @@ trait ScoverageReport extends Module { evaluator: Evaluator, sources: String = "__.allSources", dataTargets: String = "__.scoverage.data" - ): Command[PathRef] = T.command { + ): Command[PathRef] = Task.command { reportTask(evaluator, ReportType.Xml, sources, dataTargets)() } @@ -71,7 +71,7 @@ trait ScoverageReport extends Module { evaluator: Evaluator, sources: String = "__.allSources", dataTargets: String = "__.scoverage.data" - ): Command[PathRef] = T.command { + ): Command[PathRef] = Task.command { reportTask(evaluator, ReportType.XmlCobertura, sources, dataTargets)() } @@ -80,7 +80,7 @@ trait ScoverageReport extends Module { evaluator: Evaluator, sources: String = "__.allSources", dataTargets: String = "__.scoverage.data" - ): Command[PathRef] = T.command { + ): Command[PathRef] = Task.command { reportTask(evaluator, ReportType.Console, sources, dataTargets)() } @@ -107,14 +107,14 @@ trait ScoverageReport extends Module { case Right(tasks) => tasks.asInstanceOf[Seq[Task[PathRef]]] } - T.task { - val sourcePaths: Seq[Path] = T.sequence(sourcesTasks)().flatten.map(_.path) - val dataPaths: Seq[Path] = T.sequence(dataTasks)().map(_.path) + Task.anon { + val sourcePaths: Seq[Path] = Task.sequence(sourcesTasks)().flatten.map(_.path) + val dataPaths: Seq[Path] = Task.sequence(dataTasks)().map(_.path) scoverageReportWorkerModule .scoverageReportWorker() .bridge(workerModule.scoverageToolsClasspath()) - .report(reportType, sourcePaths, dataPaths, T.workspace) - PathRef(T.dest) + .report(reportType, sourcePaths, dataPaths, Task.workspace) + PathRef(Task.dest) } } } diff --git a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala index f45621802c0..cc07eebe3d0 100644 --- a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala +++ b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala @@ -1,6 +1,6 @@ package mill.contrib.scoverage -import mill.{Agg, T} +import mill.{Agg, T, Task} import mill.api.{ClassLoader, Ctx, PathRef} import mill.contrib.scoverage.api.ScoverageReportWorkerApi import mill.define.{Discover, ExternalModule, Worker} @@ -39,6 +39,6 @@ class ScoverageReportWorker extends AutoCloseable { object ScoverageReportWorker extends ExternalModule { def scoverageReportWorker: Worker[ScoverageReportWorker] = - T.worker { new ScoverageReportWorker() } - lazy val millDiscover: Discover[this.type] = Discover[this.type] + Task.worker { new ScoverageReportWorker() } + val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/contrib/scoverage/test/src/mill/contrib/scoverage/HelloWorldTests.scala b/contrib/scoverage/test/src/mill/contrib/scoverage/HelloWorldTests.scala index 00cdb72d87b..ef99250ec58 100644 --- a/contrib/scoverage/test/src/mill/contrib/scoverage/HelloWorldTests.scala +++ b/contrib/scoverage/test/src/mill/contrib/scoverage/HelloWorldTests.scala @@ -3,6 +3,7 @@ package mill.contrib.scoverage import mill._ import mill.api.Result import mill.contrib.buildinfo.BuildInfo +import mill.define.Discover import mill.scalalib.{DepSyntax, SbtModule, ScalaModule, TestModule} import mill.util.{TestEvaluator, TestUtil} import utest._ @@ -51,6 +52,8 @@ trait HelloWorldTests extends utest.TestSuite { override def ivyDeps = Agg(ivy"org.scalatest::scalatest:${testScalatestVersion}") } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldSbt extends HelloBase { @@ -63,6 +66,8 @@ trait HelloWorldTests extends utest.TestSuite { override def ivyDeps = Agg(ivy"org.scalatest::scalatest:${testScalatestVersion}") } } + + val millDiscover: Discover[this.type] = Discover[this.type] } def workspaceTest[T]( diff --git a/contrib/sonatypecentral/src/mill/contrib/sonatypecentral/SonatypeCentralPublishModule.scala b/contrib/sonatypecentral/src/mill/contrib/sonatypecentral/SonatypeCentralPublishModule.scala index 9463761b3ba..7b750cb4a70 100644 --- a/contrib/sonatypecentral/src/mill/contrib/sonatypecentral/SonatypeCentralPublishModule.scala +++ b/contrib/sonatypecentral/src/mill/contrib/sonatypecentral/SonatypeCentralPublishModule.scala @@ -21,21 +21,21 @@ import mill.scalalib.publish.SonatypeHelpers.{ } trait SonatypeCentralPublishModule extends PublishModule { - def sonatypeCentralGpgArgs: T[String] = T { defaultGpgArgs.mkString(",") } + def sonatypeCentralGpgArgs: T[String] = Task { defaultGpgArgs.mkString(",") } - def sonatypeCentralConnectTimeout: T[Int] = T { defaultConnectTimeout } + def sonatypeCentralConnectTimeout: T[Int] = Task { defaultConnectTimeout } - def sonatypeCentralReadTimeout: T[Int] = T { defaultReadTimeout } + def sonatypeCentralReadTimeout: T[Int] = Task { defaultReadTimeout } - def sonatypeCentralAwaitTimeout: T[Int] = T { defaultAwaitTimeout } + def sonatypeCentralAwaitTimeout: T[Int] = Task { defaultAwaitTimeout } - def sonatypeCentralShouldRelease: T[Boolean] = T { true } + def sonatypeCentralShouldRelease: T[Boolean] = Task { true } def publishSonatypeCentral( username: String = defaultCredentials, password: String = defaultCredentials ): define.Command[Unit] = - T.command { + Task.command { val publishData = publishArtifacts() val fileMapping = publishData.withConcretePath._1 val artifact = publishData.meta @@ -46,9 +46,9 @@ trait SonatypeCentralPublishModule extends PublishModule { gpgArgs = getFinalGpgArgs(sonatypeCentralGpgArgs()), connectTimeout = sonatypeCentralConnectTimeout(), readTimeout = sonatypeCentralReadTimeout(), - log = T.log, - workspace = T.workspace, - env = T.env, + log = Task.log, + workspace = Task.workspace, + env = Task.env, awaitTimeout = sonatypeCentralAwaitTimeout() ) publisher.publish( @@ -77,10 +77,10 @@ object SonatypeCentralPublishModule extends ExternalModule { connectTimeout: Int = defaultConnectTimeout, awaitTimeout: Int = defaultAwaitTimeout, bundleName: String = "" - ): Command[Unit] = T.command { + ): Command[Unit] = Task.command { val artifacts: Seq[(Seq[(os.Path, String)], Artifact)] = - T.sequence(publishArtifacts.value)().map { + Task.sequence(publishArtifacts.value)().map { case data @ PublishModule.PublishData(_, _) => data.withConcretePath } @@ -92,9 +92,9 @@ object SonatypeCentralPublishModule extends ExternalModule { gpgArgs = getFinalGpgArgs(gpgArgs), connectTimeout = connectTimeout, readTimeout = readTimeout, - log = T.log, - workspace = T.workspace, - env = T.env, + log = Task.log, + workspace = Task.workspace, + env = Task.env, awaitTimeout = awaitTimeout ) publisher.publishAll( @@ -116,12 +116,12 @@ object SonatypeCentralPublishModule extends ExternalModule { credentialParameterValue: String, credentialName: String, envVariableName: String - ): Task[String] = T.task { + ): Task[String] = Task.anon { if (credentialParameterValue.nonEmpty) { Result.Success(credentialParameterValue) } else { (for { - credential <- T.env.get(envVariableName) + credential <- Task.env.get(envVariableName) } yield { Result.Success(credential) }).getOrElse( @@ -135,7 +135,7 @@ object SonatypeCentralPublishModule extends ExternalModule { private def getSonatypeCredentials( usernameParameterValue: String, passwordParameterValue: String - ): Task[SonatypeCredentials] = T.task { + ): Task[SonatypeCredentials] = Task.anon { val username = getSonatypeCredential(usernameParameterValue, "username", USERNAME_ENV_VARIABLE_NAME)() val password = diff --git a/contrib/testng/test/src/mill/testng/TestNGTests.scala b/contrib/testng/test/src/mill/testng/TestNGTests.scala index 23a8a4956ce..cb342284649 100644 --- a/contrib/testng/test/src/mill/testng/TestNGTests.scala +++ b/contrib/testng/test/src/mill/testng/TestNGTests.scala @@ -1,7 +1,7 @@ package mill package testng -import mill.define.Target +import mill.define.{Discover, Target} import mill.util.Util.millProjectModule import mill.scalalib._ import mill.util.{TestEvaluator, TestUtil} @@ -15,7 +15,7 @@ object TestNGTests extends TestSuite { TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.') object test extends JavaModuleTests { - def testngClasspath = T { + def testngClasspath = Task { millProjectModule( "mill-contrib-testng", repositoriesTask(), @@ -23,20 +23,21 @@ object TestNGTests extends TestSuite { ) } - override def runClasspath: Target[Seq[PathRef]] = - T { super.runClasspath() ++ testngClasspath() } - override def ivyDeps = T { + override def runClasspath: Task[Seq[PathRef]] = + Task { super.runClasspath() ++ testngClasspath() } + override def ivyDeps = Task { super.ivyDeps() ++ Agg( ivy"org.testng:testng:6.11", ivy"de.tototec:de.tobiasroeser.lambdatest:0.8.0" ) } - override def testFramework = T { + override def testFramework = Task { "mill.testng.TestNGFramework" } } + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath: os.Path = os.pwd / "contrib" / "testng" / "test" / "resources" / "demo" diff --git a/contrib/twirllib/readme.adoc b/contrib/twirllib/readme.adoc index 69eab273295..899b223d117 100644 --- a/contrib/twirllib/readme.adoc +++ b/contrib/twirllib/readme.adoc @@ -53,7 +53,7 @@ import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._ object app extends ScalaModule with TwirlModule { def twirlVersion = "1.5.1" - def generatedSources = T{ Seq(compileTwirl().classes) } + def generatedSources = Task { Seq(compileTwirl().classes) } } ---- @@ -96,7 +96,7 @@ object app extends ScalaModule with TwirlModule { def twirlVersion = "1.5.1" def twirlScalaVersion = "2.13.8" override def twirlImports = super.twirlImports() ++ Seq("my.additional.stuff._", "my.other.stuff._") - def generatedSources = T{ Seq(compileTwirl().classes) } + def generatedSources = Task { Seq(compileTwirl().classes) } } // out.template.scala @@ -138,7 +138,7 @@ import $ivy.`com.lihaoyi::mill-contrib-twirllib:`, mill.twirllib._ object app extends ScalaModule with TwirlModule { def twirlVersion = "1.5.1" override def twirlFormats = super.twirlFormats() + Map("svg" -> "play.twirl.api.HtmlFormat") - def generatedSources = T{ Seq(compileTwirl().classes) } + def generatedSources = Task { Seq(compileTwirl().classes) } } ---- diff --git a/contrib/twirllib/src/mill/twirllib/TwirlModule.scala b/contrib/twirllib/src/mill/twirllib/TwirlModule.scala index cb0abe3343a..4b31edb0f03 100644 --- a/contrib/twirllib/src/mill/twirllib/TwirlModule.scala +++ b/contrib/twirllib/src/mill/twirllib/TwirlModule.scala @@ -18,14 +18,14 @@ trait TwirlModule extends mill.Module { twirlModule => * The Scala version matching the twirl version. * @since Mill after 0.10.5 */ - def twirlScalaVersion: T[String] = T { + def twirlScalaVersion: T[String] = Task { twirlVersion() match { case s"1.$minor.$_" if minor.toIntOption.exists(_ < 4) => BuildInfo.workerScalaVersion212 case _ => BuildInfo.scalaVersion } } - def twirlSources: T[Seq[PathRef]] = T.sources { + def twirlSources: T[Seq[PathRef]] = Task.sources { millSourcePath / "views" } @@ -33,15 +33,17 @@ trait TwirlModule extends mill.Module { twirlModule => * Replicate the logic from twirl build, * see: https://github.com/playframework/twirl/blob/2.0.1/build.sbt#L12-L17 */ - private def scalaParserCombinatorsVersion: T[String] = twirlScalaVersion.map { - case v if v.startsWith("2.") => "1.1.2" - case _ => "2.3.0" + private def scalaParserCombinatorsVersion: T[String] = Task { + twirlScalaVersion() match { + case v if v.startsWith("2.") => "1.1.2" + case _ => "2.3.0" + } } /** * @since Mill after 0.10.5 */ - def twirlIvyDeps: T[Agg[Dep]] = T { + def twirlIvyDeps: T[Agg[Dep]] = Task { Agg( if (twirlVersion().startsWith("1.")) ivy"com.typesafe.play::twirl-compiler:${twirlVersion()}" @@ -57,7 +59,7 @@ trait TwirlModule extends mill.Module { twirlModule => * @since Mill after 0.10.5 */ trait TwirlResolver extends CoursierModule { - override def resolveCoursierDependency: Task[Dep => Dependency] = T.task { d: Dep => + override def resolveCoursierDependency: Task[Dep => Dependency] = Task.anon { d: Dep => Lib.depToDependency(d, twirlScalaVersion()) } @@ -72,11 +74,11 @@ trait TwirlModule extends mill.Module { twirlModule => */ lazy val twirlCoursierResolver: TwirlResolver = new TwirlResolver {} - def twirlClasspath: T[Loose.Agg[PathRef]] = T { + def twirlClasspath: T[Loose.Agg[PathRef]] = Task { twirlCoursierResolver.defaultResolver().resolveDeps(twirlIvyDeps()) } - def twirlImports: T[Seq[String]] = T { + def twirlImports: T[Seq[String]] = Task { TwirlWorkerApi.twirlWorker.defaultImports(twirlClasspath()) } @@ -88,12 +90,12 @@ trait TwirlModule extends mill.Module { twirlModule => def twirlInclusiveDot: Boolean = false - def compileTwirl: T[mill.scalalib.api.CompilationResult] = T.persistent { + def compileTwirl: T[mill.scalalib.api.CompilationResult] = Task.persistent { TwirlWorkerApi.twirlWorker .compile( twirlClasspath(), twirlSources().map(_.path), - T.dest, + Task.dest, twirlImports(), twirlFormats(), twirlConstructorAnnotations, diff --git a/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala b/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala index 6bae2e57e54..a7f34569dac 100644 --- a/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala +++ b/contrib/twirllib/test/src/mill/twirllib/HelloWorldTests.scala @@ -1,5 +1,6 @@ package mill.twirllib +import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} import utest.framework.TestPath import utest.{TestSuite, Tests, assert, _} @@ -24,6 +25,7 @@ trait HelloWorldTests extends TestSuite { override def twirlConstructorAnnotations: Seq[String] = testConstructorAnnotations } + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldWithInclusiveDot extends HelloBase { @@ -33,6 +35,7 @@ trait HelloWorldTests extends TestSuite { override def twirlFormats = super.twirlFormats() ++ Map("svg" -> "play.twirl.api.HtmlFormat") } + val millDiscover: Discover[this.type] = Discover[this.type] } def workspaceTest[T]( diff --git a/contrib/versionfile/readme.adoc b/contrib/versionfile/readme.adoc index e489f129d83..dcb7c1fd99d 100644 --- a/contrib/versionfile/readme.adoc +++ b/contrib/versionfile/readme.adoc @@ -63,7 +63,7 @@ object mymodule extends PublishModule { == Configure the version file -If you want the version file to have another name, you will need to override the `versionFile` task. +If you want the version file to have another name, you will need to override the `versionFile` Task. If you have a project wide version file like in the example above, and you want the version file to reside at the root of the project, you can override `millSourcePath`: diff --git a/contrib/versionfile/src/mill/contrib/versionfile/VersionFileModule.scala b/contrib/versionfile/src/mill/contrib/versionfile/VersionFileModule.scala index d538ce6958e..c7060979802 100644 --- a/contrib/versionfile/src/mill/contrib/versionfile/VersionFileModule.scala +++ b/contrib/versionfile/src/mill/contrib/versionfile/VersionFileModule.scala @@ -5,34 +5,35 @@ import mill._ trait VersionFileModule extends Module { /** The file containing the current version. */ - def versionFile: T[PathRef] = T.source(millSourcePath / "version") + def versionFile: T[PathRef] = Task.source(millSourcePath / "version") /** The current version. */ - def currentVersion: T[Version] = T { Version.of(os.read(versionFile().path).trim) } + def currentVersion: T[Version] = Task { Version.of(os.read(versionFile().path).trim) } /** The release version. */ - def releaseVersion: T[Version] = T { currentVersion().asRelease } + def releaseVersion: T[Version] = Task { currentVersion().asRelease } /** The next snapshot version. */ - def nextVersion(bump: String): Task[Version] = T.task { currentVersion().asSnapshot.bump(bump) } + def nextVersion(bump: String): Task[Version] = + Task.anon { currentVersion().asSnapshot.bump(bump) } /** Writes the release version to file. */ - def setReleaseVersion(): Command[Unit] = T.command { + def setReleaseVersion(): Command[Unit] = Task.command { setVersionTask(releaseVersion)() } /** Writes the next snapshot version to file. */ - def setNextVersion(bump: String): Command[Unit] = T.command { + def setNextVersion(bump: String): Command[Unit] = Task.command { setVersionTask(nextVersion(bump))() } /** Writes the given version to file. */ - def setVersion(version: Task[Version]): Command[Unit] = T.command { + def setVersion(version: Task[Version]): Command[Unit] = Task.command { setVersionTask(version)() } - protected def setVersionTask(version: Task[Version]) = T.task { - T.log.info(generateCommitMessage(version())) + protected def setVersionTask(version: Task[Version]) = Task.anon { + Task.log.info(generateCommitMessage(version())) writeVersionToFile(versionFile(), version()) } @@ -43,7 +44,7 @@ trait VersionFileModule extends Module { ) /** Procs for tagging current version and committing changes. */ - def tag = T { + def tag = Task { Seq( os.proc("git", "commit", "-am", generateCommitMessage(currentVersion())), os.proc("git", "tag", currentVersion().toString) @@ -51,7 +52,7 @@ trait VersionFileModule extends Module { } /** Procs for committing changes and pushing. */ - def push = T { + def push = Task { Seq( os.proc("git", "commit", "-am", generateCommitMessage(currentVersion())), os.proc("git", "push", "origin", "master", "--tags") @@ -82,9 +83,9 @@ trait VersionFileModule extends Module { object VersionFileModule extends define.ExternalModule { /** Executes the given processes. */ - def exec(procs: mill.main.Tasks[Seq[os.proc]]) = T.command { + def exec(procs: mill.main.Tasks[Seq[os.proc]]) = Task.command { for { - procs <- T.sequence(procs.value)() + procs <- Task.sequence(procs.value)() proc <- procs } yield proc.call() } diff --git a/contrib/versionfile/test/src/mill/contrib/versionfile/VersionFileModuleTests.scala b/contrib/versionfile/test/src/mill/contrib/versionfile/VersionFileModuleTests.scala index 4af73db9771..548abe249dd 100644 --- a/contrib/versionfile/test/src/mill/contrib/versionfile/VersionFileModuleTests.scala +++ b/contrib/versionfile/test/src/mill/contrib/versionfile/VersionFileModuleTests.scala @@ -1,7 +1,8 @@ package mill.contrib.versionfile -import mill.T +import mill.{T, Task} import mill.api.Result +import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} import utest.{TestSuite, Tests, assert, assertMatch, test} import utest.framework.TestPath @@ -10,6 +11,8 @@ object VersionFileModuleTests extends TestSuite { object TestModule extends TestUtil.BaseModule { case object versionFile extends VersionFileModule + + val millDiscover: Discover[this.type] = Discover[this.type] } def evaluator[T, M <: TestUtil.BaseModule]( @@ -130,7 +133,7 @@ object VersionFileModuleTests extends TestSuite { test("setVersion") - workspaceTest(versions: _*) { eval => val expected = Version.Release(1, 2, 4) - eval(TestModule.versionFile.setVersion(T.task(expected))) + eval(TestModule.versionFile.setVersion(Task.anon(expected))) val actual = eval(TestModule.versionFile.currentVersion) assert(actual.value == Right(expected)) } diff --git a/docs/modules/ROOT/pages/Extending_Mill.adoc b/docs/modules/ROOT/pages/Extending_Mill.adoc index 73f816030bf..5d326424191 100644 --- a/docs/modules/ROOT/pages/Extending_Mill.adoc +++ b/docs/modules/ROOT/pages/Extending_Mill.adoc @@ -74,7 +74,7 @@ build. [source,scala] ---- -def idea(ev: Evaluator) = T.command { +def idea(ev: Evaluator) = Task.command { mill.scalalib.GenIdea( implicitly, ev.rootModule, diff --git a/docs/modules/ROOT/pages/External_References.adoc b/docs/modules/ROOT/pages/External_References.adoc index a483359d3cc..2d49732a9c2 100644 --- a/docs/modules/ROOT/pages/External_References.adoc +++ b/docs/modules/ROOT/pages/External_References.adoc @@ -39,7 +39,7 @@ ScalaDoc:: https://javadoc.io/doc/com.lihaoyi/requests_2.13/latest/index.html MainArgs is a small, dependency-free library for command line argument parsing in Scala. -Mill uses MainArgs to handle argument parsing for `T.command`s that are run +Mill uses MainArgs to handle argument parsing for `Task.command`s that are run from the command line. Project page:: https://github.com/com-lihaoyi/mainargs diff --git a/docs/modules/ROOT/pages/Java_Case_Study_Netty.adoc b/docs/modules/ROOT/pages/Java_Case_Study_Netty.adoc index f37ea78ffda..e7e205f3ac8 100644 --- a/docs/modules/ROOT/pages/Java_Case_Study_Netty.adoc +++ b/docs/modules/ROOT/pages/Java_Case_Study_Netty.adoc @@ -434,7 +434,7 @@ which we will explore below ```scala trait NettyModule extends NettyBaseModule{ def testModuleDeps: Seq[MavenModule] = Nil - def testIvyDeps: T[Agg[mill.scalalib.Dep]] = T{ Agg() } + def testIvyDeps: T[Agg[mill.scalalib.Dep]] = Task { Agg() } object test extends NettyTestSuiteModule with MavenTests{ def moduleDeps = super.moduleDeps ++ testModuleDeps @@ -579,25 +579,25 @@ import $ivy.`ant:ant-optional:1.5.3-1` object common extends NettyModule{ ... - def script = T.source(millSourcePath / "src" / "main" / "script") - def generatedSources0 = T{ + def script = Task.source(millSourcePath / "src" / "main" / "script") + def generatedSources0 = Task { val shell = new groovy.lang.GroovyShell() val context = new java.util.HashMap[String, Object] context.put("collection.template.dir", "common/src/main/templates") context.put("collection.template.test.dir", "common/src/test/templates") - context.put("collection.src.dir", (T.dest / "src").toString) - context.put("collection.testsrc.dir", (T.dest / "testsrc").toString) + context.put("collection.src.dir", (Task.dest / "src").toString) + context.put("collection.testsrc.dir", (Task.dest / "testsrc").toString) shell.setProperty("properties", context) shell.setProperty("ant", new groovy.ant.AntBuilder()) shell.evaluate((script().path / "codegen.groovy").toIO) - (PathRef(T.dest / "src"), PathRef(T.dest / "testsrc")) + (PathRef(Task.dest / "src"), PathRef(Task.dest / "testsrc")) } - def generatedSources = T{ Seq(generatedSources0()._1)} + def generatedSources = Task { Seq(generatedSources0()._1)} } ``` @@ -695,28 +695,28 @@ with the `make` command essentially being a bash script wrapped in layers of XML In contrast, the Mill configuration for this logic is as follows: ```scala -def makefile = T.source(millSourcePath / "Makefile") -def cSources = T.source(millSourcePath / "src" / "main" / "c") -def cHeaders = T{ +def makefile = Task.source(millSourcePath / "Makefile") +def cSources = Task.source(millSourcePath / "src" / "main" / "c") +def cHeaders = Task { for(p <- os.walk(cSources().path) if p.ext == "h"){ - os.copy(p, T.dest / p.relativeTo(cSources().path), createFolders = true) + os.copy(p, Task.dest / p.relativeTo(cSources().path), createFolders = true) } - PathRef(T.dest) + PathRef(Task.dest) } -def make = T{ - os.copy(makefile().path, T.dest / "Makefile") - os.copy(cSources().path, T.dest / "src" / "main" / "c", createFolders = true) +def make = Task { + os.copy(makefile().path, Task.dest / "Makefile") + os.copy(cSources().path, Task.dest / "src" / "main" / "c", createFolders = true) val Seq(sourceJar) = resolveDeps( - deps = T.task(Agg(ivy"io.netty:netty-jni-util:0.0.9.Final").map(bindDependency())), + deps = Task.anon(Agg(ivy"io.netty:netty-jni-util:0.0.9.Final").map(bindDependency())), sources = true )().toSeq - os.proc("jar", "xf", sourceJar.path).call(cwd = T.dest / "src" / "main" / "c") + os.proc("jar", "xf", sourceJar.path).call(cwd = Task.dest / "src" / "main" / "c") os.proc("make").call( - cwd = T.dest, + cwd = Task.dest, env = Map( "CC" -> "clang", "AR" -> "ar", @@ -736,7 +736,7 @@ def make = T{ ) ) - (PathRef(T.dest / "lib-out"), PathRef(T.dest / "obj-out")) + (PathRef(Task.dest / "lib-out"), PathRef(Task.dest / "obj-out")) } ``` diff --git a/docs/modules/ROOT/pages/Mill_Design_Principles.adoc b/docs/modules/ROOT/pages/Mill_Design_Principles.adoc index d06e7bf67a4..a882d8736ec 100644 --- a/docs/modules/ROOT/pages/Mill_Design_Principles.adoc +++ b/docs/modules/ROOT/pages/Mill_Design_Principles.adoc @@ -15,7 +15,7 @@ Mill: === Dependency graph first Mill's most important abstraction is the dependency graph of ``Task``s. -Constructed using the `T {...}` `T.task {...}` `T.command {...}` syntax, these +Constructed using the `Task {...}` `Task.anon {...}` `Task.command {...}` syntax, these track the dependencies between steps of a build, so those steps can be executed in the correct order, queried, or parallelized. @@ -33,7 +33,7 @@ the same as referencing a target in Scala code, `Foo.bar.baz` Everything that you can run from the command line lives in an object hierarchy in your `build.sc` file. Different parts of the hierarchy can have different -``Target``s available: just add a new `def foo = T {...}` somewhere and you'll be +``Target``s available: just add a new `def foo = Task {...}` somewhere and you'll be able to run it. Cross builds, using the `Cross` data structure, are just another kind of node in @@ -43,7 +43,7 @@ run something via `mill core.cross[a].printIt` while from code you use === Caching by default -Every `Target` in a build, defined by `def foo = T {...}`, is cached by default. +Every `Target` in a build, defined by `def foo = Task {...}`, is cached by default. Currently this is done using a `foo.json` file in the `out/` folder. The `Target` is also provided a `foo.dest/` path on the filesystem dedicated to it, for it to store output files etc. @@ -65,9 +65,9 @@ is what allows us to be aggressive about caching and parallelizing the evaluation of build targets during a build. Many kinds of build steps do require files on disk, and for that Mill provides -the `T.dest` folder. This is a folder on disk dedicated to each build target, +the `Task.dest` folder. This is a folder on disk dedicated to each build target, so that it can read and write things to it without worrying about conflicts -with other targets that have their own `T.dest` folders. In effect, this makes +with other targets that have their own `Task.dest` folders. In effect, this makes even file output "pure": we can know precisely where a target's output files live when we need to invalidate them, and it allows multiple targets all reading and writing to the filesystem to do so safely even when in parallel. @@ -116,13 +116,13 @@ sorts of useful operations on the graph before running it: with an exception In order to avoid making people using `.map` and `.zip` all over the place when -defining their ``Task``s, we use the `T {...}`/`T.task {...}`/`T.command {...}` +defining their ``Task``s, we use the `Task {...}`/`Task.anon {...}`/`Task.command {...}` macros which allow you to use `Task#apply()` within the block to "extract" a value. [source,scala] ---- -def test() = T.command { +def test() = Task.command { TestRunner.apply( "mill.UTestFramework", runDepClasspath().map(_.path) :+ compile().path, @@ -136,7 +136,7 @@ This is roughly equivalent to the following: [source,scala] ---- -def test() = T.command { T.zipMap(runDepClasspath, compile, compile) { +def test() = Task.command { Task.zipMap(runDepClasspath, compile, compile) { (runDepClasspath1, compile2, compile3) => TestRunner.apply( "mill.UTestFramework", @@ -148,7 +148,7 @@ def test() = T.command { T.zipMap(runDepClasspath, compile, compile) { ---- This is similar to SBT's `:=`/`.value` macros, or ``scala-async``'s -`async`/`await`. Like those, the `T {...}` macro should let users program most of +`async`/`await`. Like those, the `Task {...}` macro should let users program most of their code in a "direct" style and have it "automatically" lifted into a graph of ``Task``s. @@ -277,7 +277,7 @@ digraph G { .... The Scala call graph of "which target references which other target" is core to -how Mill operates. This graph is reified via the `T {...}` macro to make it +how Mill operates. This graph is reified via the `Task {...}` macro to make it available to the Mill execution engine at runtime. The call graph tells you: * Which ``Target``s depend on which other ``Target``s @@ -294,7 +294,7 @@ available to the Mill execution engine at runtime. The call graph tells you: its return value) * Defining your own task that depends on others is as simple as `def foo = - T {...}` + Task {...}` The call graph within your Scala code is essentially a data-flow graph: by defining a snippet of code: @@ -312,16 +312,16 @@ you are telling everyone that the value `a` depends on the values of `b` `c` and knowing what `Target` depends on what other ``Target``s, and what processing it does on its inputs! -With Mill, you can take the Scala call graph, wrap everything in the `T {...}` +With Mill, you can take the Scala call graph, wrap everything in the `Task {...}` macro, and get a `Target`-dependency graph that matches exactly the call-graph you already had: [source,scala] ---- -def b = T { ... } -def c = T { ... } -def d = T { ... } -def a = T { f(b(), c(), d()) } +def b = Task { ... } +def c = Task { ... } +def d = Task { ... } +def a = Task { f(b(), c(), d()) } ---- Thus, if you are familiar with how data flows through a normal Scala program, diff --git a/docs/modules/ROOT/pages/Modules.adoc b/docs/modules/ROOT/pages/Modules.adoc index 0a94c96c57f..cdd411460b5 100644 --- a/docs/modules/ROOT/pages/Modules.adoc +++ b/docs/modules/ROOT/pages/Modules.adoc @@ -34,8 +34,8 @@ package foo import mill._ object Bar extends mill.define.ExternalModule { - def baz = T { 1 } - def qux() = T.command { println(baz() + 1) } + def baz = Task { 1 } + def qux() = Task.command { println(baz() + 1) } lazy val millDiscover = mill.define.Discover[this.type] } @@ -56,7 +56,7 @@ that is shared by the entire build: for example, `mill.scalalib.ZincWorkerApi/zincWorker` provides a shared Scala compilation service & cache that is shared between all ``ScalaModule``s, and `mill.scalalib.GenIdea/idea` lets you generate IntelliJ projects without -needing to define your own `T.command` in your `build.sc` file +needing to define your own `Task.command` in your `build.sc` file == Foreign Modules @@ -86,7 +86,7 @@ import $file.bar.build import $file.^.baz.build import mill._ -def someFoo = T { +def someFoo = Task { ^.baz.build.someBaz(...) bar.build.someBar(...) diff --git a/docs/modules/ROOT/pages/Out_Dir.adoc b/docs/modules/ROOT/pages/Out_Dir.adoc index ec0903dc99e..2aca0ffa62d 100644 --- a/docs/modules/ROOT/pages/Out_Dir.adoc +++ b/docs/modules/ROOT/pages/Out_Dir.adoc @@ -51,7 +51,7 @@ out/ ---- <1> The `main` directory contains all files associated with target and submodules of the `main` module. -<2> The `compile` target has tried to access its scratch space via `T.dest`. Here you will find the actual compile results. +<2> The `compile` target has tried to access its scratch space via `Task.dest`. Here you will find the actual compile results. <3> Two targets printed something out while they ran. You can find these outputs in the `*.log` files. <4> Three targets are overridden but re-use the result of their `super`-targets in some way. You can find these result under the `*.super/` path. @@ -74,7 +74,7 @@ by `foo.json` via `PathRef` references. `foo.dest/`:: optional, a path for the `Task` to use either as a scratch space, or to place generated files that are returned using `PathRef` references. -A `Task` should only output files within its own given `foo.dest/` folder (available as `T.dest`) to avoid +A `Task` should only output files within its own given `foo.dest/` folder (available as `Task.dest`) to avoid conflicting with another `Task`, but can name files within `foo.dest/` arbitrarily. `foo.log`:: @@ -88,7 +88,7 @@ The `out/` folder is intentionally kept simple and user-readable. If your build is not behaving as you would expect, feel free to poke around the various `foo.dest/` folders to see what files are being created, or the `foo.json` files to see what is being returned by a -particular task. +particular Task. You can also simply delete folders within `out/` if you want to force portions of your project to be rebuilt, e.g. by deleting the `+out/main/+` or `+out/main/compile.*+` folders, but we strongly encourage you to use the xref:Scala_Builtin_Commands.adoc#_clean[`clean` command] instead. diff --git a/docs/modules/ROOT/pages/Tasks.adoc b/docs/modules/ROOT/pages/Tasks.adoc index 44fb22f04d7..2446efc7254 100644 --- a/docs/modules/ROOT/pages/Tasks.adoc +++ b/docs/modules/ROOT/pages/Tasks.adoc @@ -35,7 +35,7 @@ include::example/tasks/2-primary-tasks.adoc[] == Other Tasks -* <<_anonymous_tasks>>, defined using `T.task {...}` +* <<_anonymous_tasks>>, defined using `Task.anon {...}` * <<_persistent_targets>> * <<_inputs>> * <<_workers>> diff --git a/docs/modules/ROOT/pages/The_Mill_Evaluation_Model.adoc b/docs/modules/ROOT/pages/The_Mill_Evaluation_Model.adoc index 91fdd9f68c3..a45052aba1e 100644 --- a/docs/modules/ROOT/pages/The_Mill_Evaluation_Model.adoc +++ b/docs/modules/ROOT/pages/The_Mill_Evaluation_Model.adoc @@ -72,11 +72,11 @@ the overall workflow remains fast even for large projects: * xref:Tasks.adoc#_targets[Target]s only re-evaluate if their input ``Task``s change. - * xref:Tasks.adoc#_persistent_targets[T.persistent]s preserve the `T.dest` folder on disk between runs, + * xref:Tasks.adoc#_persistent_targets[Task.persistent]s preserve the `Task.dest` folder on disk between runs, allowing for finer-grained caching than Mill's default target-by-target caching and invalidation - * xref:Tasks.adoc#_workers[T.worker]s are kept in-memory between runs where possible, and only + * xref:Tasks.adoc#_workers[Task.worker]s are kept in-memory between runs where possible, and only invalidated if their input ``Task``s change as well. * ``Task``s in general are invalidated if the code they depend on changes, diff --git a/docs/modules/ROOT/pages/Thirdparty_Plugins.adoc b/docs/modules/ROOT/pages/Thirdparty_Plugins.adoc index 4c2db996371..12359e75b95 100644 --- a/docs/modules/ROOT/pages/Thirdparty_Plugins.adoc +++ b/docs/modules/ROOT/pages/Thirdparty_Plugins.adoc @@ -63,7 +63,7 @@ import $ivy.`net.mlbox::mill-antlr:0.1.0` import net.mlbox.millantlr.AntlrModule object foo extends ScalaModule with AntlrModule { - override def antlrGrammarSources = T.sources { + override def antlrGrammarSources = Task.sources { Seq(os.pwd/"someGrammar.g4").map(PathRef(_)) } } @@ -587,10 +587,10 @@ the desired information via the `buildInfoMembers` method: // build.sc import $ivy.`com.github.carueda::jbuildinfo:0.1.2` import com.github.carueda.mill.JBuildInfo -import mill.T +import mill.{task, T} object project extends JBuildInfo { - def buildInfoMembers: T[Map[String, String]] = T { + def buildInfoMembers: T[Map[String, String]] = Task { Map( "name" -> "some name", "version" -> "x.y.z" @@ -802,7 +802,7 @@ object project extends ScalaModule with OsgiBundleModule { def bundleSymbolicName = "com.example.project" - def osgiHeaders = T{ super.osgiHeaders().copy( + def osgiHeaders = Task { super.osgiHeaders().copy( `Export-Package` = Seq("com.example.api"), `Bundle-Activator` = Some("com.example.internal.Activator") )} diff --git a/example/basic/1-simple/build.sc b/example/basic/1-simple/build.sc index a15c2fe7d9c..cac481a1881 100644 --- a/example/basic/1-simple/build.sc +++ b/example/basic/1-simple/build.sc @@ -3,7 +3,7 @@ import mill._, scalalib._ object foo extends RootModule with ScalaModule { - def scalaVersion = "2.13.11" + def scalaVersion: Task[String] = "2.13.11" def ivyDeps = Agg( ivy"com.lihaoyi::scalatags:0.12.0", ivy"com.lihaoyi::mainargs:0.6.2" @@ -101,7 +101,7 @@ error: Missing argument: --text // corresponding to the task that created it. e.g. The `assembly` task puts its // metadata output in `out/assembly.json`, and its output files in // `out/assembly.dest`. You can also use `show` to make Mill print out the -// metadata output for a particular task. +// metadata output for a particular Task. // // Additional Mill tasks you would likely need include: // @@ -123,7 +123,7 @@ error: Missing argument: --text // You can run `+mill resolve __+` to see a full list of the different tasks that // are available, `+mill resolve _+` to see the tasks within `foo`, // `mill inspect compile` to inspect a task's doc-comment documentation or what -// it depends on, or `mill show foo.scalaVersion` to show the output of any task. +// it depends on, or `mill show foo.scalaVersion` to show the output of any Task. // // The most common *tasks* that Mill can run are cached *targets*, such as // `compile`, and un-cached *commands* such as `foo.run`. Targets do not diff --git a/example/basic/2-custom-build-logic/build.sc b/example/basic/2-custom-build-logic/build.sc index 3c0c0268cb9..289a9ffa1ce 100644 --- a/example/basic/2-custom-build-logic/build.sc +++ b/example/basic/2-custom-build-logic/build.sc @@ -11,14 +11,14 @@ object foo extends RootModule with ScalaModule { def scalaVersion = "2.13.11" /** Total number of lines in module's source files */ - def lineCount = T{ + def lineCount = Task { allSourceFiles().map(f => os.read.lines(f.path).size).sum } /** Generate resources using lineCount of sources */ - override def resources = T{ - os.write(T.dest / "line-count.txt", "" + lineCount()) - Seq(PathRef(T.dest)) + override def resources = Task { + os.write(Task.dest / "line-count.txt", "" + lineCount()) + Seq(PathRef(Task.dest)) } } diff --git a/example/basic/4-builtin-commands/build.sc b/example/basic/4-builtin-commands/build.sc index 9bd756c579a..4e26facd691 100644 --- a/example/basic/4-builtin-commands/build.sc +++ b/example/basic/4-builtin-commands/build.sc @@ -100,7 +100,7 @@ Inputs: // == show -// By default, Mill does not print out the metadata from evaluating a task. +// By default, Mill does not print out the metadata from evaluating a Task. // Most people would not be interested in e.g. viewing the metadata related to // incremental compilation: they just want to compile their code! However, if you // want to inspect the build to debug problems, you can make Mill show you the diff --git a/example/basicjava/2-custom-build-logic/build.sc b/example/basicjava/2-custom-build-logic/build.sc index b7d92780dea..78a7d4e8c51 100644 --- a/example/basicjava/2-custom-build-logic/build.sc +++ b/example/basicjava/2-custom-build-logic/build.sc @@ -4,13 +4,13 @@ import mill._, javalib._ object foo extends RootModule with JavaModule { /** Total number of lines in module's source files */ - def lineCount = T{ + def lineCount = Task { allSourceFiles().map(f => os.read.lines(f.path).size).sum } /** Generate resources using lineCount of sources */ - override def resources = T{ - os.write(T.dest / "line-count.txt", "" + lineCount()) - Seq(PathRef(T.dest)) + override def resources = Task { + os.write(Task.dest / "line-count.txt", "" + lineCount()) + Seq(PathRef(Task.dest)) } } diff --git a/example/cross/1-simple/build.sc b/example/cross/1-simple/build.sc index f1f9d775f44..ed2b53ec2d9 100644 --- a/example/cross/1-simple/build.sc +++ b/example/cross/1-simple/build.sc @@ -4,9 +4,9 @@ import mill._ object foo extends Cross[FooModule]("2.10", "2.11", "2.12") trait FooModule extends Cross.Module[String] { - def suffix = T { "_" + crossValue } - def bigSuffix = T { "[[[" + suffix() + "]]]" } - def sources = T.sources(millSourcePath) + def suffix = Task { "_" + crossValue } + def bigSuffix = Task { "[[[" + suffix() + "]]]" } + def sources = Task.sources(millSourcePath) } // [graphviz] diff --git a/example/cross/10-static-blog/build.sc b/example/cross/10-static-blog/build.sc index 9d7abac441f..03c2c875a75 100644 --- a/example/cross/10-static-blog/build.sc +++ b/example/cross/10-static-blog/build.sc @@ -26,8 +26,8 @@ val posts = interp.watchValue { object post extends Cross[PostModule](posts) trait PostModule extends Cross.Module[String]{ - def source = T.source(millSourcePath / crossValue) - def render = T{ + def source = Task.source(millSourcePath / crossValue) + def render = Task { val doc = Parser.builder().build().parse(os.read(source().path)) val title = mdNameToTitle(crossValue) val rendered = doctype("html")( @@ -39,40 +39,40 @@ trait PostModule extends Cross.Module[String]{ ) ) - os.write(T.dest / mdNameToHtml(crossValue), rendered) - PathRef(T.dest / mdNameToHtml(crossValue)) + os.write(Task.dest / mdNameToHtml(crossValue), rendered) + PathRef(Task.dest / mdNameToHtml(crossValue)) } } // The last page we need to generate is the index page, listing out the various // blog posts and providing links so we can navigate into them. To do this, we -// need to wrap the `posts` value in a `T.input`, as it can change depending on +// need to wrap the `posts` value in a `Task.input`, as it can change depending on // what `os.list` finds on disk. After that, it's straightforward to render the // `index.html` file we want: -def postsInput = T.input{ posts } +def postsInput = Task.input{ posts } def renderIndexEntry(mdName: String) = { h2(a(mdNameToTitle(mdName), href := ("post/" + mdNameToHtml(mdName)))) } -def index = T{ +def index = Task { val rendered = doctype("html")( html(body(h1("Blog"), postsInput().map(renderIndexEntry))) ) - os.write(T.dest / "index.html", rendered) - PathRef(T.dest / "index.html") + os.write(Task.dest / "index.html", rendered) + PathRef(Task.dest / "index.html") } // Lastly we copy the individual post HTML files and the `index.html` file // into a single target's `.dest` folder, and return it: -def dist = T { - for (post <- T.traverse(post.crossModules)(_.render)()) { - os.copy(post.path, T.dest / "post" / post.path.last, createFolders = true) +def dist = Task { + for (post <- Task.traverse(post.crossModules)(_.render)()) { + os.copy(post.path, Task.dest / "post" / post.path.last, createFolders = true) } - os.copy(index().path, T.dest / "index.html") - PathRef(T.dest) + os.copy(index().path, Task.dest / "index.html") + PathRef(Task.dest) } // Now, you can run `mill dist` to generate the blog: diff --git a/example/cross/11-default-cross-module/build.sc b/example/cross/11-default-cross-module/build.sc index 4ddbdc1800d..04aebd2a583 100644 --- a/example/cross/11-default-cross-module/build.sc +++ b/example/cross/11-default-cross-module/build.sc @@ -3,7 +3,7 @@ import mill._ object foo extends Cross[FooModule]("2.10", "2.11", "2.12") trait FooModule extends Cross.Module[String] { - def suffix = T { "_" + crossValue } + def suffix = Task { "_" + crossValue } } object bar extends Cross[FooModule]("2.10", "2.11", "2.12") { diff --git a/example/cross/2-cross-source-path/build.sc b/example/cross/2-cross-source-path/build.sc index 7c821159800..2d746bb8013 100644 --- a/example/cross/2-cross-source-path/build.sc +++ b/example/cross/2-cross-source-path/build.sc @@ -6,7 +6,7 @@ import mill._ object foo extends Cross[FooModule]("2.10", "2.11", "2.12") trait FooModule extends Cross.Module[String] { def millSourcePath = super.millSourcePath / crossValue - def sources = T.sources(millSourcePath) + def sources = Task.sources(millSourcePath) } // By default, cross modules do not include the cross key as part of the diff --git a/example/cross/3-outside-dependency/build.sc b/example/cross/3-outside-dependency/build.sc index 19b44e2e89f..ac9bb11d94d 100644 --- a/example/cross/3-outside-dependency/build.sc +++ b/example/cross/3-outside-dependency/build.sc @@ -4,12 +4,12 @@ import mill._ object foo extends Cross[FooModule]("2.10", "2.11", "2.12") trait FooModule extends Cross.Module[String] { - def suffix = T { "_" + crossValue } + def suffix = Task { "_" + crossValue } } -def bar = T { s"hello ${foo("2.10").suffix()}" } +def bar = Task { s"hello ${foo("2.10").suffix()}" } -def qux = T { s"hello ${foo("2.10").suffix()} world ${foo("2.12").suffix()}" } +def qux = Task { s"hello ${foo("2.10").suffix()} world ${foo("2.12").suffix()}" } // [graphviz] // .... diff --git a/example/cross/4-cross-dependencies/build.sc b/example/cross/4-cross-dependencies/build.sc index 8a4081ac8cb..c2455a93d16 100644 --- a/example/cross/4-cross-dependencies/build.sc +++ b/example/cross/4-cross-dependencies/build.sc @@ -5,12 +5,12 @@ import mill._ object foo extends mill.Cross[FooModule]("2.10", "2.11", "2.12") trait FooModule extends Cross.Module[String] { - def suffix = T { "_" + crossValue } + def suffix = Task { "_" + crossValue } } object bar extends mill.Cross[BarModule]("2.10", "2.11", "2.12") trait BarModule extends Cross.Module[String] { - def bigSuffix = T { "[[[" + foo(crossValue).suffix() + "]]]" } + def bigSuffix = Task { "[[[" + foo(crossValue).suffix() + "]]]" } } // [graphviz] diff --git a/example/cross/5-multiple-cross-axes/build.sc b/example/cross/5-multiple-cross-axes/build.sc index 1ffaeb48e4c..bef46510382 100644 --- a/example/cross/5-multiple-cross-axes/build.sc +++ b/example/cross/5-multiple-cross-axes/build.sc @@ -12,10 +12,10 @@ val crossMatrix = for { object foo extends mill.Cross[FooModule](crossMatrix) trait FooModule extends Cross.Module2[String, String] { val (crossVersion, platform) = (crossValue, crossValue2) - def suffix = T { "_" + crossVersion + "_" + platform } + def suffix = Task { "_" + crossVersion + "_" + platform } } -def bar = T { s"hello ${foo("2.10", "jvm").suffix()}" } +def bar = Task { s"hello ${foo("2.10", "jvm").suffix()}" } // [graphviz] // .... diff --git a/example/cross/6-axes-extension/build.sc b/example/cross/6-axes-extension/build.sc index 81e557099b6..2c0bcc363c7 100644 --- a/example/cross/6-axes-extension/build.sc +++ b/example/cross/6-axes-extension/build.sc @@ -4,18 +4,18 @@ import mill._ object foo extends Cross[FooModule]("a", "b") trait FooModule extends Cross.Module[String] { - def param1 = T { "Param Value: " + crossValue } + def param1 = Task { "Param Value: " + crossValue } } object foo2 extends Cross[FooModule2](("a", 1), ("b", 2)) trait FooModule2 extends Cross.Module2[String, Int] { - def param1 = T { "Param Value: " + crossValue } - def param2 = T { "Param Value: " + crossValue2 } + def param1 = Task { "Param Value: " + crossValue } + def param2 = Task { "Param Value: " + crossValue2 } } object foo3 extends Cross[FooModule3](("a", 1, true), ("b", 2, false)) trait FooModule3 extends FooModule2 with Cross.Module3[String, Int, Boolean] { - def param3 = T{ "Param Value: " + crossValue3 } + def param3 = Task { "Param Value: " + crossValue3 } } // Starting from an existing cross module with `Cross.Module{N-1}`, diff --git a/example/cross/7-inner-cross-module/build.sc b/example/cross/7-inner-cross-module/build.sc index fd8da725eea..0282dd445ad 100644 --- a/example/cross/7-inner-cross-module/build.sc +++ b/example/cross/7-inner-cross-module/build.sc @@ -3,7 +3,7 @@ import mill._ trait MyModule extends Module{ def crossValue: String def name: T[String] - def param = T { name() + " Param Value: " + crossValue } + def param = Task { name() + " Param Value: " + crossValue } } object foo extends Cross[FooModule]("a", "b") @@ -16,7 +16,7 @@ trait FooModule extends Cross.Module[String] { } } -def baz = T { s"hello ${foo("a").bar.param()}" } +def baz = Task { s"hello ${foo("a").bar.param()}" } // [graphviz] // .... diff --git a/example/cross/8-resolvers/build.sc b/example/cross/8-resolvers/build.sc index 76c76db5b7f..ae31b93cba5 100644 --- a/example/cross/8-resolvers/build.sc +++ b/example/cross/8-resolvers/build.sc @@ -8,12 +8,12 @@ trait MyModule extends Cross.Module[String] { object foo extends mill.Cross[FooModule]("2.10", "2.11", "2.12") trait FooModule extends MyModule { - def suffix = T { "_" + crossValue } + def suffix = Task { "_" + crossValue } } object bar extends mill.Cross[BarModule]("2.10", "2.11", "2.12") trait BarModule extends MyModule { - def bigSuffix = T { "[[[" + foo().suffix() + "]]]" } + def bigSuffix = Task { "[[[" + foo().suffix() + "]]]" } } // You can define an implicit `mill.define.Cross.Resolver` within your diff --git a/example/javabuilds/1-common-config/build.sc b/example/javabuilds/1-common-config/build.sc index 7d3c030dadd..5ff1ff0cf75 100644 --- a/example/javabuilds/1-common-config/build.sc +++ b/example/javabuilds/1-common-config/build.sc @@ -11,19 +11,19 @@ object foo extends RootModule with JavaModule { def mainClass: T[Option[String]] = Some("foo.Foo2") // Add (or replace) source folders for the module to use - def sources = T.sources{ + def sources = Task.sources{ super.sources() ++ Seq(PathRef(millSourcePath / "custom-src")) } // Add (or replace) resource folders for the module to use - def resources = T.sources{ + def resources = Task.sources{ super.resources() ++ Seq(PathRef(millSourcePath / "custom-resources")) } // Generate sources at build time - def generatedSources: T[Seq[PathRef]] = T { + def generatedSources: T[Seq[PathRef]] = Task { for(name <- Seq("A", "B", "C")) os.write( - T.dest / s"Foo$name.java", + Task.dest / s"Foo$name.java", s""" |package foo; |public class Foo$name { @@ -32,7 +32,7 @@ object foo extends RootModule with JavaModule { """.stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } // Pass additional JVM flags when `.run` is called or in the executable diff --git a/example/javabuilds/2-custom-tasks/build.sc b/example/javabuilds/2-custom-tasks/build.sc index 68414d37bd6..c592d7d515f 100644 --- a/example/javabuilds/2-custom-tasks/build.sc +++ b/example/javabuilds/2-custom-tasks/build.sc @@ -5,7 +5,7 @@ import mill._, javalib._ object foo extends RootModule with JavaModule { def ivyDeps = Agg(ivy"net.sourceforge.argparse4j:argparse4j:0.9.0") - def generatedSources: T[Seq[PathRef]] = T { + def generatedSources: T[Seq[PathRef]] = Task { val prettyIvyDeps = for(ivyDep <- ivyDeps()) yield { val org = ivyDep.dep.module.organization.value val name = ivyDep.dep.module.name.value @@ -14,7 +14,7 @@ object foo extends RootModule with JavaModule { } val ivyDepsString = prettyIvyDeps.mkString(" + \"\\n\" + \n") os.write( - T.dest / s"MyDeps.java", + Task.dest / s"MyDeps.java", s""" |package foo; |public class MyDeps { @@ -24,10 +24,10 @@ object foo extends RootModule with JavaModule { """.stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } - def lineCount: T[Int] = T { + def lineCount: T[Int] = Task { sources() .flatMap(pathRef => os.walk(pathRef.path)) .filter(_.ext == "java") @@ -37,7 +37,7 @@ object foo extends RootModule with JavaModule { def forkArgs: T[Seq[String]] = Seq(s"-Dmy.line.count=${lineCount()}") - def printLineCount() = T.command { println(lineCount()) } + def printLineCount() = Task.command { println(lineCount()) } } //// SNIPPET:COMMANDS diff --git a/example/javabuilds/3-override-tasks/build.sc b/example/javabuilds/3-override-tasks/build.sc index f6023f2c2c9..b90d325e025 100644 --- a/example/javabuilds/3-override-tasks/build.sc +++ b/example/javabuilds/3-override-tasks/build.sc @@ -3,9 +3,9 @@ import mill._, javalib._ object foo extends JavaModule { - def sources = T{ + def sources = Task { os.write( - T.dest / "Foo.java", + Task.dest / "Foo.java", """package foo; | |public class Foo { @@ -15,15 +15,15 @@ object foo extends JavaModule { |} """.stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } - def compile = T { + def compile = Task { println("Compiling...") super.compile() } - def run(args: Task[Args] = T.task(Args())) = T.command { + def run(args: Task[Args] = Task.anon(Args())) = Task.command { println("Running..." + args().value.mkString(" ")) super.run(args)() } @@ -31,15 +31,15 @@ object foo extends JavaModule { //// SNIPPET:BUILD2 object foo2 extends JavaModule { - def generatedSources = T{ - os.write(T.dest / "Foo.java", """...""") - Seq(PathRef(T.dest)) + def generatedSources = Task { + os.write(Task.dest / "Foo.java", """...""") + Seq(PathRef(Task.dest)) } } object foo3 extends JavaModule { - def sources = T{ - os.write(T.dest / "Foo.java", """...""") - super.sources() ++ Seq(PathRef(T.dest)) + def sources = Task { + os.write(Task.dest / "Foo.java", """...""") + super.sources() ++ Seq(PathRef(Task.dest)) } } diff --git a/example/javabuilds/9-realistic/build.sc b/example/javabuilds/9-realistic/build.sc index 5c5e00b9cf3..228f04bba2b 100644 --- a/example/javabuilds/9-realistic/build.sc +++ b/example/javabuilds/9-realistic/build.sc @@ -21,9 +21,9 @@ trait MyModule extends JavaModule with PublishModule { object foo extends MyModule { def moduleDeps = Seq(bar, qux) - def generatedSources = T { + def generatedSources = Task { os.write( - T.dest / "Version.java", + Task.dest / "Version.java", s""" |package foo; |public class Version { @@ -33,7 +33,7 @@ object foo extends MyModule { |} """.stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } } diff --git a/example/javamodule/10-downloading-non-maven-jars/build.sc b/example/javamodule/10-downloading-non-maven-jars/build.sc index 611c4319f85..42580e4bca1 100644 --- a/example/javamodule/10-downloading-non-maven-jars/build.sc +++ b/example/javamodule/10-downloading-non-maven-jars/build.sc @@ -2,14 +2,14 @@ import mill._, javalib._ object foo extends RootModule with JavaModule { - def unmanagedClasspath = T { + def unmanagedClasspath = Task { os.write( - T.dest / "fastjavaio.jar", + Task.dest / "fastjavaio.jar", requests.get.stream( "https://github.com/williamfiset/FastJavaIO/releases/download/1.1/fastjavaio.jar" ) ) - Agg(PathRef(T.dest / "fastjavaio.jar")) + Agg(PathRef(Task.dest / "fastjavaio.jar")) } } diff --git a/example/javamodule/12-repository-config/build.sc b/example/javamodule/12-repository-config/build.sc index d95f35beaec..d186c9b0162 100644 --- a/example/javamodule/12-repository-config/build.sc +++ b/example/javamodule/12-repository-config/build.sc @@ -15,18 +15,18 @@ object foo extends JavaModule { ivy"org.apache.commons:commons-text:1.12.0" ) - def repositoriesTask = T.task { super.repositoriesTask() ++ sonatypeReleases } + def repositoriesTask = Task.anon { super.repositoriesTask() ++ sonatypeReleases } } //// SNIPPET:BUILD2 object CustomZincWorkerModule extends ZincWorkerModule with CoursierModule { - def repositoriesTask = T.task { super.repositoriesTask() ++ sonatypeReleases } + def repositoriesTask = Task.anon { super.repositoriesTask() ++ sonatypeReleases } } object bar extends JavaModule { def zincWorker = ModuleRef(CustomZincWorkerModule) // ... rest of your build definitions - def repositoriesTask = T.task { super.repositoriesTask() ++ sonatypeReleases } + def repositoriesTask = Task.anon { super.repositoriesTask() ++ sonatypeReleases } } diff --git a/example/javamodule/13-jni/build.sc b/example/javamodule/13-jni/build.sc index 61035d24e30..78155ce5221 100644 --- a/example/javamodule/13-jni/build.sc +++ b/example/javamodule/13-jni/build.sc @@ -2,16 +2,16 @@ import mill._, javalib._, util.Jvm object foo extends RootModule with JavaModule { // Additional source folder to put C sources - def nativeSources = T.sources(millSourcePath / "native-src") + def nativeSources = Task.sources(millSourcePath / "native-src") // Auto-generate JNI `.h` files from Java classes using Javac - def nativeHeaders = T { - os.proc(Jvm.jdkTool("javac"), "-h", T.dest, "-d", T.dest.toString, allSourceFiles().map(_.path)).call() - PathRef(T.dest) + def nativeHeaders = Task { + os.proc(Jvm.jdkTool("javac"), "-h", Task.dest, "-d", Task.dest.toString, allSourceFiles().map(_.path)).call() + PathRef(Task.dest) } // Compile C - def nativeCompiled = T{ + def nativeCompiled = Task { val cSourceFiles = nativeSources().map(_.path).flatMap(os.walk(_)).filter(_.ext == "c") val output = "libhelloworld.so" os.proc( @@ -20,12 +20,12 @@ object foo extends RootModule with JavaModule { "-I" + sys.props("java.home") + "/include/", // global JVM header files "-I" + sys.props("java.home") + "/include/darwin", "-I" + sys.props("java.home") + "/include/linux", - "-o", T.dest / output, + "-o", Task.dest / output, cSourceFiles ) .call(stdout = os.Inherit) - PathRef(T.dest / output) + PathRef(Task.dest / output) } def forkEnv = Map("HELLO_WORLD_BINARY" -> nativeCompiled().path.toString) diff --git a/example/javamodule/6-annotation-processors/build.sc b/example/javamodule/6-annotation-processors/build.sc index 71de5f6213b..5f55ef57af9 100644 --- a/example/javamodule/6-annotation-processors/build.sc +++ b/example/javamodule/6-annotation-processors/build.sc @@ -35,7 +35,7 @@ Test foo.HelloWorldTest.testSimple finished... object bar extends JavaModule { def compileIvyDeps = Agg(ivy"org.projectlombok:lombok:1.18.34") - def processors = T{ + def processors = Task { defaultResolver().resolveDeps(Agg(ivy"org.projectlombok:lombok:1.18.34")) } diff --git a/example/javamodule/8-unmanaged-jars/build.sc b/example/javamodule/8-unmanaged-jars/build.sc index 8d1449ccd96..f588c499dbf 100644 --- a/example/javamodule/8-unmanaged-jars/build.sc +++ b/example/javamodule/8-unmanaged-jars/build.sc @@ -2,7 +2,7 @@ import mill._, javalib._ object foo extends RootModule with JavaModule { - def unmanagedClasspath = T { + def unmanagedClasspath = Task { if (!os.exists(millSourcePath / "lib")) Agg() else Agg.from(os.list(millSourcePath / "lib").map(PathRef(_))) } diff --git a/example/javaweb/4-hello-micronaut/build.sc b/example/javaweb/4-hello-micronaut/build.sc index 6d37e1a9688..90f2df2547a 100644 --- a/example/javaweb/4-hello-micronaut/build.sc +++ b/example/javaweb/4-hello-micronaut/build.sc @@ -22,7 +22,7 @@ object hello extends RootModule with MicronautModule { trait MicronautModule extends MavenModule{ def micronautVersion: String - def processors = T{ + def processors = Task { defaultResolver().resolveDeps( Agg( ivy"io.micronaut.data:micronaut-data-processor:4.7.0", diff --git a/example/javaweb/5-todo-micronaut/build.sc b/example/javaweb/5-todo-micronaut/build.sc index 77482a4b507..d9af11b8891 100644 --- a/example/javaweb/5-todo-micronaut/build.sc +++ b/example/javaweb/5-todo-micronaut/build.sc @@ -39,7 +39,7 @@ object hello extends RootModule with MicronautModule { trait MicronautModule extends MavenModule{ def micronautVersion: String - def processors = T { + def processors = Task { defaultResolver().resolveDeps( Agg( ivy"io.micronaut.data:micronaut-data-processor:4.7.0", diff --git a/example/misc/3-import-file-ivy/build.sc b/example/misc/3-import-file-ivy/build.sc index 97fab9d34e0..61f5309abad 100644 --- a/example/misc/3-import-file-ivy/build.sc +++ b/example/misc/3-import-file-ivy/build.sc @@ -6,10 +6,10 @@ object foo extends RootModule with ScalaModule { def scalaVersion = myScalaVersion def ivyDeps = Agg(ivy"com.lihaoyi::os-lib:0.9.1") - def htmlSnippet = T{ div(h1("hello"), p("world")).toString } - def resources = T.sources{ - os.write(T.dest / "snippet.txt", htmlSnippet()) - super.resources() ++ Seq(PathRef(T.dest)) + def htmlSnippet = Task { div(h1("hello"), p("world")).toString } + def resources = Task.sources{ + os.write(Task.dest / "snippet.txt", htmlSnippet()) + super.resources() ++ Seq(PathRef(Task.dest)) } } diff --git a/example/misc/4-mill-build-folder/build.sc b/example/misc/4-mill-build-folder/build.sc index eac7f4b71d2..400363289c8 100644 --- a/example/misc/4-mill-build-folder/build.sc +++ b/example/misc/4-mill-build-folder/build.sc @@ -6,10 +6,10 @@ object foo extends RootModule with ScalaModule { def scalaVersion = millbuild.ScalaVersion.myScalaVersion def ivyDeps = Agg(ivy"com.lihaoyi::os-lib:0.9.1") - def htmlSnippet = T{ h1("hello").toString } - def resources = T.sources{ - os.write(T.dest / "snippet.txt", htmlSnippet()) - super.resources() ++ Seq(PathRef(T.dest)) + def htmlSnippet = Task { h1("hello").toString } + def resources = Task.sources{ + os.write(Task.dest / "snippet.txt", htmlSnippet()) + super.resources() ++ Seq(PathRef(Task.dest)) } def forkArgs = Seq( diff --git a/example/misc/4-mill-build-folder/mill-build/build.sc b/example/misc/4-mill-build-folder/mill-build/build.sc index 6cbf953c3ca..95e67e90e2a 100644 --- a/example/misc/4-mill-build-folder/mill-build/build.sc +++ b/example/misc/4-mill-build-folder/mill-build/build.sc @@ -4,9 +4,9 @@ object millbuild extends MillBuildRootModule{ val scalatagsVersion = "0.12.0" def ivyDeps = Agg(ivy"com.lihaoyi::scalatags:$scalatagsVersion") - def generatedSources = T { + def generatedSources = Task { os.write( - T.dest / "DepVersions.scala", + Task.dest / "DepVersions.scala", s""" |package millbuild |object DepVersions{ @@ -14,6 +14,6 @@ object millbuild extends MillBuildRootModule{ |} """.stripMargin ) - super.generatedSources() ++ Seq(PathRef(T.dest)) + super.generatedSources() ++ Seq(PathRef(Task.dest)) } } \ No newline at end of file diff --git a/example/misc/5-module-run-task/build.sc b/example/misc/5-module-run-task/build.sc index 96ff9bf060d..7d3f6494c4a 100644 --- a/example/misc/5-module-run-task/build.sc +++ b/example/misc/5-module-run-task/build.sc @@ -5,9 +5,9 @@ object foo extends ScalaModule { def moduleDeps = Seq(bar) def ivyDeps = Agg(ivy"com.lihaoyi::mainargs:0.4.0") - def barWorkingDir = T{ T.dest } - def sources = T{ - bar.run(T.task(Args(barWorkingDir(), super.sources().map(_.path))))() + def barWorkingDir = Task { Task.dest } + def sources = Task { + bar.run(Task.anon(Args(barWorkingDir(), super.sources().map(_.path))))() Seq(PathRef(barWorkingDir())) } } diff --git a/example/scalabuilds/1-common-config/build.sc b/example/scalabuilds/1-common-config/build.sc index 4751ff3379a..8b0f13683a5 100644 --- a/example/scalabuilds/1-common-config/build.sc +++ b/example/scalabuilds/1-common-config/build.sc @@ -19,19 +19,19 @@ object foo extends RootModule with ScalaModule { def mainClass: T[Option[String]] = Some("foo.Foo2") // Add (or replace) source folders for the module to use - def sources = T.sources{ + def sources = Task.sources{ super.sources() ++ Seq(PathRef(millSourcePath / "custom-src")) } // Add (or replace) resource folders for the module to use - def resources = T.sources{ + def resources = Task.sources{ super.resources() ++ Seq(PathRef(millSourcePath / "custom-resources")) } // Generate sources at build time - def generatedSources: T[Seq[PathRef]] = T { + def generatedSources: T[Seq[PathRef]] = Task { for(name <- Seq("A", "B", "C")) os.write( - T.dest / s"Foo$name.scala", + Task.dest / s"Foo$name.scala", s""" |package foo |object Foo$name { @@ -40,7 +40,7 @@ object foo extends RootModule with ScalaModule { """.stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } // Pass additional JVM flags when `.run` is called or in the executable @@ -57,7 +57,7 @@ object foo extends RootModule with ScalaModule { //// SNIPPET:END // -// Note the use of `millSourcePath`, `T.dest`, and `PathRef` when preforming +// Note the use of `millSourcePath`, `Task.dest`, and `PathRef` when preforming // various filesystem operations: // // 1. `millSourcePath` refers to the base path of the module. For the root @@ -65,7 +65,7 @@ object foo extends RootModule with ScalaModule { // the module path e.g. for module `foo.bar.qux` the `millSourcePath` would // be `foo/bar/qux`. This can also be overriden if necessary // -// 2. `T.dest` refers to the destination folder for a task in the `out/` +// 2. `Task.dest` refers to the destination folder for a task in the `out/` // folder. This is unique to each task, and can act as both a scratch space // for temporary computations as well as a place to put "output" files, // without worrying about filesystem conflicts with other tasks diff --git a/example/scalabuilds/2-custom-tasks/build.sc b/example/scalabuilds/2-custom-tasks/build.sc index 669268b2815..125f3cc87d9 100644 --- a/example/scalabuilds/2-custom-tasks/build.sc +++ b/example/scalabuilds/2-custom-tasks/build.sc @@ -16,7 +16,7 @@ object foo extends RootModule with ScalaModule { def scalaVersion = "2.13.8" def ivyDeps = Agg(ivy"com.lihaoyi::mainargs:0.4.0") - def generatedSources: T[Seq[PathRef]] = T { + def generatedSources: T[Seq[PathRef]] = Task { val prettyIvyDeps = for(ivyDep <- ivyDeps()) yield { val org = ivyDep.dep.module.organization.value val name = ivyDep.dep.module.name.value @@ -24,7 +24,7 @@ object foo extends RootModule with ScalaModule { s"""("$org", "$name", "$version")""" } os.write( - T.dest / s"MyDeps.scala", + Task.dest / s"MyDeps.scala", s""" |package foo |object MyDeps { @@ -35,10 +35,10 @@ object foo extends RootModule with ScalaModule { """.stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } - def lineCount: T[Int] = T { + def lineCount: T[Int] = Task { sources() .flatMap(pathRef => os.walk(pathRef.path)) .filter(_.ext == "scala") @@ -48,12 +48,12 @@ object foo extends RootModule with ScalaModule { def forkArgs: T[Seq[String]] = Seq(s"-Dmy.line.count=${lineCount()}") - def printLineCount() = T.command { println(lineCount()) } + def printLineCount() = Task.command { println(lineCount()) } } //// SNIPPET:END -// Mill lets you define new cached Targets using the `T {...}` syntax, +// Mill lets you define new cached Targets using the `Task {...}` syntax, // depending on existing Targets e.g. `foo.sources` via the `foo.sources()` // syntax to extract their current value, as shown in `lineCount` above. The // return-type of a Target has to be JSON-serializable (using @@ -91,14 +91,14 @@ my.line.count: 14 // download files using `requests.get`, shell-out to Webpack // to compile some Javascript, generate sources to feed into a compiler, or // create some custom jar/zip assembly with the files you want , all of these -// can simply be custom targets with your code running in the `T {...}` block. +// can simply be custom targets with your code running in the `Task {...}` block. // // You can create arbitrarily long chains of dependent targets, and Mill will // handle the re-evaluation and caching of the targets' output for you. -// Mill also provides you a `T.dest` folder for you to use as scratch space or +// Mill also provides you a `Task.dest` folder for you to use as scratch space or // to store files you want to return: all files a task creates should live -// within `T.dest`, and any files you want to modify should be copied into -// `T.dest` before being modified. That ensures that the files belonging to a +// within `Task.dest`, and any files you want to modify should be copied into +// `Task.dest` before being modified. That ensures that the files belonging to a // particular target all live in one place, avoiding file-name conflicts and // letting Mill automatically invalidate the files when the target's inputs // change. \ No newline at end of file diff --git a/example/scalabuilds/3-override-tasks/build.sc b/example/scalabuilds/3-override-tasks/build.sc index 8ecca2454a3..9f1134c7690 100644 --- a/example/scalabuilds/3-override-tasks/build.sc +++ b/example/scalabuilds/3-override-tasks/build.sc @@ -4,9 +4,9 @@ import mill._, scalalib._ object foo extends ScalaModule { def scalaVersion = "2.13.8" - def sources = T{ + def sources = Task { os.write( - T.dest / "Foo.scala", + Task.dest / "Foo.scala", """package foo |object Foo { | def main(args: Array[String]): Unit = { @@ -15,15 +15,15 @@ object foo extends ScalaModule { |} """.stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } - def compile = T { + def compile = Task { println("Compiling...") super.compile() } - def run(args: Task[Args] = T.task(Args())) = T.command { + def run(args: Task[Args] = Task.anon(Args())) = Task.command { println("Running..." + args().value.mkString(" ")) super.run(args)() } @@ -32,10 +32,10 @@ object foo extends ScalaModule { //// SNIPPET:END // You can re-define targets and commands to override them, and use `super` if you -// want to refer to the originally defined task. The above example shows how to +// want to refer to the originally defined Task. The above example shows how to // override `compile` and `run` to add additional logging messages, and we -// override `sources` which was `T.sources` for the `src/` folder with a plain -// `T{...}` target that generates the necessary source files on-the-fly. +// override `sources` which was `Task.sources` for the `src/` folder with a plain +// `Task {...}` target that generates the necessary source files on-the-fly. // // Note that this example *replaces* your `src/` folder with the generated // sources. If you want to *add* generated sources, you can either override @@ -47,18 +47,18 @@ object foo extends ScalaModule { object foo2 extends ScalaModule { def scalaVersion = "2.13.8" - def generatedSources = T{ - os.write(T.dest / "Foo.scala", """...""") - Seq(PathRef(T.dest)) + def generatedSources = Task { + os.write(Task.dest / "Foo.scala", """...""") + Seq(PathRef(Task.dest)) } } object foo3 extends ScalaModule { def scalaVersion = "2.13.8" - def sources = T{ - os.write(T.dest / "Foo.scala", """...""") - super.sources() ++ Seq(PathRef(T.dest)) + def sources = Task { + os.write(Task.dest / "Foo.scala", """...""") + super.sources() ++ Seq(PathRef(Task.dest)) } } diff --git a/example/scalabuilds/9-realistic/build.sc b/example/scalabuilds/9-realistic/build.sc index de6b0de55bf..4e3627977d1 100644 --- a/example/scalabuilds/9-realistic/build.sc +++ b/example/scalabuilds/9-realistic/build.sc @@ -28,9 +28,9 @@ object foo extends Cross[FooModule](scalaVersions) trait FooModule extends MyScalaModule { def moduleDeps = Seq(bar(), qux) - def generatedSources = T { + def generatedSources = Task { os.write( - T.dest / "Version.scala", + Task.dest / "Version.scala", s""" |package foo |object Version{ @@ -38,7 +38,7 @@ trait FooModule extends MyScalaModule { |} """.stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } } diff --git a/example/scalamodule/10-downloading-non-maven-jars/build.sc b/example/scalamodule/10-downloading-non-maven-jars/build.sc index cf3e5154602..19a119a9ec2 100644 --- a/example/scalamodule/10-downloading-non-maven-jars/build.sc +++ b/example/scalamodule/10-downloading-non-maven-jars/build.sc @@ -3,14 +3,14 @@ import mill._, scalalib._ object foo extends RootModule with ScalaModule { def scalaVersion = "2.13.8" - def unmanagedClasspath = T { + def unmanagedClasspath = Task { os.write( - T.dest / "fastjavaio.jar", + Task.dest / "fastjavaio.jar", requests.get.stream( "https://github.com/williamfiset/FastJavaIO/releases/download/1.1/fastjavaio.jar" ) ) - Agg(PathRef(T.dest / "fastjavaio.jar")) + Agg(PathRef(Task.dest / "fastjavaio.jar")) } } diff --git a/example/scalamodule/12-repository-config/build.sc b/example/scalamodule/12-repository-config/build.sc index b24690e8a5a..ab09dc614fb 100644 --- a/example/scalamodule/12-repository-config/build.sc +++ b/example/scalamodule/12-repository-config/build.sc @@ -19,7 +19,7 @@ object foo extends ScalaModule { ivy"com.lihaoyi::mainargs:0.6.2" ) - def repositoriesTask = T.task { + def repositoriesTask = Task.anon { super.repositoriesTask() ++ sonatypeReleases } } @@ -51,7 +51,7 @@ object foo extends ScalaModule { //// SNIPPET:BUILD2 object CustomZincWorkerModule extends ZincWorkerModule with CoursierModule { - def repositoriesTask = T.task { super.repositoriesTask() ++ sonatypeReleases } + def repositoriesTask = Task.anon { super.repositoriesTask() ++ sonatypeReleases } } object bar extends ScalaModule { @@ -59,7 +59,7 @@ object bar extends ScalaModule { def zincWorker = ModuleRef(CustomZincWorkerModule) // ... rest of your build definitions - def repositoriesTask = T.task {super.repositoriesTask() ++ sonatypeReleases} + def repositoriesTask = Task.anon {super.repositoriesTask() ++ sonatypeReleases} } //// SNIPPET:END diff --git a/example/scalamodule/8-unmanaged-jars/build.sc b/example/scalamodule/8-unmanaged-jars/build.sc index 7b8df2c0fb5..ff21e38233e 100644 --- a/example/scalamodule/8-unmanaged-jars/build.sc +++ b/example/scalamodule/8-unmanaged-jars/build.sc @@ -3,7 +3,7 @@ import mill._, scalalib._ object foo extends RootModule with ScalaModule { def scalaVersion = "2.13.8" - def unmanagedClasspath = T { + def unmanagedClasspath = Task { if (!os.exists(millSourcePath / "lib")) Agg() else Agg.from(os.list(millSourcePath / "lib").map(PathRef(_))) } diff --git a/example/tasks/1-task-graph/build.sc b/example/tasks/1-task-graph/build.sc index 023ede2cbea..64b62bb98b6 100644 --- a/example/tasks/1-task-graph/build.sc +++ b/example/tasks/1-task-graph/build.sc @@ -4,23 +4,23 @@ import mill._ def mainClass: T[Option[String]] = Some("foo.Foo") -def sources = T.source(millSourcePath / "src") -def resources = T.source(millSourcePath / "resources") +def sources = Task.source(millSourcePath / "src") +def resources = Task.source(millSourcePath / "resources") -def compile = T { +def compile = Task { val allSources = os.walk(sources().path) - os.proc("javac", allSources, "-d", T.dest).call() - PathRef(T.dest) + os.proc("javac", allSources, "-d", Task.dest).call() + PathRef(Task.dest) } -def assembly = T { - for(p <- Seq(compile(), resources())) os.copy(p.path, T.dest, mergeFolders = true) +def assembly = Task { + for(p <- Seq(compile(), resources())) os.copy(p.path, Task.dest, mergeFolders = true) val mainFlags = mainClass().toSeq.flatMap(Seq("-e", _)) - os.proc("jar", "-c", mainFlags, "-f", T.dest / s"assembly.jar", ".") - .call(cwd = T.dest) + os.proc("jar", "-c", mainFlags, "-f", Task.dest / s"assembly.jar", ".") + .call(cwd = Task.dest) - PathRef(T.dest / s"assembly.jar") + PathRef(Task.dest / s"assembly.jar") } // This code defines the following task graph, with the boxes being the tasks @@ -39,8 +39,8 @@ def assembly = T { // // This example does not use any of Mill's builtin support for building Java or // Scala projects, and instead builds a pipeline "from scratch" using Mill -// tasks and `javac`/`jar`/`java` subprocesses. We define `T.source` folders, -// plain `T{...}` targets that depend on them, and a `T.command`. +// tasks and `javac`/`jar`/`java` subprocesses. We define `Task.source` folders, +// plain `Task {...}` targets that depend on them, and a `Task.command`. /** Usage diff --git a/example/tasks/2-primary-tasks/build.sc b/example/tasks/2-primary-tasks/build.sc index 934d824e044..d07c8598f08 100644 --- a/example/tasks/2-primary-tasks/build.sc +++ b/example/tasks/2-primary-tasks/build.sc @@ -1,37 +1,37 @@ // There are three primary kinds of _Tasks_ that you should care about: // -// * <<_sources>>, defined using `T.sources {...}` -// * <<_targets>>, defined using `T {...}` -// * <<_commands>>, defined using `T.command {...}` +// * <<_sources>>, defined using `Task.sources {...}` +// * <<_targets>>, defined using `Task {...}` +// * <<_commands>>, defined using `Task.command {...}` // === Sources import mill.{Module, T, _} -def sources = T.source { millSourcePath / "src" } -def resources = T.source { millSourcePath / "resources" } +def sources = Task.source { millSourcePath / "src" } +def resources = Task.source { millSourcePath / "resources" } -// ``Source``s are defined using `T.source{...}` taking one `os.Path`, or `T.sources{...}`, +// ``Source``s are defined using `Task.source{...}` taking one `os.Path`, or `Task.sources{...}`, // taking multiple ``os.Path``s as arguments. A ``Source``'s': // its build signature/`hashCode` depends not just on the path // it refers to (e.g. `foo/bar/baz`) but also the MD5 hash of the filesystem // tree under that path. // -// `T.source` and `T.sources` are most common inputs in any Mill build: +// `Task.source` and `Task.sources` are most common inputs in any Mill build: // they watch source files and folders and cause downstream targets to // re-compute if a change is detected. // === Targets -def allSources = T { +def allSources = Task { os.walk(sources().path) .filter(_.ext == "java") .map(PathRef(_)) } -def lineCount: T[Int] = T { +def lineCount: T[Int] = Task { println("Computing line count") allSources() .map(p => os.read.lines(p.path).size) @@ -48,9 +48,9 @@ def lineCount: T[Int] = T { // } // .... // -// ``Target``s are defined using the `def foo = T {...}` syntax, and dependencies +// ``Target``s are defined using the `def foo = Task {...}` syntax, and dependencies // on other targets are defined using `foo()` to extract the value from them. -// Apart from the `foo()` calls, the `T {...}` block contains arbitrary code that +// Apart from the `foo()` calls, the `Task {...}` block contains arbitrary code that // does some work and returns a result. // If a target's inputs change but its output does not, e.g. someone changes a @@ -74,31 +74,31 @@ Computing line count // line, or use `show` if you want to see the JSON content or pipe it to // external tools. -// Each target, e.g. `classFiles`, is assigned a {mill-doc-url}/api/latest/mill/api/Ctx.html#dest:os.Path[T.dest] +// Each target, e.g. `classFiles`, is assigned a {mill-doc-url}/api/latest/mill/api/Ctx.html#dest:os.Path[Task.dest] // folder e.g. `out/classFiles.dest/` on disk as scratch space & to store its // output files , and its returned metadata is automatically JSON-serialized // and stored at `out/classFiles.json`. If you want to return a file or a set -// of files as the result of a `Target`, write them to disk within your `T.dest` +// of files as the result of a `Target`, write them to disk within your `Task.dest` // folder and return a `PathRef()` that referencing the files or folders // you want to return: -def classFiles = T { +def classFiles = Task { println("Generating classfiles") - os.proc("javac", allSources().map(_.path), "-d", T.dest) - .call(cwd = T.dest) + os.proc("javac", allSources().map(_.path), "-d", Task.dest) + .call(cwd = Task.dest) - PathRef(T.dest) + PathRef(Task.dest) } -def jar = T { +def jar = Task { println("Generating jar") - os.copy(classFiles().path, T.dest, mergeFolders = true) - os.copy(resources().path, T.dest, mergeFolders = true) + os.copy(classFiles().path, Task.dest, mergeFolders = true) + os.copy(resources().path, Task.dest, mergeFolders = true) - os.proc("jar", "-cfe", T.dest / "foo.jar", "foo.Foo", ".").call(cwd = T.dest) + os.proc("jar", "-cfe", Task.dest / "foo.jar", "foo.Foo", ".").call(cwd = Task.dest) - PathRef(T.dest / "foo.jar") + PathRef(Task.dest / "foo.jar") } // [graphviz] @@ -135,7 +135,7 @@ Generating jar // in `def largeFile` running even though the `largeFile()` branch of the // `if` conditional does not get used: -def largeFile = T { +def largeFile = Task { println("Finding Largest File") allSources() .map(_.path) @@ -143,7 +143,7 @@ def largeFile = T { .maxBy(os.read.lines(_).size) } -def hugeFileName = T{ +def hugeFileName = Task { if (lineCount() > 999) largeFile().last else "" } @@ -181,7 +181,7 @@ object ClassFileData { implicit val rw: upickle.default.ReadWriter[ClassFileData] = upickle.default.macroRW } -def summarizeClassFileStats = T{ +def summarizeClassFileStats = Task { val files = os.walk(classFiles().path) ClassFileData( totalFileSize = files.map(os.size(_)).sum, @@ -213,7 +213,7 @@ def summarizeClassFileStats = T{ // === Commands -def run(args: String*) = T.command { +def run(args: String*) = Task.command { os.proc( "java", "-cp", s"${classFiles().path}:${resources().path}", @@ -235,11 +235,11 @@ def run(args: String*) = T.command { // } // .... -// Defined using `T.command {...}` syntax, ``Command``s can run arbitrary code, with +// Defined using `Task.command {...}` syntax, ``Command``s can run arbitrary code, with // dependencies declared using the same `foo()` syntax (e.g. `classFiles()` above). // Commands can be parametrized, but their output is not cached, so they will // re-evaluate every time even if none of their inputs have changed. -// A command with no parameter is defined as `def myCommand() = T.command {...}`. +// A command with no parameter is defined as `def myCommand() = Task.command {...}`. // It is a compile error if `()` is missing. // // Like <<_targets>>, a command only evaluates after all its upstream @@ -260,8 +260,8 @@ def run(args: String*) = T.command { // trait Foo extends Module { - def sourceRoots = T.sources(millSourcePath / "src") - def sourceContents = T{ + def sourceRoots = Task.sources(millSourcePath / "src") + def sourceContents = Task { sourceRoots() .flatMap(pref => os.walk(pref.path)) .filter(_.ext == "txt") @@ -271,8 +271,8 @@ trait Foo extends Module { } trait Bar extends Foo { - def additionalSources = T.sources(millSourcePath / "src2") - def sourceRoots = T { super.sourceRoots() ++ additionalSources() } + def additionalSources = Task.sources(millSourcePath / "src2") + def sourceRoots = Task { super.sourceRoots() ++ additionalSources() } } object bar extends Bar diff --git a/example/tasks/3-anonymous-tasks/build.sc b/example/tasks/3-anonymous-tasks/build.sc index 24f3678fd68..4c10d9fea23 100644 --- a/example/tasks/3-anonymous-tasks/build.sc +++ b/example/tasks/3-anonymous-tasks/build.sc @@ -1,17 +1,17 @@ import mill._, define.Task -def data = T.source(millSourcePath / "data") +def data = Task.source(millSourcePath / "data") -def anonTask(fileName: String): Task[String] = T.task { +def anonTask(fileName: String): Task[String] = Task.anon { os.read(data().path / fileName) } -def helloFileData = T { anonTask("hello.txt")() } -def printFileData(fileName: String) = T.command { +def helloFileData = Task { anonTask("hello.txt")() } +def printFileData(fileName: String) = Task.command { println(anonTask(fileName)()) } -// You can define anonymous tasks using the `T.task {...}` syntax. These are +// You can define anonymous tasks using the `Task.anon {...}` syntax. These are // not runnable from the command-line, but can be used to share common code you // find yourself repeating in ``Target``s and ``Command``s. // diff --git a/example/tasks/4-inputs/build.sc b/example/tasks/4-inputs/build.sc index a2c06705113..fe8ca6f169c 100644 --- a/example/tasks/4-inputs/build.sc +++ b/example/tasks/4-inputs/build.sc @@ -1,13 +1,13 @@ import mill._ -def myInput = T.input { - os.proc("git", "rev-parse", "HEAD").call(cwd = T.workspace) +def myInput = Task.input { + os.proc("git", "rev-parse", "HEAD").call(cwd = Task.workspace) .out .text() .trim() } -// A generalization of <<_sources>>, ``T.input``s are tasks that re-evaluate +// A generalization of <<_sources>>, ``Task.input``s are tasks that re-evaluate // _every time_ (unlike <<_anonymous_tasks>>), containing an // arbitrary block of code. // @@ -17,10 +17,10 @@ def myInput = T.input { // that target does not have any `Task` inputs and so will never re-compute // even if the external `git` status changes: -def gitStatusTarget = T { +def gitStatusTarget = Task { "v-" + os.proc("git", "log", "-1", "--pretty=format:%h-%B ") - .call(cwd = T.workspace) + .call(cwd = Task.workspace) .out .text() .trim() @@ -46,16 +46,16 @@ def gitStatusTarget = T { // `gitStatusTarget` will continue to use any previously cached value, and // ``gitStatusTarget``'s output will be out of date! -// To fix this, you can wrap your `git log` in a `T.input`: +// To fix this, you can wrap your `git log` in a `Task.input`: -def gitStatusInput = T.input { +def gitStatusInput = Task.input { os.proc("git", "log", "-1", "--pretty=format:%h-%B ") - .call(cwd = T.workspace) + .call(cwd = Task.workspace) .out .text() .trim() } -def gitStatusTarget2 = T { "v-" + gitStatusInput() } +def gitStatusTarget2 = Task { "v-" + gitStatusInput() } // This makes `gitStatusInput` to always re-evaluate every build, and only if // the output of `gitStatusInput` changes will `gitStatusTarget2` re-compute @@ -74,7 +74,7 @@ def gitStatusTarget2 = T { "v-" + gitStatusInput() } */ -// Note that because ``T.input``s re-evaluate every time, you should ensure that the -// code you put in `T.input` runs quickly. Ideally it should just be a simple check +// Note that because ``Task.input``s re-evaluate every time, you should ensure that the +// code you put in `Task.input` runs quickly. Ideally it should just be a simple check // "did anything change?" and any heavy-lifting should be delegated to downstream // targets where it can be cached if possible. diff --git a/example/tasks/5-persistent-targets/build.sc b/example/tasks/5-persistent-targets/build.sc index 0844970fbba..80b5672adad 100644 --- a/example/tasks/5-persistent-targets/build.sc +++ b/example/tasks/5-persistent-targets/build.sc @@ -1,27 +1,27 @@ -// Persistent targets defined using `T.persistent` are similar to normal -// ``Target``s, except their `T.dest` folder is not cleared before every +// Persistent targets defined using `Task.persistent` are similar to normal +// ``Target``s, except their `Task.dest` folder is not cleared before every // evaluation. This makes them useful for caching things on disk in a more // fine-grained manner than Mill's own Target-level caching. // -// Below is a semi-realistic example of using a `T.persistent` target: +// Below is a semi-realistic example of using a `Task.persistent` target: import mill._, scalalib._ import java.util.Arrays import java.io.ByteArrayOutputStream import java.util.zip.GZIPOutputStream -def data = T.source(millSourcePath / "data") +def data = Task.source(millSourcePath / "data") -def compressedData = T.persistent{ +def compressedData = Task.persistent{ println("Evaluating compressedData") - os.makeDir.all(T.dest / "cache") - os.remove.all(T.dest / "compressed") + os.makeDir.all(Task.dest / "cache") + os.remove.all(Task.dest / "compressed") for(p <- os.list(data().path)){ - val compressedPath = T.dest / "compressed" / s"${p.last}.gz" + val compressedPath = Task.dest / "compressed" / s"${p.last}.gz" val bytes = os.read.bytes(p) val hash = Arrays.hashCode(bytes) - val cachedPath = T.dest / "cache" / hash.toHexString + val cachedPath = Task.dest / "cache" / hash.toHexString if (!os.exists(cachedPath)) { println("Compressing: " + p.last) os.write(cachedPath, compressBytes(bytes)) @@ -31,7 +31,7 @@ def compressedData = T.persistent{ os.copy(cachedPath, compressedPath, createFolders = true) } - os.list(T.dest / "compressed").map(PathRef(_)) + os.list(Task.dest / "compressed").map(PathRef(_)) } def compressBytes(input: Array[Byte]) = { @@ -51,7 +51,7 @@ def compressBytes(input: Array[Byte]) = { // Since persistent targets have long-lived state on disk that lives beyond a // single evaluation, this raises the possibility of the disk contents getting // into a bad state and causing all future evaluations to fail. It is left up -// to the person implementing the `T.persistent` to ensure their implementation +// to the person implementing the `Task.persistent` to ensure their implementation // is eventually consistent. You can also use `mill clean` to manually purge // the disk contents to start fresh. diff --git a/example/tasks/6-workers/build.sc b/example/tasks/6-workers/build.sc index a0bfd059e79..f4c486e2c58 100644 --- a/example/tasks/6-workers/build.sc +++ b/example/tasks/6-workers/build.sc @@ -1,4 +1,4 @@ -// Mill workers defined using `T.worker` are long-lived in-memory objects that +// Mill workers defined using `Task.worker` are long-lived in-memory objects that // can persistent across multiple evaluations. These are similar to persistent // targets in that they let you cache things, but the fact that they let you // cache the worker object in-memory allows for greater performance and @@ -11,19 +11,19 @@ import java.util.Arrays import java.io.ByteArrayOutputStream import java.util.zip.GZIPOutputStream -def data = T.source(millSourcePath / "data") +def data = Task.source(millSourcePath / "data") -def compressWorker = T.worker{ new CompressWorker(T.dest) } +def compressWorker = Task.worker{ new CompressWorker(Task.dest) } -def compressedData = T{ +def compressedData = Task { println("Evaluating compressedData") for(p <- os.list(data().path)){ os.write( - T.dest / s"${p.last}.gz", + Task.dest / s"${p.last}.gz", compressWorker().compress(p.last, os.read.bytes(p)) ) } - os.list(T.dest).map(PathRef(_)) + os.list(Task.dest).map(PathRef(_)) } class CompressWorker(dest: os.Path){ @@ -69,7 +69,7 @@ def compressBytes(input: Array[Byte]) = { // workers after every command. Commands run repeatedly using `--watch` will // also preserve the workers between them. // -// Workers can also make use of their `T.dest` folder as a cache that persist +// Workers can also make use of their `Task.dest` folder as a cache that persist // when the worker shuts down, as a second layer of caching. The example usage // below demonstrates how using the `--no-server` flag will make the worker // read from its disk cache, where it would have normally read from its @@ -121,4 +121,4 @@ class MyWorker() extends AutoCloseable { override def close() = { /* cleanup and free resources */ } } -def myWorker = T.worker { new MyWorker() } +def myWorker = Task.worker { new MyWorker() } diff --git a/example/tasks/7-modules/build.sc b/example/tasks/7-modules/build.sc index 4eec984adae..6d78d45aa30 100644 --- a/example/tasks/7-modules/build.sc +++ b/example/tasks/7-modules/build.sc @@ -7,9 +7,9 @@ import mill._ object foo extends Module { - def bar = T { "hello" } + def bar = Task { "hello" } object qux extends Module { - def baz = T { "world" } + def baz = Task { "world" } } } @@ -60,7 +60,7 @@ object foo extends Module { trait FooModule extends Module { def bar: T[String] // required override - def qux = T { bar() + " world" } + def qux = Task { bar() + " world" } } object foo1 extends FooModule{ @@ -69,7 +69,7 @@ object foo1 extends FooModule{ } object foo2 extends FooModule { def bar = "hi" - def baz = T { qux() + " I am Cow" } // add a new `def` + def baz = Task { qux() + " I am Cow" } // add a new `def` } // This generates the following module tree and task graph, with the dotted boxes and @@ -95,7 +95,7 @@ object foo2 extends FooModule { // } // .... -// Note that the `override` keyword is optional in mill, as is `T{...}` wrapper. +// Note that the `override` keyword is optional in mill, as is `Task {...}` wrapper. /** Usage @@ -131,8 +131,8 @@ object foo2 extends FooModule { // module expects its input files to be on disk. trait MyModule extends Module{ - def sources = T.source(millSourcePath / "sources") - def target = T { "hello " + os.list(sources().path).map(os.read(_)).mkString(" ") } + def sources = Task.source(millSourcePath / "sources") + def target = Task { "hello " + os.list(sources().path).map(os.read(_)).mkString(" ") } } object outer extends MyModule { diff --git a/example/tasks/8-diy-java-modules/build.sc b/example/tasks/8-diy-java-modules/build.sc index 52c1aec037e..b019b13c167 100644 --- a/example/tasks/8-diy-java-modules/build.sc +++ b/example/tasks/8-diy-java-modules/build.sc @@ -8,26 +8,26 @@ trait DiyJavaModule extends Module{ def moduleDeps: Seq[DiyJavaModule] = Nil def mainClass: T[Option[String]] = None - def upstream: T[Seq[PathRef]] = T{ T.traverse(moduleDeps)(_.classPath)().flatten } - def sources = T.source(millSourcePath / "src") + def upstream: T[Seq[PathRef]] = Task { Task.traverse(moduleDeps)(_.classPath)().flatten } + def sources = Task.source(millSourcePath / "src") - def compile = T { + def compile = Task { val allSources = os.walk(sources().path) val cpFlag = Seq("-cp", upstream().map(_.path).mkString(":")) - os.proc("javac", cpFlag, allSources, "-d", T.dest).call() - PathRef(T.dest) + os.proc("javac", cpFlag, allSources, "-d", Task.dest).call() + PathRef(Task.dest) } - def classPath = T{ Seq(compile()) ++ upstream() } + def classPath = Task { Seq(compile()) ++ upstream() } - def assembly = T { - for(cp <- classPath()) os.copy(cp.path, T.dest, mergeFolders = true) + def assembly = Task { + for(cp <- classPath()) os.copy(cp.path, Task.dest, mergeFolders = true) val mainFlags = mainClass().toSeq.flatMap(Seq("-e", _)) - os.proc("jar", "-c", mainFlags, "-f", T.dest / s"assembly.jar", ".") - .call(cwd = T.dest) + os.proc("jar", "-c", mainFlags, "-f", Task.dest / s"assembly.jar", ".") + .call(cwd = Task.dest) - PathRef(T.dest / s"assembly.jar") + PathRef(Task.dest / s"assembly.jar") } } // This defines the following build graph for `DiyJavaModule`. Note that some of the @@ -59,11 +59,11 @@ trait DiyJavaModule extends Module{ // change the shape of the task graph during evaluation, whereas `moduleDeps` // defines module dependencies that determine the shape of the graph. // -// * Using `T.traverse` to recursively gather the upstream classpath. This is +// * Using `Task.traverse` to recursively gather the upstream classpath. This is // necessary to convert the `Seq[T[V]]` into a `T[Seq[V]]` that we can work // with inside our targets // -// * We use the `millSourcePath` together with `T.workspace` to infer a default +// * We use the `millSourcePath` together with `Task.workspace` to infer a default // name for the jar of each module. Users can override it if they want, but // having a default is very convenient // diff --git a/example/tasks/9-backticked-names/build.sc b/example/tasks/9-backticked-names/build.sc index a709371f45e..943742c5e8b 100644 --- a/example/tasks/9-backticked-names/build.sc +++ b/example/tasks/9-backticked-names/build.sc @@ -2,13 +2,13 @@ import mill._ import mill.scalalib._ object `hyphenated-module` extends Module { - def `hyphenated-target` = T{ + def `hyphenated-target` = Task { println("hyphenated target in a hyphenated module.") } } object unhyphenatedModule extends Module { - def unhyphenated_target = T{ + def unhyphenated_target = Task { println("unhyphenated target in an unhyphenated module.") } } diff --git a/example/thirdparty/acyclic/build.sc b/example/thirdparty/acyclic/build.sc index f8be2a5a021..e2d4797a064 100644 --- a/example/thirdparty/acyclic/build.sc +++ b/example/thirdparty/acyclic/build.sc @@ -31,7 +31,7 @@ trait AcyclicModule extends CrossScalaModule with PublishModule { def compileIvyDeps = Agg(Deps.scalaCompiler(crossScalaVersion)) object test extends ScalaTests with TestModule.Utest { - def sources = T.sources(millSourcePath / "src", millSourcePath / "resources") + def sources = Task.sources(millSourcePath / "src", millSourcePath / "resources") def ivyDeps = Agg(Deps.utest, Deps.scalaCompiler(crossScalaVersion)) } } diff --git a/example/thirdparty/jimfs/build.sc b/example/thirdparty/jimfs/build.sc index d8b5543532d..9f9268626b6 100644 --- a/example/thirdparty/jimfs/build.sc +++ b/example/thirdparty/jimfs/build.sc @@ -1,6 +1,6 @@ import mill._, javalib._, publish._ -def sharedCompileIvyDeps = T{ +def sharedCompileIvyDeps = Task { Agg( ivy"com.google.auto.service:auto-service:1.0.1", ivy"com.google.code.findbugs:jsr305:3.0.2", diff --git a/example/thirdparty/netty/build.sc b/example/thirdparty/netty/build.sc index cd001231ebf..5e58cb8d2f1 100644 --- a/example/thirdparty/netty/build.sc +++ b/example/thirdparty/netty/build.sc @@ -57,10 +57,10 @@ trait NettyBaseTestSuiteModule extends NettyBaseModule with TestModule.Junit5{ "-enableassertions" ) - def compile = T{ + def compile = Task { // Hack to satisfy fragile tests that look for /test-classes/ in the file paths val sup = super.compile() - val testClasses = T.dest / "test-classes" + val testClasses = Task.dest / "test-classes" if (os.exists(sup.classes.path)) os.copy(sup.classes.path, testClasses, createFolders = true) sup.copy(classes = PathRef(testClasses)) } @@ -70,7 +70,7 @@ trait NettyTestSuiteModule extends NettyBaseTestSuiteModule{ } trait NettyModule extends NettyBaseModule{ def testModuleDeps: Seq[MavenModule] = Nil - def testIvyDeps: T[Agg[mill.scalalib.Dep]] = T{ Agg() } + def testIvyDeps: T[Agg[mill.scalalib.Dep]] = Task { Agg() } object test extends NettyBaseTestSuiteModule with MavenTests{ def moduleDeps = super.moduleDeps ++ testModuleDeps @@ -85,12 +85,12 @@ trait NettyModule extends NettyBaseModule{ trait NettyJniModule extends NettyModule { def jniLibraryName: T[String] - def cSources = T.source(millSourcePath / "src" / "main" / "c") - def resources = T{ - os.copy(clang().path, T.dest / "META-INF" / "native" / jniLibraryName(), createFolders = true) - Seq(PathRef(T.dest)) + def cSources = Task.source(millSourcePath / "src" / "main" / "c") + def resources = Task { + os.copy(clang().path, Task.dest / "META-INF" / "native" / jniLibraryName(), createFolders = true) + Seq(PathRef(Task.dest)) } - def clang = T{ + def clang = Task { val Seq(sourceJar) = defaultResolver() .resolveDeps( Agg(ivy"io.netty:netty-jni-util:0.0.9.Final").map(bindDependency()), @@ -98,15 +98,15 @@ trait NettyJniModule extends NettyModule { ) .toSeq - os.makeDir.all(T.dest / "src" / "main" / "c") - os.proc("jar", "xf", sourceJar.path).call(cwd = T.dest / "src" / "main" / "c") + os.makeDir.all(Task.dest / "src" / "main" / "c") + os.proc("jar", "xf", sourceJar.path).call(cwd = Task.dest / "src" / "main" / "c") os.proc( "clang", // CFLAGS "-O3", "-Werror", "-fno-omit-frame-pointer", "-Wunused-variable", "-fvisibility=hidden", - "-I" + (T.dest / "src" / "main" / "c"), + "-I" + (Task.dest / "src" / "main" / "c"), "-I" + `transport-native-unix-common`.cHeaders().path, "-I" + sys.props("java.home") + "/include/", "-I" + sys.props("java.home") + "/include/darwin", @@ -121,9 +121,9 @@ trait NettyJniModule extends NettyModule { "-DPIC", // sources os.list(cSources().path) - ).call(cwd = T.dest, env = Map("MACOSX_DEPLOYMENT_TARGET" -> "10.9")) + ).call(cwd = Task.dest, env = Map("MACOSX_DEPLOYMENT_TARGET" -> "10.9")) - PathRef(T.dest / "a.out") + PathRef(Task.dest / "a.out") } } @@ -247,22 +247,22 @@ object common extends NettyModule{ ivy"org.jctools:jctools-core:4.0.5", ) - def script = T.source(millSourcePath / "src" / "main" / "script") - def generatedSources0 = T{ + def script = Task.source(millSourcePath / "src" / "main" / "script") + def generatedSources0 = Task { val shell = new groovy.lang.GroovyShell() val context = new java.util.HashMap[String, Object] context.put("collection.template.dir", "common/src/main/templates") context.put("collection.template.test.dir", "common/src/test/templates") - context.put("collection.src.dir", (T.dest / "src").toString) - context.put("collection.testsrc.dir", (T.dest / "testsrc").toString) + context.put("collection.src.dir", (Task.dest / "src").toString) + context.put("collection.testsrc.dir", (Task.dest / "testsrc").toString) shell.setProperty("properties", context) shell.setProperty("ant", new groovy.ant.AntBuilder()) shell.evaluate((script().path / "codegen.groovy").toIO) - (PathRef(T.dest / "src"), PathRef(T.dest / "testsrc")) + (PathRef(Task.dest / "src"), PathRef(Task.dest / "testsrc")) } - def generatedSources = T{ Seq(generatedSources0()._1)} + def generatedSources = Task { Seq(generatedSources0()._1)} } object `dev-tools` extends NettyModule{ @@ -394,26 +394,26 @@ object `testsuite-autobahn` extends NettyTestSuiteModule{ object `testsuite-http2` extends NettyTestSuiteModule{ def moduleDeps = Seq(common, buffer, transport, handler, `codec-http`, `codec-http2`) - def h2Spec = T{ + def h2Spec = Task { val isOSX = sys.props("os.name").toLowerCase.contains("mac") val binaryName = if (isOSX) "h2spec_darwin_amd64.tar.gz" else "h2spec_linux_amd64.tar.gz" val url = s"https://github.com/summerwind/h2spec/releases/download/v2.6.0/$binaryName" - os.write(T.dest / "h2spec.tar.gz", requests.get(url)) + os.write(Task.dest / "h2spec.tar.gz", requests.get(url)) - os.proc("tar", "xzf", T.dest / "h2spec.tar.gz").call(cwd = T.dest) - PathRef(T.dest / "h2spec") + os.proc("tar", "xzf", Task.dest / "h2spec.tar.gz").call(cwd = Task.dest) + PathRef(Task.dest / "h2spec") } - override def test(args: String*) = T.command{ + override def test(args: String*) = Task.command{ val server = os.proc(assembly().path).spawn(stdout = os.Inherit) try { Thread.sleep(1000) // let the server start up - os.proc(h2Spec().path, "-p9000", "--junit-report", T.dest / "report.xml") + os.proc(h2Spec().path, "-p9000", "--junit-report", Task.dest / "report.xml") .call(stdout = os.Inherit, check = false) // Use the Scala XML library to parse and fish out the data we want from the report - val xmlFile = scala.xml.XML.loadFile((T.dest / "report.xml").toIO) + val xmlFile = scala.xml.XML.loadFile((Task.dest / "report.xml").toIO) val testCasesWithErrors = (xmlFile \\ "testcase").filter { testcase => (testcase \\ "error").nonEmpty } @@ -444,7 +444,7 @@ object `testsuite-http2` extends NettyTestSuiteModule{ object `testsuite-native` extends NettyTestSuiteModule{ def moduleDeps = Seq(`transport-native-kqueue`, `resolver-dns-native-macos`, `resolver-dns-classes-macos`, `transport-native-epoll`) def testModuleDeps = Seq(`resolver-dns-classes-macos`) - override def sources = T.sources( millSourcePath / "src" / "test" / "java" ) + override def sources = Task.sources( millSourcePath / "src" / "test" / "java" ) } object `testsuite-native-image` extends NettyTestSuiteModule{ @@ -470,7 +470,7 @@ object `testsuite-osgi` extends NettyTestSuiteModule{ transport, `transport-sctp`, `transport-udt` ) - override def sources = T.sources( millSourcePath / "src" / "test" / "java" ) + override def sources = Task.sources( millSourcePath / "src" / "test" / "java" ) def ivyDeps = super.ivyDeps() ++ Agg( ivy"org.apache.felix:org.apache.felix.configadmin:1.9.14", @@ -483,7 +483,7 @@ object `testsuite-osgi` extends NettyTestSuiteModule{ object `testsuite-shading` extends NettyTestSuiteModule{ def moduleDeps = Seq(common) - override def sources = T.sources( millSourcePath / "src" / "test" / "java" ) + override def sources = Task.sources( millSourcePath / "src" / "test" / "java" ) } object transport extends NettyModule{ @@ -515,7 +515,7 @@ object `transport-native-epoll` extends NettyJniModule{ ) // Stub this out on OS-X - def clang = if (!isOSX) T{ super.clang() } else T{ PathRef(os.temp())} + def clang = if (!isOSX) Task { super.clang() } else Task { PathRef(os.temp())} } object `transport-native-kqueue` extends NettyJniModule{ @@ -524,34 +524,34 @@ object `transport-native-kqueue` extends NettyJniModule{ def testModuleDeps = Seq(testsuite, `transport-native-unix-common-tests`) // Stub this out on linux - def clang = if (isOSX) T{ super.clang() } else T{ PathRef(os.temp())} + def clang = if (isOSX) Task { super.clang() } else Task { PathRef(os.temp())} } object `transport-native-unix-common` extends NettyModule{ def moduleDeps = Seq(common, buffer, transport) def ivyDeps = Agg(ivy"org.junit.jupiter:junit-jupiter-api:5.9.0") - def makefile = T.source(millSourcePath / "Makefile") - def cSources = T.source(millSourcePath / "src" / "main" / "c") - def cHeaders = T{ + def makefile = Task.source(millSourcePath / "Makefile") + def cSources = Task.source(millSourcePath / "src" / "main" / "c") + def cHeaders = Task { for(p <- os.walk(cSources().path) if p.ext == "h"){ - os.copy(p, T.dest / p.relativeTo(cSources().path), createFolders = true) + os.copy(p, Task.dest / p.relativeTo(cSources().path), createFolders = true) } - PathRef(T.dest) + PathRef(Task.dest) } - def make = T{ + def make = Task { val Seq(sourceJar) = resolveDeps( - deps = T.task(Agg(ivy"io.netty:netty-jni-util:0.0.9.Final").map(bindDependency())), + deps = Task.anon(Agg(ivy"io.netty:netty-jni-util:0.0.9.Final").map(bindDependency())), sources = true )().toSeq - os.copy(makefile().path, T.dest / "Makefile") - os.copy(cSources().path, T.dest / "src" / "main" / "c", createFolders = true) - os.proc("jar", "xf", sourceJar.path).call(cwd = T.dest / "src" / "main" / "c") + os.copy(makefile().path, Task.dest / "Makefile") + os.copy(cSources().path, Task.dest / "src" / "main" / "c", createFolders = true) + os.proc("jar", "xf", sourceJar.path).call(cwd = Task.dest / "src" / "main" / "c") os.proc("make").call( - cwd = T.dest, + cwd = Task.dest, env = Map( "CC" -> "clang", "AR" -> "ar", @@ -577,7 +577,7 @@ object `transport-native-unix-common` extends NettyModule{ ) - (PathRef(T.dest / "lib-out"), PathRef(T.dest / "obj-out")) + (PathRef(Task.dest / "lib-out"), PathRef(Task.dest / "obj-out")) } } object `transport-native-unix-common-tests` extends NettyTestSuiteModule{ diff --git a/example/web/2-webapp-cache-busting/build.sc b/example/web/2-webapp-cache-busting/build.sc index 5f6f43ef4c0..4a8b6a40267 100644 --- a/example/web/2-webapp-cache-busting/build.sc +++ b/example/web/2-webapp-cache-busting/build.sc @@ -9,19 +9,19 @@ object root extends RootModule with ScalaModule { ivy"com.lihaoyi::os-lib:0.9.1" ) - def resources = T { + def resources = Task { val hashMapping = for { resourceRoot <- super.resources() path <- os.walk(resourceRoot.path) if os.isFile(path) - } yield hashFile(path, resourceRoot.path, T.dest) + } yield hashFile(path, resourceRoot.path, Task.dest) os.write( - T.dest / "hashed-resource-mapping.json", + Task.dest / "hashed-resource-mapping.json", upickle.default.write(hashMapping.toMap, indent = 4) ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } object test extends ScalaTests { diff --git a/example/web/4-webapp-scalajs/build.sc b/example/web/4-webapp-scalajs/build.sc index a851f3a92e8..df78ed2ac08 100644 --- a/example/web/4-webapp-scalajs/build.sc +++ b/example/web/4-webapp-scalajs/build.sc @@ -8,14 +8,14 @@ object root extends RootModule with ScalaModule { ivy"com.lihaoyi::scalatags:0.12.0" ) - def resources = T { - os.makeDir(T.dest / "webapp") + def resources = Task { + os.makeDir(Task.dest / "webapp") val jsPath = client.fastLinkJS().dest.path // Move main.js[.map]into the proper filesystem position // in the resource folder for the web server code to pick up - os.copy(jsPath / "main.js", T.dest / "webapp" / "main.js") - os.copy(jsPath / "main.js.map", T.dest / "webapp" / "main.js.map") - super.resources() ++ Seq(PathRef(T.dest)) + os.copy(jsPath / "main.js", Task.dest / "webapp" / "main.js") + os.copy(jsPath / "main.js.map", Task.dest / "webapp" / "main.js.map") + super.resources() ++ Seq(PathRef(Task.dest)) } object test extends ScalaTests { diff --git a/example/web/5-webapp-scalajs-shared/build.sc b/example/web/5-webapp-scalajs-shared/build.sc index 2052523f606..e56f8f4376b 100644 --- a/example/web/5-webapp-scalajs-shared/build.sc +++ b/example/web/5-webapp-scalajs-shared/build.sc @@ -12,12 +12,12 @@ object root extends RootModule with AppScalaModule { def moduleDeps = Seq(shared.jvm) def ivyDeps = Agg(ivy"com.lihaoyi::cask:0.9.1") - def resources = T{ - os.makeDir(T.dest / "webapp") + def resources = Task { + os.makeDir(Task.dest / "webapp") val jsPath = client.fastLinkJS().dest.path - os.copy(jsPath / "main.js", T.dest / "webapp" / "main.js") - os.copy(jsPath / "main.js.map", T.dest / "webapp" / "main.js.map") - super.resources() ++ Seq(PathRef(T.dest)) + os.copy(jsPath / "main.js", Task.dest / "webapp" / "main.js") + os.copy(jsPath / "main.js.map", Task.dest / "webapp" / "main.js.map") + super.resources() ++ Seq(PathRef(Task.dest)) } object test extends ScalaTests with TestModule.Utest { diff --git a/idea/src/mill/idea/GenIdea.scala b/idea/src/mill/idea/GenIdea.scala index f3f70d990b1..85d541ab9da 100644 --- a/idea/src/mill/idea/GenIdea.scala +++ b/idea/src/mill/idea/GenIdea.scala @@ -1,6 +1,6 @@ package mill.idea -import mill.T +import mill.{Task, T} import mill.api.Result import mill.define.{Command, Discover, ExternalModule} import mill.eval.Evaluator @@ -9,7 +9,7 @@ import scala.util.control.NonFatal object GenIdea extends ExternalModule { - def idea(allBootstrapEvaluators: Evaluator.AllBootstrapEvaluators): Command[Unit] = T.command { + def idea(allBootstrapEvaluators: Evaluator.AllBootstrapEvaluators): Command[Unit] = Task.command { try { Result.Success(GenIdeaImpl( evaluators = allBootstrapEvaluators.value @@ -21,5 +21,5 @@ object GenIdea extends ExternalModule { } } - override lazy val millDiscover: Discover[this.type] = Discover[this.type] + override val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/idea/src/mill/idea/GenIdeaImpl.scala b/idea/src/mill/idea/GenIdeaImpl.scala index 3a53387d442..06a37462056 100755 --- a/idea/src/mill/idea/GenIdeaImpl.scala +++ b/idea/src/mill/idea/GenIdeaImpl.scala @@ -15,7 +15,7 @@ import mill.scalajslib.ScalaJSModule import mill.scalalib.GenIdeaModule.{IdeaConfigFile, JavaFacet} import mill.scalalib.internal.JavaModuleUtils import mill.util.Classpath -import mill.{T, scalalib} +import mill.{T, Task, scalalib} import mill.scalalib.{GenIdeaImpl => _, _} import mill.scalanativelib.ScalaNativeModule @@ -131,65 +131,65 @@ case class GenIdeaImpl( case (path, mod) => { // same as input of resolvedIvyDeps - val allIvyDeps = T.task { + val allIvyDeps = Task.anon { mod.transitiveIvyDeps() ++ mod.transitiveCompileIvyDeps() } val scalaCompilerClasspath = mod match { case x: ScalaModule => x.scalaCompilerClasspath case _ => - T.task { + Task.anon { Agg.empty[PathRef] } } - val externalLibraryDependencies = T.task { + val externalLibraryDependencies = Task.anon { mod.defaultResolver().resolveDeps(mod.mandatoryIvyDeps()) } - val externalDependencies = T.task { + val externalDependencies = Task.anon { mod.resolvedIvyDeps() ++ - T.traverse(mod.transitiveModuleDeps)(_.unmanagedClasspath)().flatten + Task.traverse(mod.transitiveModuleDeps)(_.unmanagedClasspath)().flatten } - val extCompileIvyDeps = T.task { + val extCompileIvyDeps = Task.anon { mod.defaultResolver().resolveDeps(mod.compileIvyDeps()) } val extRunIvyDeps = mod.resolvedRunIvyDeps - val externalSources = T.task { + val externalSources = Task.anon { mod.resolveDeps(allIvyDeps, sources = true)() } val (scalacPluginsIvyDeps, allScalacOptions, scalaVersion) = mod match { case mod: ScalaModule => ( - T.task(mod.scalacPluginIvyDeps()), - T.task(mod.allScalacOptions()), - T.task { Some(mod.scalaVersion()) } + Task.anon(mod.scalacPluginIvyDeps()), + Task.anon(mod.allScalacOptions()), + Task.anon { Some(mod.scalaVersion()) } ) case _ => ( - T.task(Agg[Dep]()), - T.task(Seq[String]()), - T.task(None) + Task.anon(Agg[Dep]()), + Task.anon(Seq[String]()), + Task.anon(None) ) } - val scalacPluginDependencies = T.task { + val scalacPluginDependencies = Task.anon { mod.defaultResolver().resolveDeps(scalacPluginsIvyDeps()) } - val facets = T.task { + val facets = Task.anon { mod.ideaJavaModuleFacets(ideaConfigVersion)() } - val configFileContributions = T.task { + val configFileContributions = Task.anon { mod.ideaConfigFiles(ideaConfigVersion)() } - val compilerOutput = T.task { + val compilerOutput = Task.anon { mod.ideaCompileOutput() } - T.task { + Task.anon { val resolvedCp: Agg[Scoped[os.Path]] = externalDependencies().map(_.path).map(Scoped(_, None)) ++ extCompileIvyDeps() diff --git a/integration/failure/module-init-error/repo/build.sc b/integration/failure/module-init-error/repo/build.sc index 3ed72aceb2a..1bffd9ecf6e 100644 --- a/integration/failure/module-init-error/repo/build.sc +++ b/integration/failure/module-init-error/repo/build.sc @@ -1,21 +1,21 @@ import mill._, scalalib._ -def rootTarget = T{ println("Running rootTarget"); "rootTarget" } -def rootCommand(s: String) = T.command{ println(s"Running rootCommand $s") } +def rootTarget = Task { println("Running rootTarget"); "rootTarget" } +def rootCommand(s: String) = Task.command{ println(s"Running rootCommand $s") } object foo extends Module{ - def fooTarget = T{ println(s"Running fooTarget"); 123 } - def fooCommand(s: String) = T.command{ println(s"Running fooCommand $s") } + def fooTarget = Task { println(s"Running fooTarget"); 123 } + def fooCommand(s: String) = Task.command{ println(s"Running fooCommand $s") } throw new Exception("Foo Boom") } object bar extends Module { - def barTarget = T { println(s"Running barTarget"); "abc" } - def barCommand(s: String) = T.command{ println(s"Running barCommand $s") } + def barTarget = Task { println(s"Running barTarget"); "abc" } + def barCommand(s: String) = Task.command{ println(s"Running barCommand $s") } object qux extends Module{ - def quxTarget = T { println(s"Running quxTarget"); "xyz" } - def quxCommand(s: String) = T.command{ println(s"Running quxCommand $s") } + def quxTarget = Task { println(s"Running quxTarget"); "xyz" } + def quxCommand(s: String) = Task.command{ println(s"Running quxCommand $s") } throw new Exception("Qux Boom") } } diff --git a/integration/failure/things-outside-top-level-module/repo/build.sc b/integration/failure/things-outside-top-level-module/repo/build.sc index 9f91a3b0fc4..d74662f8f47 100644 --- a/integration/failure/things-outside-top-level-module/repo/build.sc +++ b/integration/failure/things-outside-top-level-module/repo/build.sc @@ -1,6 +1,6 @@ import mill._ -def invalidTarget = T{ "..." } +def invalidTarget = Task { "..." } object invalidModule extends Module diff --git a/integration/feature/docannotations/repo/build.sc b/integration/feature/docannotations/repo/build.sc index cbe16e5a5fe..522e67e464b 100644 --- a/integration/feature/docannotations/repo/build.sc +++ b/integration/feature/docannotations/repo/build.sc @@ -7,7 +7,7 @@ trait JUnitTests extends TestModule.Junit4 { * Overridden ivyDeps Docs!!! */ def ivyDeps = Agg(ivy"com.novocode:junit-interface:0.11") - def task = T { + def task = Task { "???" } } @@ -21,7 +21,7 @@ object core extends JavaModule { /** * Core Target Docz! */ - def target = T { + def target = Task { import collection.JavaConverters._ println(this.getClass.getClassLoader.getResources("scalac-plugin.xml").asScala.toList) "Hello!" diff --git a/integration/feature/hygiene/repo/build.sc b/integration/feature/hygiene/repo/build.sc index 8b5b127e198..968307b8de9 100644 --- a/integration/feature/hygiene/repo/build.sc +++ b/integration/feature/hygiene/repo/build.sc @@ -1,7 +1,7 @@ import _root_.mill._, scalalib._, publish._ object scala extends Module { - def foo = T { + def foo = Task { "fooValue" } } diff --git a/integration/feature/mill-jvm-opts/repo/build.sc b/integration/feature/mill-jvm-opts/repo/build.sc index 6de43ccb014..a095407f51f 100644 --- a/integration/feature/mill-jvm-opts/repo/build.sc +++ b/integration/feature/mill-jvm-opts/repo/build.sc @@ -2,7 +2,7 @@ import mill._ import java.lang.management.ManagementFactory import scala.jdk.CollectionConverters._ -def checkJvmOpts() = T.command { +def checkJvmOpts() = Task.command { val prop = System.getProperty("PROPERTY_PROPERLY_SET_VIA_JVM_OPTS") if (prop != "value-from-file") sys.error("jvm-opts not correctly applied, value was: " + prop) val runtime = ManagementFactory.getRuntimeMXBean() diff --git a/integration/feature/private-methods/repo/build.sc b/integration/feature/private-methods/repo/build.sc index 62bf2f18791..84502e922f3 100644 --- a/integration/feature/private-methods/repo/build.sc +++ b/integration/feature/private-methods/repo/build.sc @@ -1,30 +1,30 @@ import mill._ -def pub = T { +def pub = Task { priv() } -private def priv = T { +private def priv = Task { "priv" } object foo extends Module { - def bar = T { + def bar = Task { baz() } } -private def baz = T { +private def baz = Task { "bazOuter" } object qux extends Module { object foo extends Module { - def bar = T { + def bar = Task { baz() } } - private def baz = T { + private def baz = Task { "bazInner" } } @@ -32,12 +32,12 @@ object qux extends Module { object cls extends cls class cls extends Module { object foo extends Module { - def bar = T { + def bar = Task { baz() } } - private def baz = T { + private def baz = Task { "bazCls" } } diff --git a/integration/feature/subprocess-stdout/repo/build.sc b/integration/feature/subprocess-stdout/repo/build.sc index 48302802042..f16d9af5c3c 100644 --- a/integration/feature/subprocess-stdout/repo/build.sc +++ b/integration/feature/subprocess-stdout/repo/build.sc @@ -2,7 +2,7 @@ import scala.util.Properties import mill._ -def inheritInterleaved = T { +def inheritInterleaved = Task { for (i <- Range.inclusive(1, 9)) { println("print stdout" + i) val echoCommandStdout = @@ -17,7 +17,7 @@ def inheritInterleaved = T { } } -def inheritRaw = T{ +def inheritRaw = Task { println("print stdoutRaw") val echoCommandStdoutRaw = if (Properties.isWin) Seq("cmd.exe", "/C", "echo proc stdoutRaw") diff --git a/integration/ide/bsp-install/repo/build.sc b/integration/ide/bsp-install/repo/build.sc index 93d59bbe0e3..f05d286a787 100644 --- a/integration/ide/bsp-install/repo/build.sc +++ b/integration/ide/bsp-install/repo/build.sc @@ -6,8 +6,8 @@ trait HelloBspModule extends ScalaModule { def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) object test extends ScalaTests with TestModule.Utest - override def generatedSources = T { - Seq(PathRef(T.ctx().dest / "classes")) + override def generatedSources = Task { + Seq(PathRef(Task.ctx().dest / "classes")) } } diff --git a/integration/ide/bsp-modules/repo/build.sc b/integration/ide/bsp-modules/repo/build.sc index 2b84fa8fd3b..ae441bacdd1 100644 --- a/integration/ide/bsp-modules/repo/build.sc +++ b/integration/ide/bsp-modules/repo/build.sc @@ -13,14 +13,14 @@ object HelloBsp extends HelloBspModule { // Explicitly depends on proj2 def compileModuleDeps: Seq[JavaModule] = Seq(build.proj2.module) // Implicitly depends on proj3 via a target - override def unmanagedClasspath: T[Agg[PathRef]] = T { + override def unmanagedClasspath: T[Agg[PathRef]] = Task { Agg(build.proj3.module.jar()) } } -def validate() = T.command { +def validate() = Task.command { val transitiveModules = mill.scalalib.internal.JavaModuleUtils.transitiveModules(build.`package`) - val file = T.dest / "transitive-modules.json" + val file = Task.dest / "transitive-modules.json" val moduleNames = transitiveModules.map(m => mill.scalalib.internal.ModuleUtils.moduleDisplayName(m) ).mkString("\n") diff --git a/integration/ide/gen-idea/repo/extended/build.sc b/integration/ide/gen-idea/repo/extended/build.sc index 1f1e6cd14ae..3d0aa2f2d1c 100644 --- a/integration/ide/gen-idea/repo/extended/build.sc +++ b/integration/ide/gen-idea/repo/extended/build.sc @@ -9,8 +9,8 @@ trait HelloWorldModule extends scalalib.ScalaModule { override def scalaVersion = "2.13.6" object test extends ScalaTests with TestModule.Utest - override def generatedSources = T { - Seq(PathRef(T.dest / "classes")) + override def generatedSources = Task { + Seq(PathRef(Task.dest / "classes")) } object subScala3 extends scalalib.ScalaModule { @@ -18,7 +18,7 @@ trait HelloWorldModule extends scalalib.ScalaModule { } def ideaJavaModuleFacets(ideaConfigVersion: Int): Task[Seq[JavaFacet]] = - T.task { + Task.anon { ideaConfigVersion match { case 4 => Seq( @@ -46,7 +46,7 @@ trait HelloWorldModule extends scalalib.ScalaModule { override def ideaConfigFiles( ideaConfigVersion: Int - ): Task[Seq[IdeaConfigFile]] = T.task { + ): Task[Seq[IdeaConfigFile]] = Task.anon { ideaConfigVersion match { case 4 => Seq( diff --git a/integration/ide/gen-idea/repo/hello-idea/build.sc b/integration/ide/gen-idea/repo/hello-idea/build.sc index 626a2280c27..ee4cc471ec8 100644 --- a/integration/ide/gen-idea/repo/hello-idea/build.sc +++ b/integration/ide/gen-idea/repo/hello-idea/build.sc @@ -7,14 +7,14 @@ import mill.scalalib.{Dep, DepSyntax, JavaModule, TestModule} trait HelloIdeaModule extends scalalib.ScalaModule { def scalaVersion = "2.12.5" object test extends ScalaTests with TestModule.Utest { - override def compileIvyDeps: Target[Agg[Dep]] = Agg( + override def compileIvyDeps: Task[Agg[Dep]] = Agg( ivy"org.slf4j:jcl-over-slf4j:1.7.25" ) - override def ivyDeps: Target[Agg[Dep]] = Agg( + override def ivyDeps: Task[Agg[Dep]] = Agg( ivy"org.slf4j:slf4j-api:1.7.25", ivy"ch.qos.logback:logback-core:1.2.3" ) - override def runIvyDeps: Target[Agg[Dep]] = Agg( + override def runIvyDeps: Task[Agg[Dep]] = Agg( ivy"ch.qos.logback:logback-core:1.2.3", ivy"ch.qos.logback:logback-classic:1.2.3" ) @@ -35,7 +35,7 @@ object HelloIdeaJs extends ScalaJSModule { override def scalaVersion = "3.3.1" override def scalaJSVersion = "1.16.0" object test extends ScalaJSTests with TestModule.Utest { - override def ivyDeps: Target[Agg[Dep]] = Agg( + override def ivyDeps: Task[Agg[Dep]] = Agg( ivy"com.lihaoyi::utest::0.8.4" ) } diff --git a/integration/invalidation/codesig-hello/repo/build.sc b/integration/invalidation/codesig-hello/repo/build.sc index bcb6705bced..d1fe9b8d274 100644 --- a/integration/invalidation/codesig-hello/repo/build.sc +++ b/integration/invalidation/codesig-hello/repo/build.sc @@ -3,4 +3,4 @@ import mill._ val valueFoo = 0 val valueFooUsedInBar = 0 def helperFoo = { println("running helperFoo"); 1 + valueFoo } -def foo = T{ println("running foo"); helperFoo } +def foo = Task { println("running foo"); helperFoo } diff --git a/integration/invalidation/codesig-nested/repo/build.sc b/integration/invalidation/codesig-nested/repo/build.sc index 9c47880706b..fb99483d4d4 100644 --- a/integration/invalidation/codesig-nested/repo/build.sc +++ b/integration/invalidation/codesig-nested/repo/build.sc @@ -3,18 +3,18 @@ import mill._ val valueFoo = 0 val valueFooUsedInBar = 0 def helperFoo = { println("running helperFoo"); 1 + valueFoo } -def foo = T{ println("running foo"); helperFoo } +def foo = Task { println("running foo"); helperFoo } object outer extends Module{ val valueBar = 0 val valueBarUsedInQux = 0 def helperBar = { println("running helperBar"); 20 } - def bar = T{ println("running bar"); helperBar + valueBar + valueFooUsedInBar } + def bar = Task { println("running bar"); helperBar + valueBar + valueFooUsedInBar } trait InnerModule extends Module{ val valueQux = 0 def helperQux = { println("running helperQux"); 300 + valueQux + valueBarUsedInQux } - def qux = T{ println("running qux"); foo() + bar() + helperQux } + def qux = Task { println("running qux"); foo() + bar() + helperQux } } object inner extends InnerModule } @@ -22,12 +22,12 @@ object outer extends Module{ trait TraitOuter extends Module{ val valueTraitOuter = 0 def helperTraitOuter = { println("running helperTraitOuter"); 300 + valueTraitOuter } - def outer = T{ println("running outer"); foo() + helperTraitOuter } + def outer = Task { println("running outer"); foo() + helperTraitOuter } object traitInner extends Module{ val valueTraitInner = 0 def helperTraitInner = { println("running helperTraitInner"); 300 + valueTraitOuter + valueTraitInner } - def inner = T{ println("running inner"); foo() + outer() + helperTraitInner } + def inner = Task { println("running inner"); foo() + outer() + helperTraitInner } } } diff --git a/integration/invalidation/codesig-nested/test/src/CodeSigNestedTests.scala b/integration/invalidation/codesig-nested/test/src/CodeSigNestedTests.scala index a80371267f6..a0c1b2c6d44 100644 --- a/integration/invalidation/codesig-nested/test/src/CodeSigNestedTests.scala +++ b/integration/invalidation/codesig-nested/test/src/CodeSigNestedTests.scala @@ -27,7 +27,7 @@ object CodeSigNestedTests extends IntegrationTestSuite { val cached = evalStdout("outer.inner.qux") assert(cached.out == "") - // Changing the body of a T{...} block directly invalidates that target, + // Changing the body of a Task {...} block directly invalidates that target, // but not downstream targets unless the return value changes mangleFile(wsRoot / "build.sc", _.replace("running foo", "running foo2")) val mangledFoo = evalStdout("outer.inner.qux") @@ -59,7 +59,7 @@ object CodeSigNestedTests extends IntegrationTestSuite { Set("running qux2", "running helperQux") ) - // Changing the body of some helper method that gets called by a T{...} + // Changing the body of some helper method that gets called by a Task {...} // block also invalidates the respective targets, and downstream targets if necessary mangleFile(wsRoot / "build.sc", _.replace(" 1 ", " 6 ")) diff --git a/integration/invalidation/codesig-scalamodule/repo/build.sc b/integration/invalidation/codesig-scalamodule/repo/build.sc index 304c4591eba..31b0bd13e2e 100644 --- a/integration/invalidation/codesig-scalamodule/repo/build.sc +++ b/integration/invalidation/codesig-scalamodule/repo/build.sc @@ -3,10 +3,10 @@ import mill._, scalalib._ object foo extends ScalaModule { def scalaVersion = "2.13.8" - def sources = T{ + def sources = Task { println("Foo generating sources...") os.write( - T.dest / "Foo.scala", + Task.dest / "Foo.scala", """package foo |object Foo { | final val fooMsg = "Hello World" @@ -16,20 +16,20 @@ object foo extends ScalaModule { | } |}""".stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } - def compile = T { + def compile = Task { println("Foo compiling...") super.compile() } - def run(args: Task[Args] = T.task(Args())) = T.command { + def run(args: Task[Args] = Task.anon(Args())) = Task.command { println("Foo running..." + args().value.mkString(" ")) super.run(args)() } - def assembly = T { + def assembly = Task { println("Foo assembly...") super.assembly() } @@ -39,10 +39,10 @@ object bar extends ScalaModule { def moduleDeps = Seq(foo) def scalaVersion = "2.13.8" - def sources = T { + def sources = Task { println("Bar generating sources...") os.write( - T.dest / "Bar.scala", + Task.dest / "Bar.scala", """package bar |object Bar { | def main(args: Array[String]): Unit = { @@ -50,15 +50,15 @@ object bar extends ScalaModule { | } |}""".stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } - def compile = T { + def compile = Task { println("Bar compiling...") super.compile() } - def assembly = T { + def assembly = Task { println("Bar assembly...") super.assembly() } @@ -67,10 +67,10 @@ object bar extends ScalaModule { object qux extends ScalaModule { def scalaVersion = "2.13.8" - def sources = T { + def sources = Task { println("Qux generating sources...") os.write( - T.dest / "Qux.scala", + Task.dest / "Qux.scala", """package qux |object Qux { | def main(args: Array[String]): Unit = { @@ -78,15 +78,15 @@ object qux extends ScalaModule { | } |}""".stripMargin ) - Seq(PathRef(T.dest)) + Seq(PathRef(Task.dest)) } - def compile = T { + def compile = Task { println("Qux compiling...") super.compile() } - def assembly = T { + def assembly = Task { println("Qux assembly...") super.assembly() } diff --git a/integration/invalidation/codesig-scalamodule/test/src/CodeSigScalaModuleTests.scala b/integration/invalidation/codesig-scalamodule/test/src/CodeSigScalaModuleTests.scala index ad19e563aab..c39df3df0f9 100644 --- a/integration/invalidation/codesig-scalamodule/test/src/CodeSigScalaModuleTests.scala +++ b/integration/invalidation/codesig-scalamodule/test/src/CodeSigScalaModuleTests.scala @@ -34,7 +34,7 @@ object CodeSigScalaModuleTests extends IntegrationTestSuite { ) ) - // Changing the body of a T{...} block directly invalidates that target + // Changing the body of a Task {...} block directly invalidates that target // and any downstream targets mangleFile(wsRoot / "build.sc", _.replace("Foo running...", "FOO RUNNING")) val mangledFoo = evalStdout("foo.run") diff --git a/integration/invalidation/invalidation/repo/-#+&%/module.sc b/integration/invalidation/invalidation/repo/-#+&%/module.sc index 7067e644657..9e55c7f63fe 100644 --- a/integration/invalidation/invalidation/repo/-#+&%/module.sc +++ b/integration/invalidation/invalidation/repo/-#+&%/module.sc @@ -1,5 +1,5 @@ import mill._ object module extends Module { - def input = T {} + def input = Task {} } diff --git a/integration/invalidation/invalidation/repo/a/module.sc b/integration/invalidation/invalidation/repo/a/module.sc index 8242efcbad6..f71b76316a7 100644 --- a/integration/invalidation/invalidation/repo/a/module.sc +++ b/integration/invalidation/invalidation/repo/a/module.sc @@ -1,5 +1,5 @@ import mill._ -def input = T { +def input = Task { println("a") } diff --git a/integration/invalidation/invalidation/repo/b/module.sc b/integration/invalidation/invalidation/repo/b/module.sc index 891f40b39ff..8bd1fae959a 100644 --- a/integration/invalidation/invalidation/repo/b/module.sc +++ b/integration/invalidation/invalidation/repo/b/module.sc @@ -1,7 +1,7 @@ import mill._ import $file.inputD -def input = T { +def input = Task { inputD.method() println("b") } diff --git a/integration/invalidation/invalidation/repo/build.sc b/integration/invalidation/invalidation/repo/build.sc index 742a95e3d45..b1e6b8eb00b 100644 --- a/integration/invalidation/invalidation/repo/build.sc +++ b/integration/invalidation/invalidation/repo/build.sc @@ -2,14 +2,14 @@ import mill._ import $ivy.`org.scalaj::scalaj-http:2.4.2` -def task = T { +def task = Task { build.a.input() build.b.input() build.c.input() } object module extends Module { - def task = T { + def task = Task { println("task") build.a.input() build.b.input() @@ -17,17 +17,17 @@ object module extends Module { } } -def taskE = T { +def taskE = Task { println("taskE") build.e.input() } -def taskSymbols = T { +def taskSymbols = Task { println("taskSymbols") build.`-#!+→&%=~`.input() } -def taskSymbolsInFile = T { +def taskSymbolsInFile = Task { println("taskSymbolsInFile") build.`-#+&%`.module.input() } diff --git a/integration/invalidation/invalidation/repo/c/module.sc b/integration/invalidation/invalidation/repo/c/module.sc index c543be39058..732167e35b4 100644 --- a/integration/invalidation/invalidation/repo/c/module.sc +++ b/integration/invalidation/invalidation/repo/c/module.sc @@ -1,5 +1,5 @@ import mill._ -def input = T { +def input = Task { println("c") } diff --git a/integration/invalidation/invalidation/repo/e/module.sc b/integration/invalidation/invalidation/repo/e/module.sc index 9cbd474eb57..3224117b132 100644 --- a/integration/invalidation/invalidation/repo/e/module.sc +++ b/integration/invalidation/invalidation/repo/e/module.sc @@ -1,6 +1,6 @@ import mill._ -def input = T { +def input = Task { println("e") build.a.input() } diff --git a/integration/invalidation/multi-level-editing/repo/mill-build/build.sc b/integration/invalidation/multi-level-editing/repo/mill-build/build.sc index 008a0091067..8596fc39ebe 100644 --- a/integration/invalidation/multi-level-editing/repo/mill-build/build.sc +++ b/integration/invalidation/multi-level-editing/repo/mill-build/build.sc @@ -4,15 +4,15 @@ import mill._, scalalib._ object millbuild extends MillBuildRootModule{ def ivyDeps = Agg(ivy"com.lihaoyi::scalatags:${constant.MetaConstant.scalatagsVersion}") - def generatedSources = T { + def generatedSources = Task { os.write( - T.dest / "Constant.scala", + Task.dest / "Constant.scala", s"""package constant |object Constant{ | def scalatagsVersion = "${constant.MetaConstant.scalatagsVersion}" |} |""".stripMargin ) - super.generatedSources() ++ Seq(PathRef(T.dest / "Constant.scala")) + super.generatedSources() ++ Seq(PathRef(Task.dest / "Constant.scala")) } } \ No newline at end of file diff --git a/integration/invalidation/multi-level-editing/repo/mill-build/mill-build/build.sc b/integration/invalidation/multi-level-editing/repo/mill-build/mill-build/build.sc index db8d00ce722..5cda6a49015 100644 --- a/integration/invalidation/multi-level-editing/repo/mill-build/mill-build/build.sc +++ b/integration/invalidation/multi-level-editing/repo/mill-build/mill-build/build.sc @@ -2,15 +2,15 @@ import mill._, scalalib._ object millbuild extends MillBuildRootModule { - def generatedSources = T{ + def generatedSources = Task { os.write( - T.dest / "MetaConstant.scala", + Task.dest / "MetaConstant.scala", """package constant |object MetaConstant{ | def scalatagsVersion = "0.8.2" |} |""".stripMargin ) - super.generatedSources() ++ Seq(PathRef(T.dest / "MetaConstant.scala")) + super.generatedSources() ++ Seq(PathRef(Task.dest / "MetaConstant.scala")) } } diff --git a/integration/invalidation/multi-level-editing/test/src/MultiLevelBuildTests.scala b/integration/invalidation/multi-level-editing/test/src/MultiLevelBuildTests.scala index a5dd3a1f40f..0d31a742f7b 100644 --- a/integration/invalidation/multi-level-editing/test/src/MultiLevelBuildTests.scala +++ b/integration/invalidation/multi-level-editing/test/src/MultiLevelBuildTests.scala @@ -312,7 +312,7 @@ object MultiLevelBuildTests extends IntegrationTestSuite { test("runtimeErrorEdits") { val runErrorSnippet = """{ - |override def runClasspath = T{ + |override def runClasspath = Task { | throw new Exception("boom") | super.runClasspath() |}""".stripMargin diff --git a/integration/invalidation/watch-source-input/repo/build.sc b/integration/invalidation/watch-source-input/repo/build.sc index 70bf339d6c2..97b948731e1 100644 --- a/integration/invalidation/watch-source-input/repo/build.sc +++ b/integration/invalidation/watch-source-input/repo/build.sc @@ -2,10 +2,10 @@ import mill._ println("Setting up build.sc") -def foo = T.sources(millSourcePath / "foo1.txt", millSourcePath / "foo2.txt") -def bar = T.source(millSourcePath / "bar.txt") +def foo = Task.sources(millSourcePath / "foo1.txt", millSourcePath / "foo2.txt") +def bar = Task.source(millSourcePath / "bar.txt") -def qux = T{ +def qux = Task { val fooMsg = "Running qux foo contents " + foo().map(p => os.read(p.path)).mkString(" ") println(fooMsg) @@ -19,9 +19,9 @@ def qux = T{ interp.watchValue(PathRef(millSourcePath / "watchValue.txt")) -def baz = T.input(PathRef(millSourcePath / "baz.txt")) +def baz = Task.input(PathRef(millSourcePath / "baz.txt")) -def lol = T{ +def lol = Task { val barMsg = "Running lol baz contents " + os.read(baz().path) println(barMsg) diff --git a/integration/invalidation/watch-source-input/test/src/WatchSourceInputTests.scala b/integration/invalidation/watch-source-input/test/src/WatchSourceInputTests.scala index 3c98b127a00..ab6ffd24607 100644 --- a/integration/invalidation/watch-source-input/test/src/WatchSourceInputTests.scala +++ b/integration/invalidation/watch-source-input/test/src/WatchSourceInputTests.scala @@ -12,9 +12,9 @@ import scala.concurrent.ExecutionContext.Implicits.global /** * Test to make sure that `--watch` works in the following cases: * - * 1. `T.source` - * 2. `T.sources` - * 3. `T.input` + * 1. `Task.source` + * 2. `Task.sources` + * 3. `Task.input` * 4. `interp.watchValue` * 5. Implicitly watched files, like `build.sc` */ diff --git a/main/api/src/mill/api/Ctx.scala b/main/api/src/mill/api/Ctx.scala index 6ba07731d9f..92239e1759b 100644 --- a/main/api/src/mill/api/Ctx.scala +++ b/main/api/src/mill/api/Ctx.scala @@ -7,7 +7,9 @@ import scala.language.implicitConversions * Provides access to various resources in the context of a currently execution Target. */ object Ctx { - @compileTimeOnly("Target.ctx() / T.ctx() / T.* APIs can only be used with a T{...} block") + @compileTimeOnly( + "Target.ctx() / Task.ctx() / Task.* APIs can only be used with a Task {...} block" + ) @ImplicitStub implicit def taskCtx: Ctx = ??? @@ -17,7 +19,7 @@ object Ctx { trait Dest { /** - * `T.dest` is a unique `os.Path` (e.g. `out/classFiles.dest/` or `out/run.dest/`) + * `Task.dest` is a unique `os.Path` (e.g. `out/classFiles.dest/` or `out/run.dest/`) * that is assigned to every Target or Command. It is cleared before your * task runs, and you can use it as a scratch space for temporary files or * a place to put returned artifacts. This is guaranteed to be unique for @@ -34,7 +36,7 @@ object Ctx { trait Log { /** - * `T.log` is the default logger provided for every task. While your task is running, + * `Task.log` is the default logger provided for every Task. While your task is running, * `System.out` and `System.in` are also redirected to this logger. The logs for a * task are streamed to standard out/error as you would expect, but each task's * specific output is also streamed to a log file on disk, e.g. `out/run.log` or @@ -62,8 +64,8 @@ object Ctx { trait Env { /** - * `T.env` is the environment variable map passed to the Mill command when - * it is run; typically used inside a `T.input` to ensure any changes in + * `Task.env` is the environment variable map passed to the Mill command when + * it is run; typically used inside a `Task.input` to ensure any changes in * the env vars are properly detected. * * Note that you should not use `sys.env`, as Mill's long-lived server diff --git a/main/api/src/mill/api/Result.scala b/main/api/src/mill/api/Result.scala index cbe27b004d8..ef489b14ff0 100644 --- a/main/api/src/mill/api/Result.scala +++ b/main/api/src/mill/api/Result.scala @@ -5,7 +5,7 @@ import scala.language.implicitConversions /** * The result of a task execution. * - * @tparam T The result type of the computed task. + * @tparam T The result type of the computed Task. */ sealed trait Result[+T] { def map[V](f: T => V): Result[V] @@ -29,8 +29,8 @@ object Result { /** * A successful task execution. - * @param value The value computed by the task. - * @tparam T The result type of the computed task. + * @param value The value computed by the Task. + * @tparam T The result type of the computed Task. */ case class Success[+T](value: T) extends Result[T] { def map[V](f: T => V): Success[V] = Result.Success(f(value)) @@ -56,7 +56,7 @@ object Result { /** * A failed task execution. - * @tparam T The result type of the computed task. + * @tparam T The result type of the computed Task. */ sealed trait Failing[+T] extends java.lang.Exception with Result[T] { def map[V](f: T => V): Failing[V] @@ -69,7 +69,7 @@ object Result { * An intensional failure, which provides a proper error message as well as an optional result value. * @param msg The error message. * @param value The optional result value. - * @tparam T The result type of the computed task. + * @tparam T The result type of the computed Task. */ case class Failure[T](msg: String, value: Option[T] = None) extends Failing[T] { def map[V](f: T => V): Failure[V] = Result.Failure(msg, value.map(f(_))) @@ -80,7 +80,7 @@ object Result { /** * An (mostly) unintentionally failed task which the exception that caused the failure. * @param throwable The exception that describes or caused the failure. - * @param outerStack The [[OuterStack]] of the failed task. + * @param outerStack The [[OuterStack]] of the failed Task. */ case class Exception(throwable: Throwable, outerStack: OuterStack) extends Failing[Nothing] { def map[V](f: Nothing => V): Exception = this diff --git a/main/define/src/mill/define/Applicative.scala b/main/define/src/mill/define/Applicative.scala index 7c88ebef9cc..c9ce2b36621 100644 --- a/main/define/src/mill/define/Applicative.scala +++ b/main/define/src/mill/define/Applicative.scala @@ -24,7 +24,7 @@ object Applicative { def apply[T](t: M[T]): T } object ApplyHandler { - @compileTimeOnly("Target#apply() can only be used with a T{...} block") + @compileTimeOnly("Target#apply() can only be used with a Task {...} block") implicit def defaultApplyHandler[M[+_]]: ApplyHandler[M] = ??? } trait Applyable[M[+_], +T] { @@ -70,7 +70,7 @@ object Applicative { val banned0 = banned.next() c.abort( banned0.pos, - "Target#apply() call cannot use `" + banned0.symbol + "` defined within the T{...} block" + "Target#apply() call cannot use `" + banned0.symbol + "` defined within the Task {...} block" ) } val tempName = c.freshName(TermName("tmp")) diff --git a/main/define/src/mill/define/BaseModuleTree.scala b/main/define/src/mill/define/BaseModuleTree.scala index 802fd0575a4..062e3bc4146 100644 --- a/main/define/src/mill/define/BaseModuleTree.scala +++ b/main/define/src/mill/define/BaseModuleTree.scala @@ -20,9 +20,25 @@ class BaseModuleTree(value: Seq[(Seq[String], BaseModule)]) { lookupByParent0.getOrElse(parentPrefixOpt, Nil) def rootModule: BaseModule = lookupByParent(None).head._2 - val allPossibleNames: Set[String] = - value.flatMap(_._2.millDiscover.value.values).flatMap(_._1).toSet + val allPossibleNames: Set[String] = { + + value + .flatMap(_._2.millDiscover.value.values) + .flatMap { t => t._1 ++ t._2.map(_.defaultName) } + .toSet + } + + val targetNamesByClass: Map[Class[_], Set[String]] = value + .flatMap { case (segs, base) => base.millDiscover.value.mapValues(_._1.toSet) } + .toMap + + val commandNamesByClass: Map[Class[_], Set[String]] = value + .flatMap { case (segs, base) => + base.millDiscover.value.mapValues(_._2.toSet.map[String](_.defaultName)) + } + .toMap } + object BaseModuleTree { def from(rootModules: Seq[BaseModule]): BaseModuleTree = { new BaseModuleTree( diff --git a/main/define/src/mill/define/Discover.scala b/main/define/src/mill/define/Discover.scala index 6dcca7e8f67..a41f3ba1162 100644 --- a/main/define/src/mill/define/Discover.scala +++ b/main/define/src/mill/define/Discover.scala @@ -6,14 +6,14 @@ import scala.reflect.macros.blackbox /** * Macro to walk the module tree and generate `mainargs` entrypoints for any - * `T.command` methods that it finds. + * `Task.command` methods that it finds. * * Note that unlike the rest of Mill's module-handling logic which uses Java * reflection, generation of entrypoints requires typeclass resolution, and so * needs to be done at compile time. Thus we walk the entire module tree, * collecting all the module `Class[_]`s we can find, and for each one generate * the `mainargs.MainData` containing metadata and resolved typeclasses for all - * the `T.command` methods we find. This mapping from `Class[_]` to `MainData` + * the `Task.command` methods we find. This mapping from `Class[_]` to `MainData` * can then be used later to look up the `MainData` for any module. */ case class Discover[T] private ( @@ -105,21 +105,45 @@ object Discover { val mapping = for { discoveredModuleType <- seen.toSeq.sortBy(_.typeSymbol.fullName) curCls = discoveredModuleType - methods = getValsOrMeths(curCls) + methods = { + // Inlined from mainargs.Macros.getValsOrMeths, to allow us to pick up `val`s + // to support Mill's test suite + def isAMemberOfAnyRef(member: Symbol) = { + // AnyRef is an alias symbol, we go to the real "owner" of these methods + val anyRefSym = c.mirror.universe.definitions.ObjectClass + member.owner == anyRefSym + } + val extractableMembers = for { + member <- curCls.members.toList.reverse + if !isAMemberOfAnyRef(member) + if !member.isSynthetic + if member.isPublic + if member.isTerm + memTerm = member.asTerm + // if memTerm.isMethod + if !memTerm.isModule + } yield { + memTerm.asMethod + } + + extractableMembers flatMap { case memTerm => + if (memTerm.isSetter || memTerm.isConstructor) Nil + else Seq(memTerm) + } + } overridesRoutes = { assertParamListCounts( methods, - (weakTypeOf[mill.define.Command[_]], 1, "`T.command`"), - (weakTypeOf[mill.define.Target[_]], 0, "Target") + (weakTypeOf[mill.define.Command[_]], 1, "`Task.command`") ) Tuple2( for { - m <- methods.toList.sortBy(_.fullName) - if m.returnType <:< weakTypeOf[mill.define.NamedTask[_]] + m <- methods.sortBy(_.fullName) + if (m.returnType <:< weakTypeOf[mill.define.Task[_]] && m.paramLists.isEmpty) } yield m.name.decoded, for { - m <- methods.toList.sortBy(_.fullName) + m <- methods.sortBy(_.fullName) if m.returnType <:< weakTypeOf[mill.define.Command[_]] } yield extractMethod( m.name, diff --git a/main/define/src/mill/define/Module.scala b/main/define/src/mill/define/Module.scala index 66fd1539804..4f78019ce29 100644 --- a/main/define/src/mill/define/Module.scala +++ b/main/define/src/mill/define/Module.scala @@ -71,7 +71,7 @@ object Module { modules.map(m => (m.millModuleSegments, m)).toMap lazy val targets: Set[Target[_]] = - traverse { _.millInternal.reflectAll[Target[_]].toIndexedSeq }.toSet + traverse(_.millInternal.reflectAll[Task[_]].toIndexedSeq.flatMap(_.asTarget)).toSet def reflect[T: ClassTag](filter: String => Boolean): Seq[T] = { Reflect.reflect( diff --git a/main/define/src/mill/define/Task.scala b/main/define/src/mill/define/Task.scala index c8c41d746e8..f149cd5103f 100644 --- a/main/define/src/mill/define/Task.scala +++ b/main/define/src/mill/define/Task.scala @@ -14,7 +14,7 @@ import scala.reflect.macros.blackbox.Context * Generally not instantiated manually, but instead constructed via the * [[Target.apply]] & similar macros. */ -abstract class Task[+T] extends Task.Ops[T] with Applyable[Task, T] { +trait Task[+T] extends Task.Ops[T] with Applyable[Task, T] { /** * What other tasks does this task depend on? @@ -33,7 +33,7 @@ abstract class Task[+T] extends Task.Ops[T] with Applyable[Task, T] { def sideHash: Int = 0 /** - * Whether or not this [[Task]] deletes the `T.dest` folder between runs + * Whether or not this [[Task]] deletes the `Task.dest` folder between runs */ def flushDest: Boolean = true @@ -41,9 +41,16 @@ abstract class Task[+T] extends Task.Ops[T] with Applyable[Task, T] { def asCommand: Option[Command[T]] = None def asWorker: Option[Worker[T]] = None def self: Task[T] = this + def ctx: Ctx = throw new UnsupportedOperationException("Cannot get the ctx of an anonymous task") } -object Task { +object Task extends TaskCompanion { + implicit def applyImplicit2[T](t: T)(implicit rw: RW[T], ctx: mill.define.Ctx): Task[T] = + macro Target.Internal.targetImpl[T] + + implicit def applyImplicit2[T](t: Result[T])(implicit rw: RW[T], ctx: mill.define.Ctx): Task[T] = + macro Target.Internal.targetResultImpl[T] + abstract class Ops[+T] { this: Task[T] => def map[V](f: T => V): Task[V] = new Task.Mapped(this, f) def filter(f: T => Boolean): Task[T] = this @@ -85,9 +92,9 @@ object Task { } /** - * Represents a task that can be referenced by its path segments. `T{...}` - * targets, `T.input`, `T.worker`, etc. but not including anonymous - * `T.task` or `T.traverse` etc. instances + * Represents a task that can be referenced by its path segments. `Task {...}` + * targets, `Task.input`, `Task.worker`, etc. but not including anonymous + * `Task.anon` or `Task.traverse` etc. instances */ trait NamedTask[+T] extends Task[T] { @@ -107,7 +114,7 @@ trait NamedTask[+T] extends Task[T] { def evaluate(ctx: mill.api.Ctx): Result[T] = ctx.arg[T](0) - val ctx: Ctx = ctx0.withSegments(segments = ctx0.segments ++ Seq(ctx0.segment)) + override val ctx: Ctx = ctx0.withSegments(segments = ctx0.segments ++ Seq(ctx0.segment)) val inputs: Seq[Task[_]] = Seq(t) def readWriterOpt: Option[upickle.default.ReadWriter[_]] = None @@ -121,223 +128,13 @@ trait NamedTask[+T] extends Task[T] { */ trait Target[+T] extends NamedTask[T] -/** - * The [[mill.define.Target]] companion object, usually aliased as [[T]], - * provides most of the helper methods and macros used to build task graphs. - * methods like `T.`[[apply]], `T.`[[sources]], `T.`[[command]] allow you to - * define the tasks, while methods like `T.`[[dest]], `T.`[[log]] or - * `T.`[[env]] provide the core APIs that are provided to a task implementation - */ -object Target extends Applicative.Applyer[Task, Task, Result, mill.api.Ctx] { - - /** - * `T.dest` is a unique `os.Path` (e.g. `out/classFiles.dest/` or `out/run.dest/`) - * that is assigned to every Target or Command. It is cleared before your - * task runs, and you can use it as a scratch space for temporary files or - * a place to put returned artifacts. This is guaranteed to be unique for - * every Target or Command, so you can be sure that you will not collide or - * interfere with anyone else writing to those same paths. - */ - def dest(implicit ctx: mill.api.Ctx.Dest): os.Path = ctx.dest - - /** - * `T.log` is the default logger provided for every task. While your task is running, - * `System.out` and `System.in` are also redirected to this logger. The logs for a - * task are streamed to standard out/error as you would expect, but each task's - * specific output is also streamed to a log file on disk, e.g. `out/run.log` or - * `out/classFiles.log` for you to inspect later. - * - * Messages logged with `log.debug` appear by default only in the log files. - * You can use the `--debug` option when running mill to show them on the console too. - */ - def log(implicit ctx: mill.api.Ctx.Log): Logger = ctx.log - - /** - * Returns the implicit [[mill.api.Ctx.Home.home]] in scope. - */ - def home(implicit ctx: mill.api.Ctx.Home): os.Path = ctx.home - - /** - * `T.env` is the environment variable map passed to the Mill command when - * it is run; typically used inside a `T.input` to ensure any changes in - * the env vars are properly detected. - * - * Note that you should not use `sys.env`, as Mill's long-lived server - * process means that `sys.env` variables may not be up to date. - */ - def env(implicit ctx: mill.api.Ctx.Env): Map[String, String] = ctx.env - - /** - * Returns the implicit [[mill.api.Ctx.Args.args]] in scope. - */ - def args(implicit ctx: mill.api.Ctx.Args): IndexedSeq[_] = ctx.args - - /** - * Report test results to BSP for IDE integration - */ - def testReporter(implicit ctx: mill.api.Ctx): TestReporter = ctx.testReporter - - /** - * Report build results to BSP for IDE integration - */ - def reporter(implicit ctx: mill.api.Ctx): Int => Option[CompileProblemReporter] = ctx.reporter - - /** - * This is the `os.Path` pointing to the project root directory. - * - * This is the preferred access to the project directory, and should - * always be prefered over `os.pwd`* (which might also point to the - * project directory in classic cli scenarios, but might not in other - * use cases like BSP or LSP server usage). - */ - def workspace(implicit ctx: mill.api.Ctx): os.Path = ctx.workspace - - /** - * A target is the most common [[Task]] a user would encounter, commonly - * defined using the `def foo = T{...}` syntax. [[TargetImpl]]s require that their - * return type is JSON serializable. In return they automatically caches their - * return value to disk, only re-computing if upstream [[Task]]s change - */ - implicit def apply[T](t: T)(implicit rw: RW[T], ctx: mill.define.Ctx): Target[T] = - macro Internal.targetImpl[T] - - implicit def apply[T](t: Result[T])(implicit rw: RW[T], ctx: mill.define.Ctx): Target[T] = - macro Internal.targetResultImpl[T] - - def apply[T](t: Task[T])(implicit rw: RW[T], ctx: mill.define.Ctx): Target[T] = - macro Internal.targetTaskImpl[T] - - /** - * [[PersistentImpl]] are a flavor of [[TargetImpl]], normally defined using - * the `T.persistent{...}` syntax. The main difference is that while - * [[TargetImpl]] deletes the `T.dest` folder in between runs, - * [[PersistentImpl]] preserves it. This lets the user make use of files on - * disk that persistent between runs of the task, e.g. to implement their own - * fine-grained caching beyond what Mill provides by default. - * - * Note that the user defining a `T.persistent` task is taking on the - * responsibility of ensuring that their implementation is idempotent, i.e. - * that it computes the same result whether or not there is data in `T.dest`. - * Violating that invariant can result in confusing mis-behaviors - */ - def persistent[T](t: Result[T])(implicit rw: RW[T], ctx: mill.define.Ctx): Target[T] = - macro Internal.persistentImpl[T] - - /** - * A specialization of [[InputImpl]] defined via `T.sources`, [[SourcesImpl]] - * uses [[PathRef]]s to compute a signature for a set of source files and - * folders. - * - * This is most used when detecting changes in source code: when you edit a - * file and run `mill compile`, it is the `T.sources` that re-computes the - * signature for you source files/folders and decides whether or not downstream - * [[TargetImpl]]s need to be invalidated and re-computed. - */ - def sources(values: Result[os.Path]*)(implicit ctx: mill.define.Ctx): Target[Seq[PathRef]] = - macro Internal.sourcesImpl1 - - def sources(values: Result[Seq[PathRef]])(implicit ctx: mill.define.Ctx): Target[Seq[PathRef]] = - macro Internal.sourcesImpl2 +object Target extends TaskCompanion { - /** - * Similar to [[Source]], but only for a single source file or folder. Defined - * using `T.source`. - */ - def source(value: Result[os.Path])(implicit ctx: mill.define.Ctx): Target[PathRef] = - macro Internal.sourceImpl1 + implicit def applyImplicit[T](t: T)(implicit rw: RW[T], ctx: mill.define.Ctx): Target[T] = + macro Target.Internal.targetImpl[T] - def source(value: Result[PathRef])(implicit ctx: mill.define.Ctx): Target[PathRef] = - macro Internal.sourceImpl2 - - /** - * [[InputImpl]]s, normally defined using `T.input`, are [[NamedTask]]s that - * re-evaluate every time Mill is run. This is in contrast to [[TargetImpl]]s - * which only re-evaluate when upstream tasks change. - * - * [[InputImpl]]s are useful when you want to capture some input to the Mill - * build graph that comes from outside: maybe from an environment variable, a - * JVM system property, the hash returned by `git rev-parse HEAD`. Reading - * these external mutable variables inside a `T{...}` [[TargetImpl]] will - * incorrectly cache them forever. Reading them inside a `T.input{...}` - * will re-compute them every time, and only if the value changes would it - * continue to invalidate downstream [[TargetImpl]]s - * - * The most common case of [[InputImpl]] is [[SourceImpl]] and [[SourcesImpl]], - * used for detecting changes to source files. - */ - def input[T](value: Result[T])(implicit - w: upickle.default.Writer[T], - ctx: mill.define.Ctx - ): Target[T] = - macro Internal.inputImpl[T] - - /** - * [[Command]]s are only [[NamedTask]]s defined using - * `def foo() = T.command{...}` and are typically called from the - * command-line. Unlike other [[NamedTask]]s, [[Command]]s can be defined to - * take arguments that are automatically converted to command-line - * arguments, as long as an implicit [[mainargs.TokensReader]] is available. - */ - def command[T](t: Task[T])(implicit - ctx: mill.define.Ctx, - w: W[T], - cls: EnclosingClass - ): Command[T] = macro Internal.commandFromTask[T] - - def command[T](t: Result[T])(implicit - w: W[T], - ctx: mill.define.Ctx, - cls: EnclosingClass - ): Command[T] = macro Internal.commandImpl[T] - - /** - * [[Worker]] is a [[NamedTask]] that lives entirely in-memory, defined using - * `T.worker{...}`. The value returned by `T.worker{...}` is long-lived, - * persisting as long as the Mill process is kept alive (e.g. via `--watch`, - * or via its default `MillServerMain` server process). This allows the user to - * perform in-memory caching that is even more aggressive than the disk-based - * caching enabled by [[PersistentImpl]]: your [[Worker]] can cache running - * sub-processes, JVM Classloaders with JITed code, and all sorts of things - * that do not easily serialize to JSON on disk. - * - * Like [[PersistentImpl]], The user defining a [[Worker]] assumes the - * responsibility of ensuring the implementation is idempotent regardless of - * what in-memory state the worker may have. - */ - def worker[T](t: Task[T])(implicit ctx: mill.define.Ctx): Worker[T] = - macro Internal.workerImpl1[T] - - def worker[T](t: Result[T])(implicit ctx: mill.define.Ctx): Worker[T] = - macro Internal.workerImpl2[T] - - /** - * Creates an anonymous `Task`. These depend on other tasks and - * be-depended-upon by other tasks, but cannot be run directly from the - * command line and do not perform any caching. Typically used as helpers to - * implement `T{...}` targets. - */ - def task[T](t: Result[T]): Task[T] = macro Applicative.impl[Task, T, mill.api.Ctx] - - /** - * Converts a `Seq[Task[T]]` into a `Task[Seq[T]]` - */ - def sequence[T](source: Seq[Task[T]]): Task[Seq[T]] = new Task.Sequence[T](source) - - /** - * Converts a `Seq[T]` into a `Task[Seq[V]]` using the given `f: T => Task[V]` - */ - def traverse[T, V](source: Seq[T])(f: T => Task[V]): Task[Seq[V]] = { - new Task.Sequence[V](source.map(f)) - } - - /** - * A variant of [[traverse]] that also provides the [[mill.api.Ctx]] to the - * function [[f]] - */ - def traverseCtx[I, R](xs: Seq[Task[I]])(f: (IndexedSeq[I], mill.api.Ctx) => Result[R]) - : Task[R] = { - new Task.TraverseCtx[I, R](xs, f) - } + implicit def applyImplicit[T](t: Result[T])(implicit rw: RW[T], ctx: mill.define.Ctx): Target[T] = + macro Target.Internal.targetResultImpl[T] object Internal { private def isPrivateTargetOption(c: Context): c.Expr[Option[Boolean]] = { @@ -596,6 +393,220 @@ object Target extends Applicative.Applyer[Task, Task, Result, mill.api.Ctx] { ) } } + +} + +/** + * The [[mill.define.Task]] companion object, usually aliased as [[task]], + * provides most of the helper methods and macros used to build task graphs. + * methods like `Task.`[[apply]], `Task.`[[sources]], `Task.`[[command]] allow you to + * define the tasks, while methods like `Task.`[[dest]], `Task.`[[log]] or + * `Task.`[[env]] provide the core APIs that are provided to a task implementation + */ +trait TaskCompanion extends Applicative.Applyer[Task, Task, Result, mill.api.Ctx] { + + /** + * `Task.dest` is a unique `os.Path` (e.g. `out/classFiles.dest/` or `out/run.dest/`) + * that is assigned to every Target or Command. It is cleared before your + * task runs, and you can use it as a scratch space for temporary files or + * a place to put returned artifacts. This is guaranteed to be unique for + * every Target or Command, so you can be sure that you will not collide or + * interfere with anyone else writing to those same paths. + */ + def dest(implicit ctx: mill.api.Ctx.Dest): os.Path = ctx.dest + + /** + * `Task.log` is the default logger provided for every Task. While your task is running, + * `System.out` and `System.in` are also redirected to this logger. The logs for a + * task are streamed to standard out/error as you would expect, but each task's + * specific output is also streamed to a log file on disk, e.g. `out/run.log` or + * `out/classFiles.log` for you to inspect later. + * + * Messages logged with `log.debug` appear by default only in the log files. + * You can use the `--debug` option when running mill to show them on the console too. + */ + def log(implicit ctx: mill.api.Ctx.Log): Logger = ctx.log + + /** + * Returns the implicit [[mill.api.Ctx.Home.home]] in scope. + */ + def home(implicit ctx: mill.api.Ctx.Home): os.Path = ctx.home + + /** + * `Task.env` is the environment variable map passed to the Mill command when + * it is run; typically used inside a `Task.input` to ensure any changes in + * the env vars are properly detected. + * + * Note that you should not use `sys.env`, as Mill's long-lived server + * process means that `sys.env` variables may not be up to date. + */ + def env(implicit ctx: mill.api.Ctx.Env): Map[String, String] = ctx.env + + /** + * Returns the implicit [[mill.api.Ctx.Args.args]] in scope. + */ + def args(implicit ctx: mill.api.Ctx.Args): IndexedSeq[_] = ctx.args + + /** + * Report test results to BSP for IDE integration + */ + def testReporter(implicit ctx: mill.api.Ctx): TestReporter = ctx.testReporter + + /** + * Report build results to BSP for IDE integration + */ + def reporter(implicit ctx: mill.api.Ctx): Int => Option[CompileProblemReporter] = ctx.reporter + + /** + * This is the `os.Path` pointing to the project root directory. + * + * This is the preferred access to the project directory, and should + * always be prefered over `os.pwd`* (which might also point to the + * project directory in classic cli scenarios, but might not in other + * use cases like BSP or LSP server usage). + */ + def workspace(implicit ctx: mill.api.Ctx): os.Path = ctx.workspace + + /** + * A target is the most common [[Task]] a user would encounter, commonly + * defined using the `def foo = Task {...}` syntax. [[TargetImpl]]s require that their + * return type is JSON serializable. In return they automatically caches their + * return value to disk, only re-computing if upstream [[Task]]s change + */ + def apply[T](t: T)(implicit rw: RW[T], ctx: mill.define.Ctx): Task[T] = + macro Target.Internal.targetImpl[T] + + def apply[T](t: Result[T])(implicit rw: RW[T], ctx: mill.define.Ctx): Task[T] = + macro Target.Internal.targetResultImpl[T] + + def ofTask[T](t: Task[T])(implicit rw: RW[T], ctx: mill.define.Ctx): Task[T] = + macro Target.Internal.targetTaskImpl[T] + + /** + * [[PersistentImpl]] are a flavor of [[TargetImpl]], normally defined using + * the `Task.persistent{...}` syntax. The main difference is that while + * [[TargetImpl]] deletes the `Task.dest` folder in between runs, + * [[PersistentImpl]] preserves it. This lets the user make use of files on + * disk that persistent between runs of the task, e.g. to implement their own + * fine-grained caching beyond what Mill provides by default. + * + * Note that the user defining a `Task.persistent` task is taking on the + * responsibility of ensuring that their implementation is idempotent, i.e. + * that it computes the same result whether or not there is data in `Task.dest`. + * Violating that invariant can result in confusing mis-behaviors + */ + def persistent[T](t: Result[T])(implicit rw: RW[T], ctx: mill.define.Ctx): Task[T] = + macro Target.Internal.persistentImpl[T] + + /** + * A specialization of [[InputImpl]] defined via `Task.sources`, [[SourcesImpl]] + * uses [[PathRef]]s to compute a signature for a set of source files and + * folders. + * + * This is most used when detecting changes in source code: when you edit a + * file and run `mill compile`, it is the `Task.sources` that re-computes the + * signature for you source files/folders and decides whether or not downstream + * [[TargetImpl]]s need to be invalidated and re-computed. + */ + def sources(values: Result[os.Path]*)(implicit ctx: mill.define.Ctx): Task[Seq[PathRef]] = + macro Target.Internal.sourcesImpl1 + + def sources(values: Result[Seq[PathRef]])(implicit ctx: mill.define.Ctx): Task[Seq[PathRef]] = + macro Target.Internal.sourcesImpl2 + + /** + * Similar to [[Source]], but only for a single source file or folder. Defined + * using `Task.source`. + */ + def source(value: Result[os.Path])(implicit ctx: mill.define.Ctx): Task[PathRef] = + macro Target.Internal.sourceImpl1 + + def source(value: Result[PathRef])(implicit ctx: mill.define.Ctx): Task[PathRef] = + macro Target.Internal.sourceImpl2 + + /** + * [[InputImpl]]s, normally defined using `Task.input`, are [[NamedTask]]s that + * re-evaluate every time Mill is run. This is in contrast to [[TargetImpl]]s + * which only re-evaluate when upstream tasks change. + * + * [[InputImpl]]s are useful when you want to capture some input to the Mill + * build graph that comes from outside: maybe from an environment variable, a + * JVM system property, the hash returned by `git rev-parse HEAD`. Reading + * these external mutable variables inside a `Task {...}` [[TargetImpl]] will + * incorrectly cache them forever. Reading them inside a `Task.input{...}` + * will re-compute them every time, and only if the value changes would it + * continue to invalidate downstream [[TargetImpl]]s + * + * The most common case of [[InputImpl]] is [[SourceImpl]] and [[SourcesImpl]], + * used for detecting changes to source files. + */ + def input[T](value: Result[T])(implicit + w: upickle.default.Writer[T], + ctx: mill.define.Ctx + ): Task[T] = + macro Target.Internal.inputImpl[T] + + /** + * [[Command]]s are only [[NamedTask]]s defined using + * `def foo() = Task.command{...}` and are typically called from the + * command-line. Unlike other [[NamedTask]]s, [[Command]]s can be defined to + * take arguments that are automatically converted to command-line + * arguments, as long as an implicit [[mainargs.TokensReader]] is available. + */ + def command[T](t: Result[T])(implicit + w: W[T], + ctx: mill.define.Ctx, + cls: EnclosingClass + ): Command[T] = macro Target.Internal.commandImpl[T] + + /** + * [[Worker]] is a [[NamedTask]] that lives entirely in-memory, defined using + * `Task.worker{...}`. The value returned by `Task.worker{...}` is long-lived, + * persisting as long as the Mill process is kept alive (e.g. via `--watch`, + * or via its default `MillServerMain` server process). This allows the user to + * perform in-memory caching that is even more aggressive than the disk-based + * caching enabled by [[PersistentImpl]]: your [[Worker]] can cache running + * sub-processes, JVM Classloaders with JITed code, and all sorts of things + * that do not easily serialize to JSON on disk. + * + * Like [[PersistentImpl]], The user defining a [[Worker]] assumes the + * responsibility of ensuring the implementation is idempotent regardless of + * what in-memory state the worker may have. + */ + def worker[T](t: Result[T])(implicit ctx: mill.define.Ctx): Worker[T] = + macro Target.Internal.workerImpl2[T] + + @deprecated("Use .anon", "0.12.0") + def task[T](t: Result[T]): Task[T] = macro Applicative.impl[Task, T, mill.api.Ctx] + + /** + * Creates an anonymous `Task`. These depend on other tasks and + * be-depended-upon by other tasks, but cannot be run directly from the + * command line and do not perform any caching. Typically used as helpers to + * implement `Task {...}` targets. + */ + def anon[T](t: Result[T]): Task[T] = macro Applicative.impl[Task, T, mill.api.Ctx] + + /** + * Converts a `Seq[Task[T]]` into a `Task[Seq[T]]` + */ + def sequence[T](source: Seq[Task[T]]): Task[Seq[T]] = new Task.Sequence[T](source) + + /** + * Converts a `Seq[T]` into a `Task[Seq[V]]` using the given `f: T => Task[V]` + */ + def traverse[T, V](source: Seq[T])(f: T => Task[V]): Task[Seq[V]] = { + new Task.Sequence[V](source.map(f)) + } + + /** + * A variant of [[traverse]] that also provides the [[mill.api.Ctx]] to the + * function [[f]] + */ + def traverseCtx[I, R](xs: Seq[Task[I]])(f: (IndexedSeq[I], mill.api.Ctx) => Result[R]) + : Task[R] = { + new Task.TraverseCtx[I, R](xs, f) + } } class TargetImpl[+T]( diff --git a/main/define/test/src/mill/define/ApplicativeTests.scala b/main/define/test/src/mill/define/ApplicativeTests.scala index 81c536e51e2..54292fb24eb 100644 --- a/main/define/test/src/mill/define/ApplicativeTests.scala +++ b/main/define/test/src/mill/define/ApplicativeTests.scala @@ -28,7 +28,7 @@ object ApplicativeTests extends TestSuite { value } } - @compileTimeOnly("Target.ctx() can only be used with a T{...} block") + @compileTimeOnly("Target.ctx() can only be used with a Task {...} block") @ImplicitStub implicit def taskCtx: String = ??? diff --git a/main/define/test/src/mill/define/BasePathTests.scala b/main/define/test/src/mill/define/BasePathTests.scala index 33f8bcee0d6..675bdb8614a 100644 --- a/main/define/test/src/mill/define/BasePathTests.scala +++ b/main/define/test/src/mill/define/BasePathTests.scala @@ -61,6 +61,8 @@ object BasePathTests extends TestSuite { override def millSourcePath = super.millSourcePath / "overriddenBasePathDoubleNested" } } + + val millDiscover: Discover[this.type] = Discover[this.type] } assert( overriddenBasePath.millSourcePath == os.pwd / "overriddenBasePathRootValue", diff --git a/main/define/test/src/mill/define/CacherTests.scala b/main/define/test/src/mill/define/CacherTests.scala index b0d013ba5a9..651b85c3c28 100644 --- a/main/define/test/src/mill/define/CacherTests.scala +++ b/main/define/test/src/mill/define/CacherTests.scala @@ -1,25 +1,31 @@ package mill.define import mill.util.{TestEvaluator, TestUtil} -import mill.T +import mill.{Task, T} import mill.api.Result.Success import utest._ import utest.framework.TestPath object CacherTests extends TestSuite { - object Base extends Base + object Base extends Base { + val millDiscover: Discover[this.type] = Discover[this.type] + } trait Base extends TestUtil.BaseModule { - def value = T { 1 } - def result = T { Success(1) } + def value = Task { 1 } + def result = Task { Success(1) } + } + object Middle extends Middle { + val millDiscover: Discover[this.type] = Discover[this.type] } - object Middle extends Middle trait Middle extends Base { - override def value = T { super.value() + 2 } - def overridden = T { super.value() } + override def value = Task { super.value() + 2 } + def overridden = Task { super.value() } + } + object Terminal extends Terminal { + val millDiscover: Discover[this.type] = Discover[this.type] } - object Terminal extends Terminal trait Terminal extends Middle { - override def value = T { super.value() + 4 } + override def value = Task { super.value() + 4 } } val tests = Tests { diff --git a/main/define/test/src/mill/define/DiscoverTests.scala b/main/define/test/src/mill/define/DiscoverTests.scala index a08281c2db7..4cfc50e6b65 100644 --- a/main/define/test/src/mill/define/DiscoverTests.scala +++ b/main/define/test/src/mill/define/DiscoverTests.scala @@ -6,7 +6,7 @@ import utest._ object DiscoverTests extends TestSuite { val testGraphs = new TestGraphs val tests = Tests { - def check[T <: Module](m: T)(targets: (T => Target[_])*) = { + def check[T <: Module](m: T)(targets: (T => Task[_])*) = { val discovered = m.millInternal.targets val expected = targets.map(_(m)).toSet assert(discovered == expected) @@ -28,7 +28,13 @@ object DiscoverTests extends TestSuite { check(TestGraphs.TraitWithModuleObject)(_.TraitModule.testFrameworks) } "nestedModule" - { - check(TestGraphs.nestedModule)(_.single, _.nested.single, _.classInstance.single) + check(TestGraphs.nestedModule)( + _.single, + _.nested.single, + _.classInstance.single, + _.classInstance.visible2, + _.classInstance.visible3 + ) } "singleCross" - { check(TestGraphs.singleCross)( diff --git a/main/define/test/src/mill/define/MacroErrorTests.scala b/main/define/test/src/mill/define/MacroErrorTests.scala index 2c6494009a5..508b2aedbe8 100644 --- a/main/define/test/src/mill/define/MacroErrorTests.scala +++ b/main/define/test/src/mill/define/MacroErrorTests.scala @@ -1,7 +1,7 @@ package mill.define import utest._ -import mill.{T, Module} +import mill.{T, Task, Module} import mill.util.TestUtil object MacroErrorTests extends TestSuite { @@ -11,7 +11,7 @@ object MacroErrorTests extends TestSuite { val expectedMsg = "T{} members must be defs defined in a Cacher class/trait/object body" - val err = compileError("object Foo extends TestUtil.BaseModule{ val x = T{1} }") + val err = compileError("object Foo extends TestUtil.BaseModule{ val x = Task {1} }") assert(err.msg == expectedMsg) } @@ -19,76 +19,76 @@ object MacroErrorTests extends TestSuite { "command" - { val e = compileError(""" object foo extends mill.util.TestUtil.BaseModule{ - def w = T.command{1} + def w = Task.command{1} } mill.define.Discover[foo.type] """) assert( - e.msg.contains("`T.command` definitions must have 1 parameter list"), + e.msg.contains("`Task.command` definitions must have 1 parameter list"), e.pos.contains("def w = ") ) } - "target" - { - val e = compileError(""" - object foo extends mill.util.TestUtil.BaseModule{ - def x() = T{1} - } - mill.define.Discover[foo.type] - """) - assert( - e.msg.contains("Target definitions must have 0 parameter lists"), - e.pos.contains("def x() = ") - ) - } - "input" - { - val e = compileError(""" - object foo extends mill.util.TestUtil.BaseModule{ - def y() = T.input{1} - } - mill.define.Discover[foo.type] - """) - assert( - e.msg.contains("Target definitions must have 0 parameter lists"), - e.pos.contains("def y() = ") - ) - } - "sources" - { - val e = compileError(""" - object foo extends mill.util.TestUtil.BaseModule{ - def z() = T.sources{os.pwd} - } - mill.define.Discover[foo.type] - """) - assert( - e.msg.contains("Target definitions must have 0 parameter lists"), - e.pos.contains("def z() = ") - ) - } - "persistent" - { - val e = compileError(""" - object foo extends mill.util.TestUtil.BaseModule{ - def a() = T.persistent{1} - } - mill.define.Discover[foo.type] - """) - assert( - e.msg.contains("Target definitions must have 0 parameter lists"), - e.pos.contains("def a() = ") - ) - } +// "target" - { +//// val e = compileError(""" +// object foo extends mill.util.TestUtil.BaseModule{ +// def x() = Task {1} +// } +// mill.define.Discover[foo.type] +//// """) +//// assert( +//// e.msg.contains("Target definitions must have 0 parameter lists"), +//// e.pos.contains("def x() = ") +//// ) +// } +// "input" - { +// val e = compileError(""" +// object foo extends mill.util.TestUtil.BaseModule{ +// def y() = Task.input{1} +// } +// mill.define.Discover[foo.type] +// """) +// assert( +// e.msg.contains("Target definitions must have 0 parameter lists"), +// e.pos.contains("def y() = ") +// ) +// } +// "sources" - { +// val e = compileError(""" +// object foo extends mill.util.TestUtil.BaseModule{ +// def z() = Task.sources{os.pwd} +// } +// mill.define.Discover[foo.type] +// """) +// assert( +// e.msg.contains("Target definitions must have 0 parameter lists"), +// e.pos.contains("def z() = ") +// ) +// } +// "persistent" - { +// val e = compileError(""" +// object foo extends mill.util.TestUtil.BaseModule{ +// def a() = Task.persistent{1} +// } +// mill.define.Discover[foo.type] +// """) +// assert( +// e.msg.contains("Target definitions must have 0 parameter lists"), +// e.pos.contains("def a() = ") +// ) +// } } "badTmacro" - { - // Make sure we can reference values from outside the T{...} block as part + // Make sure we can reference values from outside the Task {...} block as part // of our `Target#apply()` calls, but we cannot reference any values that - // come from inside the T{...} block + // come from inside the Task {...} block "pos" - { val e = compileError(""" - val a = T{ 1 } + val a = Task { 1 } val arr = Array(a) val b = { val c = 0 - T{ + Task { arr(c)() } } @@ -100,12 +100,12 @@ object MacroErrorTests extends TestSuite { "neg" - { val expectedMsg = - "Target#apply() call cannot use `value n` defined within the T{...} block" + "Target#apply() call cannot use `value n` defined within the Task {...} block" val err = compileError("""new Module{ - def a = T{ 1 } + def a = Task { 1 } val arr = Array(a) def b = { - T{ + Task { val n = 0 arr(n)() } @@ -116,12 +116,12 @@ object MacroErrorTests extends TestSuite { "neg2" - { val expectedMsg = - "Target#apply() call cannot use `value x` defined within the T{...} block" + "Target#apply() call cannot use `value x` defined within the Task {...} block" val err = compileError("""new Module{ - def a = T{ 1 } + def a = Task { 1 } val arr = Array(a) def b = { - T{ + Task { arr.map{x => x()} } } @@ -131,10 +131,10 @@ object MacroErrorTests extends TestSuite { "neg3" - { val borkedCachedDiamond1 = utest.compileError(""" object borkedCachedDiamond1 { - def up = T{ TestUtil.test() } - def left = T{ TestUtil.test(up) } - def right = T{ TestUtil.test(up) } - def down = T{ TestUtil.test(left, right) } + def up = Task { TestUtil.test() } + def left = Task { TestUtil.test(up) } + def right = Task { TestUtil.test(up) } + def down = Task { TestUtil.test(left, right) } } """) assert(borkedCachedDiamond1.msg.contains( diff --git a/main/eval/src/mill/eval/EvaluatorImpl.scala b/main/eval/src/mill/eval/EvaluatorImpl.scala index 56ca20c862a..67735d196c0 100644 --- a/main/eval/src/mill/eval/EvaluatorImpl.scala +++ b/main/eval/src/mill/eval/EvaluatorImpl.scala @@ -4,6 +4,7 @@ import mill.api.Val import mill.api.Strict.Agg import mill.define._ import mill.util._ + import scala.collection.mutable import scala.reflect.ClassTag diff --git a/main/eval/src/mill/eval/EvaluatorPaths.scala b/main/eval/src/mill/eval/EvaluatorPaths.scala index bd446219c1d..b959447d1b1 100644 --- a/main/eval/src/mill/eval/EvaluatorPaths.scala +++ b/main/eval/src/mill/eval/EvaluatorPaths.scala @@ -1,7 +1,7 @@ package mill.eval import mill.api.internal -import mill.define.{NamedTask, Segment, Segments} +import mill.define.{Segment, Segments, Task} import java.util.regex.Matcher @@ -43,7 +43,7 @@ object EvaluatorPaths { } def resolveDestPaths( workspacePath: os.Path, - task: NamedTask[_] + task: Task[_] ): EvaluatorPaths = resolveDestPaths(workspacePath, task.ctx.segments, task.ctx.foreign) // case-insensitive match on reserved names diff --git a/main/eval/src/mill/eval/GroupEvaluator.scala b/main/eval/src/mill/eval/GroupEvaluator.scala index 3ee01997a99..844cc2ecd2f 100644 --- a/main/eval/src/mill/eval/GroupEvaluator.scala +++ b/main/eval/src/mill/eval/GroupEvaluator.scala @@ -42,7 +42,7 @@ private[mill] trait GroupEvaluator { this.threadCount.getOrElse(Runtime.getRuntime().availableProcessors()) /** - * Synchronize evaluations of the same terminal task. + * Synchronize evaluations of the same terminal Task. * This isn't necessarily needed for normal Mill executions, * but in an BSP context, where multiple requests where handled concurrently in the same Mill instance, * evaluating the same task concurrently can happen. @@ -147,7 +147,7 @@ private[mill] trait GroupEvaluator { )) .getDeclaringClass.getName val name = namedTask.ctx.segment.pathSegments.last - val expectedName = methodClass + "#" + name + "()mill.define.Target" + val expectedName = methodClass + "#" + name + "()mill.define.Task" // We not only need to look up the code hash of the Target method being called, // but also the code hash of the constructors required to instantiate the Module @@ -316,9 +316,9 @@ private[mill] trait GroupEvaluator { override def rawOutputStream: PrintStream = logger.rawOutputStream } - // This is used to track the usage of `T.dest` in more than one Task + // This is used to track the usage of `Task.dest` in more than one Task // But it's not really clear what issue we try to prevent here - // Vice versa, being able to use T.dest in multiple `T.task` + // Vice versa, being able to use Task.dest in multiple `Task.anon` // is rather essential to split up larger tasks into small parts // So I like to disable this detection for now var usedDest = Option.empty[(Task[_], Array[StackTraceElement])] diff --git a/main/eval/src/mill/eval/Terminal.scala b/main/eval/src/mill/eval/Terminal.scala index 2baf1dc9a98..aca4d90c41f 100644 --- a/main/eval/src/mill/eval/Terminal.scala +++ b/main/eval/src/mill/eval/Terminal.scala @@ -5,7 +5,7 @@ import mill.define.{NamedTask, Segment, Segments} /** * A terminal or terminal target is some important work unit, that in most cases has a name (Right[Labelled]) * or was directly called by the user (Left[Task]). - * It's a T, T.worker, T.input, T.source, T.sources, T.persistent + * It's a T, Task.worker, Task.input, Task.source, Task.sources, Task.persistent */ sealed trait Terminal { def render: String @@ -18,7 +18,7 @@ object Terminal { } case class Task[T](task: mill.define.Task[_]) extends Terminal { - def render = task.toString + def render = Task.toString } def destSegments(labelledTask: Terminal.Labelled[_]): Segments = { @@ -29,7 +29,7 @@ object Terminal { } def printTerm(term: Terminal): String = term match { - case Terminal.Task(task) => task.toString() + case Terminal.Task(task) => Task.toString() case labelled: Terminal.Labelled[_] => val Seq(first, rest @ _*) = destSegments(labelled).value val msgParts = Seq(first.asInstanceOf[Segment.Label].value) ++ rest.map { diff --git a/main/eval/test/src/mill/eval/EvaluationTests.scala b/main/eval/test/src/mill/eval/EvaluationTests.scala index 4b83517861a..fe9ed9e2d5c 100644 --- a/main/eval/test/src/mill/eval/EvaluationTests.scala +++ b/main/eval/test/src/mill/eval/EvaluationTests.scala @@ -1,8 +1,8 @@ package mill.eval import mill.util.TestUtil.{Test, test} -import mill.define.{TargetImpl, Task} -import mill.T +import mill.define.{Discover, TargetImpl} +import mill.{T, Task} import mill.util.{TestEvaluator, TestGraphs, TestUtil} import mill.api.Strict.Agg import os.SubPath @@ -304,11 +304,13 @@ class EvaluationTests(threadCount: Option[Int]) extends TestSuite { var leftCount = 0 var rightCount = 0 var middleCount = 0 - def up = T { test.anon() } - def left = T.task { leftCount += 1; up() + 1 } - def middle = T.task { middleCount += 1; 100 } - def right = T { rightCount += 1; 10000 } - def down = T { left() + middle() + right() } + def up = Task.ofTask { test.anon() } + def left = Task.anon { leftCount += 1; up() + 1 } + def middle = Task.anon { middleCount += 1; 100 } + def right = Task { rightCount += 1; 10000 } + def down = Task { left() + middle() + right() } + + val millDiscover: Discover[this.type] = Discover[this.type] } import build._ diff --git a/main/eval/test/src/mill/eval/FailureTests.scala b/main/eval/test/src/mill/eval/FailureTests.scala index dd2fbb237ec..6692460c0c7 100644 --- a/main/eval/test/src/mill/eval/FailureTests.scala +++ b/main/eval/test/src/mill/eval/FailureTests.scala @@ -1,8 +1,9 @@ package mill.eval -import mill.T +import mill.{T, Task} import mill.util.{TestEvaluator, TestUtil} import mill.api.Result.OuterStack +import mill.define.Discover import utest._ object FailureTests extends TestSuite { @@ -181,12 +182,14 @@ object FailureTests extends TestSuite { "multipleUsesOfDest" - { object build extends TestUtil.BaseModule { - // Using `T.ctx( ).dest` twice in a single task is ok - def left = T { +T.dest.toString.length + T.dest.toString.length } + // Using `Task.ctx( ).dest` twice in a single task is ok + def left = Task { +Task.dest.toString.length + Task.dest.toString.length } - // Using `T.ctx( ).dest` once in two different tasks is ok - val task = T.task { T.dest.toString.length } - def right = T { task() + left() + T.dest.toString().length } + // Using `Task.ctx( ).dest` once in two different tasks is ok + val task = Task.anon { Task.dest.toString.length } + def right = Task { task() + left() + Task.dest.toString().length } + + val millDiscover: Discover[this.type] = Discover[this.type] } val check = new TestEvaluator(build) diff --git a/main/eval/test/src/mill/eval/GraphTests.scala b/main/eval/test/src/mill/eval/GraphTests.scala index 0a0c5dcbfdf..0c77ad7d3ae 100644 --- a/main/eval/test/src/mill/eval/GraphTests.scala +++ b/main/eval/test/src/mill/eval/GraphTests.scala @@ -69,9 +69,9 @@ object GraphTests extends TestSuite { } "groupAroundNamedTargets" - { - def check[T, R <: Target[Int]](base: T)( + def check[T, R <: Task[Int]](base: T)( target: T => R, - important0: Agg[T => Target[_]], + important0: Agg[T => Task[_]], expected: Agg[(R, Int)] ) = { @@ -85,7 +85,7 @@ object GraphTests extends TestSuite { TestUtil.checkTopological(flattened) for ((terminal, expectedSize) <- expected) { - val grouping = grouped.lookupKey(terminal) + val grouping = grouped.lookupKey(terminal.asTarget.get) assert( grouping.size == expectedSize, grouping.flatMap(_.asTarget: Option[Target[_]]).filter(important.contains) == Agg( diff --git a/main/eval/test/src/mill/eval/JavaCompileJarTests.scala b/main/eval/test/src/mill/eval/JavaCompileJarTests.scala index bc96507d6b1..7867c08cba9 100644 --- a/main/eval/test/src/mill/eval/JavaCompileJarTests.scala +++ b/main/eval/test/src/mill/eval/JavaCompileJarTests.scala @@ -2,12 +2,13 @@ package mill.eval import mill.util.Jvm import mill.api.Ctx.Dest -import mill.T +import mill.{T, Task} import mill.util.{TestEvaluator, TestUtil} import mill.api.Strict.Agg import mill.api.{JarManifest, Loose} import utest._ import mill._ +import mill.define.Discover object JavaCompileJarTests extends TestSuite { def compileAll(sources: mill.api.Loose.Agg[mill.api.PathRef])(implicit ctx: Dest) = { @@ -57,6 +58,8 @@ object JavaCompileJarTests extends TestSuite { os.proc("java", "-Duser.language=en", "-cp", classFiles().path, mainClsName) .call(stderr = os.Pipe) } + + val millDiscover: Discover[this.type] = Discover[this.type] } import Build._ diff --git a/main/eval/test/src/mill/eval/ModuleTests.scala b/main/eval/test/src/mill/eval/ModuleTests.scala index a0b0e057040..516081f8d1b 100644 --- a/main/eval/test/src/mill/eval/ModuleTests.scala +++ b/main/eval/test/src/mill/eval/ModuleTests.scala @@ -1,21 +1,23 @@ package mill.eval import mill.util.{TestEvaluator, TestUtil} -import mill.T +import mill.{Task, T} import mill.define.Discover import utest._ object ModuleTests extends TestSuite { object ExternalModule extends mill.define.ExternalModule { - def x = T { 13 } + def x = Task { 13 } object inner extends mill.Module { - def y = T { 17 } + def y = Task { 17 } } - lazy val millDiscover = Discover[this.type] + lazy val millDiscover: Discover[this.type] = Discover[this.type] } object Build extends TestUtil.BaseModule { - def z = T { ExternalModule.x() + ExternalModule.inner.y() } + def z = Task { ExternalModule.x() + ExternalModule.inner.y() } + + val millDiscover: Discover[this.type] = Discover[this.type] } val tests = Tests { "externalModuleTargetsAreNamespacedByModulePackagePath" - { @@ -37,8 +39,8 @@ object ModuleTests extends TestSuite { object Build extends mill.define.ExternalModule { - def z = T { ExternalModule.x() + ExternalModule.inner.y() } - lazy val millDiscover = Discover[this.type] + def z = Task { ExternalModule.x() + ExternalModule.inner.y() } + lazy val millDiscover: Discover[this.type] = Discover[this.type] } intercept[java.lang.AssertionError] { Build } diff --git a/main/eval/test/src/mill/eval/TaskTests.scala b/main/eval/test/src/mill/eval/TaskTests.scala index 1d47d3cd596..b86c9013b14 100644 --- a/main/eval/test/src/mill/eval/TaskTests.scala +++ b/main/eval/test/src/mill/eval/TaskTests.scala @@ -1,8 +1,8 @@ package mill.eval import utest._ -import mill.T -import mill.define.{Module, Worker} +import mill.{T, Task} +import mill.define.{Discover, Module, Worker} import mill.util.{TestEvaluator, TestUtil} import utest.framework.TestPath @@ -11,17 +11,17 @@ trait TaskTests extends TestSuite { var superBuildInputCount = 0 - def superBuildInputOverrideWithConstant = T.input { + def superBuildInputOverrideWithConstant = Task.input { superBuildInputCount += 1 superBuildInputCount } - def superBuildInputOverrideUsingSuper = T.input { + def superBuildInputOverrideUsingSuper = Task.input { superBuildInputCount += 1 superBuildInputCount } - def superBuildTargetOverrideWithInput = T { + def superBuildTargetOverrideWithInput = Task { 1234 } } @@ -31,100 +31,100 @@ trait TaskTests extends TestSuite { var workerCloseCount = 0 // Explicitly instantiate `Function1` objects to make sure we get // different instances each time - def staticWorker: Worker[Int => Int] = T.worker { + def staticWorker: Worker[Int => Int] = Task.worker { new Function1[Int, Int] { def apply(v1: Int) = v1 + 1 } } - def changeOnceWorker: Worker[Int => Int] = T.worker { + def changeOnceWorker: Worker[Int => Int] = Task.worker { new Function1[Int, Int] { def apply(v1: Int): Int = changeOnceInput() + v1 } } - def noisyWorker: Worker[Int => Int] = T.worker { + def noisyWorker: Worker[Int => Int] = Task.worker { new Function1[Int, Int] { def apply(v1: Int) = input() + v1 } } - def noisyClosableWorker: Worker[(Int => Int) with AutoCloseable] = T.worker { + def noisyClosableWorker: Worker[(Int => Int) with AutoCloseable] = Task.worker { new Function1[Int, Int] with AutoCloseable { override def apply(v1: Int) = input() + v1 override def close(): Unit = workerCloseCount += 1 } } - def changeOnceInput = T.input { + def changeOnceInput = Task.input { val ret = changeOnceCount if (changeOnceCount != 1) changeOnceCount = 1 ret } - def input = T.input { + def input = Task.input { count += 1 count } - def task = T.task { + def task = Task.anon { count += 1 count } - def taskInput = T { input() } - def taskNoInput = T { task() } + def taskInput = Task { input() } + def taskNoInput = Task { task() } - def persistent = T.persistent { + def persistent = Task.persistent { input() // force re-computation - os.makeDir.all(T.dest) - os.write.append(T.dest / "count", "hello\n") - os.read.lines(T.dest / "count").length + os.makeDir.all(Task.dest) + os.write.append(Task.dest / "count", "hello\n") + os.read.lines(Task.dest / "count").length } - def nonPersistent = T { + def nonPersistent = Task { input() // force re-computation - os.makeDir.all(T.dest) - os.write.append(T.dest / "count", "hello\n") - os.read.lines(T.dest / "count").length + os.makeDir.all(Task.dest) + os.write.append(Task.dest / "count", "hello\n") + os.read.lines(Task.dest / "count").length } - def staticWorkerDownstream = T { + def staticWorkerDownstream = Task { val w = staticWorker() w.apply(1) } - def reevalTrigger = T.input { + def reevalTrigger = Task.input { new Object().hashCode() } - def staticWorkerDownstreamReeval = T { + def staticWorkerDownstreamReeval = Task { val w = staticWorker() reevalTrigger() w.apply(1) } - def noisyWorkerDownstream = T { + def noisyWorkerDownstream = Task { val w = noisyWorker() w.apply(1) } - def noisyClosableWorkerDownstream = T { + def noisyClosableWorkerDownstream = Task { val w = noisyClosableWorker() w.apply(1) } - def changeOnceWorkerDownstream = T { + def changeOnceWorkerDownstream = Task { val w = changeOnceWorker() w.apply(1) } - override def superBuildInputOverrideWithConstant = T { 123 } - override def superBuildInputOverrideUsingSuper = T { + override def superBuildInputOverrideWithConstant = Task { 123 } + override def superBuildInputOverrideUsingSuper = Task { 123 + super.superBuildInputOverrideUsingSuper() } var superBuildTargetOverrideWithInputCount = 0 - override def superBuildTargetOverrideWithInput = T.input { + override def superBuildTargetOverrideWithInput = Task.input { superBuildTargetOverrideWithInputCount += 1 superBuildTargetOverrideWithInputCount } // Reproduction of issue https://github.com/com-lihaoyi/mill/issues/2958 object repro2958 extends Module { - val task1 = T.task { "task1" } - def task2 = T { task1() } - def task3 = T { task1() } - def command() = T.command { + val task1 = Task.anon { "task1" } + def task2 = Task { task1() } + def task3 = Task { task1() } + def command() = Task.command { val t2 = task2() val t3 = task3() s"${t2},${t3}" @@ -262,7 +262,9 @@ trait TaskTests extends TestSuite { object SeqTaskTests extends TaskTests { def withEnv(f: (Build, TestEvaluator) => Unit)(implicit tp: TestPath) = { - object build extends Build + object build extends Build { + val millDiscover: Discover[this.type] = Discover[this.type] + } val check = new TestEvaluator( build, threads = Some(1), @@ -273,7 +275,9 @@ object SeqTaskTests extends TaskTests { } object ParTaskTests extends TaskTests { def withEnv(f: (Build, TestEvaluator) => Unit)(implicit tp: TestPath) = { - object build extends Build + object build extends Build { + val millDiscover: Discover[this.type] = Discover[this.type] + } val check = new TestEvaluator( build, threads = Some(16), diff --git a/main/resolve/src/mill/resolve/Resolve.scala b/main/resolve/src/mill/resolve/Resolve.scala index adbbb0d85ab..e1768215da2 100644 --- a/main/resolve/src/mill/resolve/Resolve.scala +++ b/main/resolve/src/mill/resolve/Resolve.scala @@ -97,7 +97,12 @@ object Resolve { private def instantiateTarget(r: Resolved.Target, p: Module): Either[String, Target[_]] = { val definition = Reflect - .reflect(p.getClass, classOf[Target[_]], _ == r.segments.parts.last, true) + .reflect( + p.getClass, + classOf[mill.define.Task[_]], + _ == r.segments.parts.last, + true + ) .head ResolveCore.catchWrapException( @@ -132,10 +137,10 @@ object Resolve { rest: Seq[String], nullCommandDefaults: Boolean ): Iterable[Either[String, Command[_]]] = for { - (cls, (names, entryPoints)) <- discover.value - if cls.isAssignableFrom(target.getClass) - ep <- entryPoints - if ep.name == name + ep <- ResolveCore.findFromParents( + target.getClass, + discover.value.get(_).flatMap(_._2.find(_.name == name)).toSeq + ) } yield { def withNullDefault(a: mainargs.ArgSig): mainargs.ArgSig = { if (a.default.nonEmpty) a diff --git a/main/resolve/src/mill/resolve/ResolveCore.scala b/main/resolve/src/mill/resolve/ResolveCore.scala index 080bedbbdc3..9038bbe8bc3 100644 --- a/main/resolve/src/mill/resolve/ResolveCore.scala +++ b/main/resolve/src/mill/resolve/ResolveCore.scala @@ -433,21 +433,35 @@ private object ResolveCore { } } - val targets = Reflect - .reflect(cls, classOf[Target[_]], namePred, noParams = true) - .map { m => - Resolved.Target(Segments.labels(decode(m.getName))) -> - None - } + val targets = findFromParents( + cls, + c => baseModules.targetNamesByClass.getOrElse(c, Set()).filter(namePred).toSeq + ).map { name => Resolved.Target(Segments.labels(name)) -> None } - val commands = Reflect - .reflect(cls, classOf[Command[_]], namePred, noParams = false) - .map(m => decode(m.getName)) - .map { name => Resolved.Command(Segments.labels(name)) -> None } + val commands = findFromParents( + cls, + c => baseModules.commandNamesByClass.getOrElse(c, Set()).filter(namePred).toSeq + ).map { name => Resolved.Command(Segments.labels(name)) -> None } modulesOrErr.map(_ ++ targets ++ commands) } + def findFromParents[T]( + c: Class[_], + target: Class[_] => Seq[T], + seen: collection.mutable.Set[Class[_]] = collection.mutable.Set() + ): Seq[T] = { + if (seen(c)) Nil + else { + seen.add(c) + + target(c) ++ + (Option(c.getSuperclass).iterator ++ c.getInterfaces) + .flatMap(findFromParents(_, target, seen)) + .toSeq + } + } + def notFoundResult( baseModules: BaseModuleTree, querySoFar: Segments, diff --git a/main/resolve/src/mill/resolve/SimpleTaskTokenReader.scala b/main/resolve/src/mill/resolve/SimpleTaskTokenReader.scala index d1ee46a5bdc..8b7de21b56b 100644 --- a/main/resolve/src/mill/resolve/SimpleTaskTokenReader.scala +++ b/main/resolve/src/mill/resolve/SimpleTaskTokenReader.scala @@ -4,7 +4,7 @@ import mainargs.TokensReader import mill.define.{Target, Task} /** - * Transparently handle `Task[T]` like simple `T` but lift the result into a T.task. + * Transparently handle `Task[T]` like simple `T` but lift the result into a Task.anon. */ class SimpleTaskTokenReader[T](tokensReaderOfT: TokensReader.Simple[T]) extends mainargs.TokensReader.Simple[Task[T]] { diff --git a/main/resolve/test/src/mill/main/ResolveTests.scala b/main/resolve/test/src/mill/main/ResolveTests.scala index 309fecfa2cc..9f71d116bcb 100644 --- a/main/resolve/test/src/mill/main/ResolveTests.scala +++ b/main/resolve/test/src/mill/main/ResolveTests.scala @@ -1,6 +1,6 @@ package mill.resolve -import mill.define.NamedTask +import mill.define.Task import mill.util.TestGraphs import mill.util.TestGraphs._ import utest._ @@ -10,13 +10,13 @@ object ResolveTests extends TestSuite { def apply( selectorString: String, - expected0: Either[String, Set[T => NamedTask[_]]], + expected0: Either[String, Set[T => Task[_]]], expectedMetadata: Set[String] = Set() ) = checkSeq(Seq(selectorString), expected0, expectedMetadata) def checkSeq( selectorStrings: Seq[String], - expected0: Either[String, Set[T => NamedTask[_]]], + expected0: Either[String, Set[T => Task[_]]], expectedMetadata: Set[String] = Set() ) = { val expected = expected0.map(_.map(_(module))) @@ -37,7 +37,7 @@ object ResolveTests extends TestSuite { def checkSeq0( selectorStrings: Seq[String], - check: Either[String, List[NamedTask[_]]] => Boolean, + check: Either[String, List[Task[_]]] => Boolean, checkMetadata: Either[String, List[String]] => Boolean = _ => true ) = { @@ -69,8 +69,14 @@ object ResolveTests extends TestSuite { x.left.exists(_.contains(s)) && // Make sure the stack traces are truncated and short-ish, and do not // contain the entire Mill internal call stack at point of failure - x.left.exists(_.linesIterator.size < 20) + x.left.exists(_.linesIterator.size < 25) + def segments( + found: Either[String, List[Task[_]]], + expected: Either[String, List[Task[_]]] + ) = { + found.map(_.map(_.ctx.segments)) == expected.map(_.map(_.ctx.segments)) + } val tests = Tests { val graphs = new mill.util.TestGraphs() import graphs._ @@ -114,7 +120,7 @@ object ResolveTests extends TestSuite { ) "neg5" - check( "invisible", - Left("Cannot resolve invisible. Try `mill resolve _` to see what's available.") + Left("Cannot resolve invisible. Did you mean invisible&?") ) "negBadParse" - check( "invisible&", @@ -134,6 +140,7 @@ object ResolveTests extends TestSuite { ) } } + "nested" - { val check = new Checker(nestedModule) "pos1" - check("single", Right(Set(_.single)), Set("single")) @@ -197,7 +204,9 @@ object ResolveTests extends TestSuite { ) "wildcardNeg" - check( "_._.single", - Left("Cannot resolve _._.single. Try `mill resolve _` to see what's available.") + Left( + "Cannot resolve _._.single. Try `mill resolve _` or `mill resolve __.single` to see what's available." + ) ) "wildcardNeg2" - check( "_._.__", @@ -259,6 +268,38 @@ object ResolveTests extends TestSuite { ) } + "commands" - { + val check = new Checker(commands) + "pos1" - check.checkSeq0( + Seq("outerCmd"), + segments(_, Right(List(commands.outerCmd()))), + _ == Right(List("outerCmd")) + ) + "pos2" - check.checkSeq0( + Seq("inner.innerCmd"), + segments(_, Right(List(commands.inner.innerCmd()))), + _ == Right(List("inner.innerCmd")) + ) + "neg1" - check( + "innerCmd", + Left( + "Cannot resolve innerCmd. Try `mill resolve _` or `mill resolve __.innerCmd` to see what's available." + ) + ) + "neg2" - check( + "outerCm", + Left("Cannot resolve outerCm. Did you mean outerCmd?") + ) + } + + "commandLooksLikeTarget" - { + val check = new Checker(commandLooksLikeTarget) + check.checkSeq0( + Seq("sngle"), + segments(_, Right(List(commandLooksLikeTarget.sngle()))) + ) + } + "cross" - { "single" - { val check = new Checker(singleCross) @@ -296,7 +337,7 @@ object ResolveTests extends TestSuite { "neg4" - check( "cross[doesntExist].suffix", Left( - "Cannot resolve cross[doesntExist].suffix. Try `mill resolve cross._` to see what's available." + "Cannot resolve cross[doesntExist].suffix. Try `mill resolve cross._` or `mill resolve __.suffix` to see what's available." ) ) "wildcard" - check( @@ -346,7 +387,9 @@ object ResolveTests extends TestSuite { "wildcard" - { "labelNeg1" - check( "_.suffix", - Left("Cannot resolve _.suffix. Try `mill resolve _._` to see what's available.") + Left( + "Cannot resolve _.suffix. Try `mill resolve _._` or `mill resolve __.suffix` to see what's available." + ) ) "labelNeg2" - check( "_.doesntExist", @@ -594,13 +637,6 @@ object ResolveTests extends TestSuite { "duplicate" - { val check = new Checker(duplicates) - def segments( - found: Either[String, List[NamedTask[_]]], - expected: Either[String, List[NamedTask[_]]] - ) = { - found.map(_.map(_.ctx.segments)) == expected.map(_.map(_.ctx.segments)) - } - "wildcard" - { "wrapped" - { "targets" - check.checkSeq0( diff --git a/main/src/mill/main/MainModule.scala b/main/src/mill/main/MainModule.scala index e40a3e5df93..da134cdb14b 100644 --- a/main/src/mill/main/MainModule.scala +++ b/main/src/mill/main/MainModule.scala @@ -120,7 +120,7 @@ trait MainModule extends BaseModule0 { } /** - * Prints out some dependency path from the `src` task to the `dest` task. + * Prints out some dependency path from the `src` task to the `dest` Task. * * If there are multiple dependency paths between `src` and `dest`, the path * chosen is arbitrary. diff --git a/main/src/mill/main/TokenReaders.scala b/main/src/mill/main/TokenReaders.scala index d3c37219fa1..a889210da82 100644 --- a/main/src/mill/main/TokenReaders.scala +++ b/main/src/mill/main/TokenReaders.scala @@ -6,7 +6,7 @@ import mill.define.{Args, Target, Task} import mill.resolve.{Resolve, SelectMode} import mill.resolve.SimpleTaskTokenReader -case class Tasks[T](value: Seq[mill.define.NamedTask[T]]) +case class Tasks[T](value: Seq[mill.define.Task[T]]) object Tasks { private[main] class TokenReader[T]() extends mainargs.TokensReader.Simple[Tasks[T]] { diff --git a/main/src/mill/main/VisualizeModule.scala b/main/src/mill/main/VisualizeModule.scala index c2e8e274ce3..3ee60e89d0c 100644 --- a/main/src/mill/main/VisualizeModule.scala +++ b/main/src/mill/main/VisualizeModule.scala @@ -18,12 +18,12 @@ object VisualizeModule extends ExternalModule with VisualizeModule { MavenRepository("https://oss.sonatype.org/content/repositories/releases") ) - lazy val millDiscover: Discover[this.type] = Discover[this.type] + val millDiscover: Discover[this.type] = Discover[this.type] } trait VisualizeModule extends mill.define.TaskModule { def repositories: Seq[Repository] def defaultCommandName() = "run" - def classpath: Target[Loose.Agg[PathRef]] = Target { + def classpath: mill.define.Task[Loose.Agg[PathRef]] = Target { millProjectModule("mill-main-graphviz", repositories) } diff --git a/main/src/mill/package.scala b/main/src/mill/package.scala index 071f608e5ec..bad0f9cfe84 100644 --- a/main/src/mill/package.scala +++ b/main/src/mill/package.scala @@ -1,8 +1,10 @@ package object mill extends mill.api.JsonFormatters { - val T = define.Target - type T[+T] = define.Target[T] - val Target = define.Target - type Target[+T] = define.Target[T] + @deprecated("Use Task.*", "0.12.0") + val T = define.Task + type T[+T] = define.Task[T] + + val Target = define.Task + type Target[+T] = define.Task[T] val PathRef = mill.api.PathRef type PathRef = mill.api.PathRef type Module = define.Module @@ -20,10 +22,10 @@ package object mill extends mill.api.JsonFormatters { type Command[+T] = define.Command[T] type Worker[+T] = define.Worker[T] - type Input[T] = define.Target[T] - type Persistent[T] = define.Target[T] - type Source = define.Target[mill.api.PathRef] - type Sources = define.Target[Seq[mill.api.PathRef]] + type Input[T] = define.Task[T] + type Persistent[T] = define.Task[T] + type Source = define.Task[mill.api.PathRef] + type Sources = define.Task[Seq[mill.api.PathRef]] type TaskModule = define.TaskModule } diff --git a/main/test/src/mill/main/MainModuleTests.scala b/main/test/src/mill/main/MainModuleTests.scala index d504d7c78c7..456d5391fe1 100644 --- a/main/test/src/mill/main/MainModuleTests.scala +++ b/main/test/src/mill/main/MainModuleTests.scala @@ -1,7 +1,7 @@ package mill.main import mill.api.{PathRef, Result, Val} -import mill.{Agg, T} +import mill.Agg import mill.define.{Cross, Discover, Module, Task} import mill.util.{TestEvaluator, TestUtil} import utest.{TestSuite, Tests, assert, test} @@ -11,30 +11,30 @@ import java.io.{ByteArrayOutputStream, PrintStream} object MainModuleTests extends TestSuite { object mainModule extends TestUtil.BaseModule with MainModule { - def hello = T { + def hello = Task { System.out.println("Hello System Stdout") System.err.println("Hello System Stderr") Console.out.println("Hello Console Stdout") Console.err.println("Hello Console Stderr") Seq("hello", "world") } - def hello2 = T { + def hello2 = Task { System.out.println("Hello2 System Stdout") System.err.println("Hello2 System Stderr") Console.out.println("Hello2 Console Stdout") Console.err.println("Hello2 Console Stderr") Map("1" -> "hello", "2" -> "world") } - def helloCommand(x: Int, y: Task[String]) = T.command { (x, y(), hello()) } - override lazy val millDiscover: Discover[this.type] = Discover[this.type] + def helloCommand(x: Int, y: Task[String]) = Task.command { (x, y(), hello()) } + override val millDiscover: Discover[this.type] = Discover[this.type] } object cleanModule extends TestUtil.BaseModule with MainModule { trait Cleanable extends Module { - def target = T { - os.write(T.dest / "dummy.txt", "dummy text") - Seq(PathRef(T.dest)) + def target = Task { + os.write(Task.dest / "dummy.txt", "dummy text") + Seq(PathRef(Task.dest)) } } @@ -42,21 +42,23 @@ object MainModuleTests extends TestSuite { object sub extends Cleanable } object bar extends Cleanable { - override def target = T { - os.write(T.dest / "dummy.txt", "dummy text") - super.target() ++ Seq(PathRef(T.dest)) + override def target = Task { + os.write(Task.dest / "dummy.txt", "dummy text") + super.target() ++ Seq(PathRef(Task.dest)) } } object bazz extends Cross[Bazz]("1", "2", "3") trait Bazz extends Cleanable with Cross.Module[String] - def all = T { + def all = Task { foo.target() bar.target() bazz("1").target() bazz("2").target() bazz("3").target() } + + val millDiscover: Discover[this.type] = Discover[this.type] } override def tests: Tests = Tests { diff --git a/main/test/src/mill/util/TestGraphs.scala b/main/test/src/mill/util/TestGraphs.scala index dd92bd3d9b3..e46a05f9325 100644 --- a/main/test/src/mill/util/TestGraphs.scala +++ b/main/test/src/mill/util/TestGraphs.scala @@ -1,7 +1,7 @@ package mill.util import TestUtil.test import mill.define.{Command, Cross, Discover, DynamicModule, ModuleRef, TaskModule} -import mill.{Module, T} +import mill.{Module, T, Task} /** * Example dependency graphs for us to use in our test suite. @@ -15,9 +15,10 @@ import mill.{Module, T} * live in the companion object. */ class TestGraphs() { - // single object singleton extends TestUtil.BaseModule { val single = test() + + val millDiscover: Discover[this.type] = Discover[this.type] } object bactickIdentifiers extends TestUtil.BaseModule { @@ -27,18 +28,24 @@ class TestGraphs() { object `nested-module` extends Module { val `nested-target` = test() } + + val millDiscover: Discover[this.type] = Discover[this.type] } // up---down object pair extends TestUtil.BaseModule { val up = test() val down = test(up) + + val millDiscover: Discover[this.type] = Discover[this.type] } // up---o---down object anonTriple extends TestUtil.BaseModule { val up = test() val down = test(test.anon(up)) + + val millDiscover: Discover[this.type] = Discover[this.type] } // left @@ -51,6 +58,8 @@ class TestGraphs() { val left = test(up) val right = test(up) val down = test(left, right) + + val millDiscover: Discover[this.type] = Discover[this.type] } // o @@ -61,13 +70,17 @@ class TestGraphs() { object anonDiamond extends TestUtil.BaseModule { val up = test() val down = test(test.anon(up), test.anon(up)) + + val millDiscover: Discover[this.type] = Discover[this.type] } object defCachedDiamond extends TestUtil.BaseModule { - def up = T { test() } - def left = T { test(up) } - def right = T { test(up) } - def down = T { test(left, right) } + def up = Task.ofTask { test() } + def left = Task.ofTask { test(up) } + def right = Task.ofTask { test(up) } + def down = Task.ofTask { test(left, right) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object borkedCachedDiamond2 extends TestUtil.BaseModule { @@ -75,6 +88,8 @@ class TestGraphs() { def left = test(up) def right = test(up) def down = test(left, right) + + val millDiscover: Discover[this.type] = Discover[this.type] } object borkedCachedDiamond3 extends TestUtil.BaseModule { @@ -82,6 +97,8 @@ class TestGraphs() { def left = test(up) def right = test(up) def down = test(left, right) + + val millDiscover: Discover[this.type] = Discover[this.type] } // o g-----o @@ -114,6 +131,8 @@ class TestGraphs() { test(test.anon(g), test.anon(test.anon(h))) } val j = test(test.anon(i), test.anon(i, f), test.anon(f)) + + val millDiscover: Discover[this.type] = Discover[this.type] } // _ left _ // / \ @@ -121,58 +140,59 @@ class TestGraphs() { // _/ // change - task2 object separateGroups extends TestUtil.BaseModule { - val task1 = T.task { 1 } - def left = T { task1() } + val task1 = Task.anon { 1 } + def left = Task { task1() } val change = test() - val task2 = T.task { change() } - def right = T { task1() + task2() + left() + 1 } + val task2 = Task.anon { change() } + def right = Task { task1() + task2() + left() + 1 } + val millDiscover: Discover[this.type] = Discover[this.type] } object moduleInitError extends TestUtil.BaseModule { - def rootTarget = T { println("Running rootTarget"); "rootTarget Result" } - def rootCommand(s: String) = T.command { println(s"Running rootCommand $s") } + def rootTarget = Task { println("Running rootTarget"); "rootTarget Result" } + def rootCommand(s: String) = Task.command { println(s"Running rootCommand $s") } object foo extends Module { - def fooTarget = T { println(s"Running fooTarget"); 123 } - def fooCommand(s: String) = T.command { println(s"Running fooCommand $s") } + def fooTarget = Task { println(s"Running fooTarget"); 123 } + def fooCommand(s: String) = Task.command { println(s"Running fooCommand $s") } throw new Exception("Foo Boom") } object bar extends Module { - def barTarget = T { println(s"Running barTarget"); "barTarget Result" } - def barCommand(s: String) = T.command { println(s"Running barCommand $s") } + def barTarget = Task { println(s"Running barTarget"); "barTarget Result" } + def barCommand(s: String) = Task.command { println(s"Running barCommand $s") } object qux extends Module { - def quxTarget = T { println(s"Running quxTarget"); "quxTarget Result" } - def quxCommand(s: String) = T.command { println(s"Running quxCommand $s") } + def quxTarget = Task { println(s"Running quxTarget"); "quxTarget Result" } + def quxCommand(s: String) = Task.command { println(s"Running quxCommand $s") } throw new Exception("Qux Boom") } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } object moduleDependencyInitError extends TestUtil.BaseModule { object foo extends Module { - def fooTarget = T { println(s"Running fooTarget"); 123 } - def fooCommand(s: String) = T.command { println(s"Running fooCommand $s") } + def fooTarget = Task { println(s"Running fooTarget"); 123 } + def fooCommand(s: String) = Task.command { println(s"Running fooCommand $s") } throw new Exception("Foo Boom") } object bar extends Module { - def barTarget = T { + def barTarget = Task { println(s"Running barTarget") s"${foo.fooTarget()} barTarget Result" } - def barCommand(s: String) = T.command { + def barCommand(s: String) = Task.command { foo.fooCommand(s)() println(s"Running barCommand $s") } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } object crossModuleSimpleInitError extends TestUtil.BaseModule { @@ -180,27 +200,27 @@ class TestGraphs() { throw new Exception(s"MyCross Boom") } trait MyCross extends Cross.Module[Int] { - def foo = T { crossValue } + def foo = Task { crossValue } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } object crossModulePartialInitError extends TestUtil.BaseModule { object myCross extends Cross[MyCross](1, 2, 3, 4) trait MyCross extends Cross.Module[Int] { if (crossValue > 2) throw new Exception(s"MyCross Boom $crossValue") - def foo = T { crossValue } + def foo = Task { crossValue } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } object crossModuleSelfInitError extends TestUtil.BaseModule { object myCross extends Cross[MyCross](1, 2, 3, throw new Exception(s"MyCross Boom")) trait MyCross extends Cross.Module[Int] { - def foo = T { crossValue } + def foo = Task { crossValue } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } object crossModuleParentInitError extends TestUtil.BaseModule { @@ -208,11 +228,11 @@ class TestGraphs() { throw new Exception(s"Parent Boom") object myCross extends Cross[MyCross](1, 2, 3, 4) trait MyCross extends Cross.Module[Int] { - def foo = T { crossValue } + def foo = Task { crossValue } } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } object overrideModule extends TestUtil.BaseModule { @@ -220,34 +240,34 @@ class TestGraphs() { lazy val inner: BaseInnerModule = new BaseInnerModule {} lazy val ignored: ModuleRef[BaseInnerModule] = ModuleRef(new BaseInnerModule {}) trait BaseInnerModule extends mill.define.Module { - def baseTarget = T { 1 } + def baseTarget = Task { 1 } } } object sub extends Base { override lazy val inner: SubInnerModule = new SubInnerModule {} override lazy val ignored: ModuleRef[SubInnerModule] = ModuleRef(new SubInnerModule {}) trait SubInnerModule extends BaseInnerModule { - def subTarget = T { 2 } + def subTarget = Task { 2 } } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } object dynamicModule extends TestUtil.BaseModule { object normal extends DynamicModule { object inner extends Module { - def target = T { 1 } + def target = Task { 1 } } } object niled extends DynamicModule { override def millModuleDirectChildren: Seq[Module] = Nil object inner extends Module { - def target = T { 1 } + def target = Task { 1 } } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } } @@ -256,147 +276,185 @@ object TestGraphs { // / \ // task -------- right object triangleTask extends TestUtil.BaseModule { - val task = T.task { 1 } - def left = T { task() } - def right = T { task() + left() + 1 } + val task = Task.anon { 1 } + def left = Task { task() } + def right = Task { task() + left() + 1 } + + val millDiscover: Discover[this.type] = Discover[this.type] } // _ left // / // task -------- right object multiTerminalGroup extends TestUtil.BaseModule { - val task = T.task { 1 } - def left = T { task() } - def right = T { task() } + val task = Task.anon { 1 } + def left = Task { task() } + def right = Task { task() } + + val millDiscover: Discover[this.type] = Discover[this.type] } // _ left _____________ // / \ \ // task1 -------- right ----- task2 object multiTerminalBoundary extends TestUtil.BaseModule { - val task1 = T.task { 1 } - def left = T { task1() } - def right = T { task1() + left() + 1 } - val task2 = T.task { left() + right() } + val task1 = Task.anon { 1 } + def left = Task { task1() } + def right = Task { task1() + left() + 1 } + val task2 = Task.anon { left() + right() } + + val millDiscover: Discover[this.type] = Discover[this.type] } trait CanNest extends Module { - def single = T { 1 } - def invisible: Any = T { 2 } - def invisible2: mill.define.Task[Int] = T { 3 } - def invisible3: mill.define.Task[_] = T { 4 } + def single = Task { 1 } + def invisible: Any = Task { 2 } + def visible2: mill.define.Task[Int] = Task { 3 } + def visible3: mill.define.Task[_] = Task { 4 } } object nestedModule extends TestUtil.BaseModule { - def single = T { 5 } - def invisible: Any = T { 6 } + def single = Task { 5 } + def invisible: Any = Task { 6 } object nested extends Module { - def single = T { 7 } - def invisible: Any = T { 8 } + def single = Task { 7 } + def invisible: Any = Task { 8 } } object classInstance extends CanNest + val millDiscover: Discover[this.type] = Discover[this.type] } object doubleNestedModule extends TestUtil.BaseModule { - def single = T { 5 } + def single = Task { 5 } object nested extends Module { - def single = T { 7 } + def single = Task { 7 } object inner extends Module { - def single = T { 9 } + def single = Task { 9 } } } + + val millDiscover: Discover[this.type] = Discover[this.type] + } + + object commands extends TestUtil.BaseModule { + def outerCmd() = Task.command {} + + object inner extends Module { + def innerCmd() = Task.command {} + } + + val millDiscover: Discover[this.type] = Discover[this.type] + } + + object commandLooksLikeTarget extends TestUtil.BaseModule { + // Make sure Mill doesn't get confused when the command `sngle` has the same + // name as a target `sngle`, and a target `sngle` exists elsewhere in the build + // graph, but there is no `sngle in the module being looked at + val single = test() + + def sngle() = Task.command {} + object foo extends Module { + val sngle = test() + } + + val millDiscover: Discover[this.type] = Discover[this.type] } trait BaseModule extends Module { - def foo = T { Seq("base") } - def cmd(i: Int) = T.command { Seq("base" + i) } + def foo = Task { Seq("base") } + def cmd(i: Int) = Task.command { Seq("base" + i) } } object canOverrideSuper extends TestUtil.BaseModule with BaseModule { - override def foo = T { super.foo() ++ Seq("object") } - override def cmd(i: Int) = T.command { super.cmd(i)() ++ Seq("object" + i) } - override lazy val millDiscover: Discover[this.type] = Discover[this.type] + override def foo = Task { super.foo() ++ Seq("object") } + override def cmd(i: Int) = Task.command { super.cmd(i)() ++ Seq("object" + i) } + override val millDiscover: Discover[this.type] = Discover[this.type] } trait TraitWithModule extends Module { outer => object TraitModule extends Module { - def testFrameworks = T { Seq("mill.UTestFramework") } - def test() = T.command { () /*donothing*/ } + def testFrameworks = Task { Seq("mill.UTestFramework") } + def test() = Task.command { () /*donothing*/ } } } // Make sure nested objects inherited from traits work object TraitWithModuleObject extends TestUtil.BaseModule with TraitWithModule { - override lazy val millDiscover: Discover[this.type] = Discover[this.type] + override val millDiscover: Discover[this.type] = Discover[this.type] } object nullTasks extends TestUtil.BaseModule { val nullString: String = null - def nullTask1 = T.task { nullString } - def nullTask2 = T.task { nullTask1() } + def nullTask1 = Task.anon { nullString } + def nullTask2 = Task.anon { nullTask1() } - def nullTarget1 = T { nullString } - def nullTarget2 = T { nullTarget1() } - def nullTarget3 = T { nullTask1() } - def nullTarget4 = T { nullTask2() } + def nullTarget1 = Task { nullString } + def nullTarget2 = Task { nullTarget1() } + def nullTarget3 = Task { nullTask1() } + def nullTarget4 = Task { nullTask2() } - def nullCommand1() = T.command { nullString } - def nullCommand2() = T.command { nullTarget1() } - def nullCommand3() = T.command { nullTask1() } - def nullCommand4() = T.command { nullTask2() } + def nullCommand1() = Task.command { nullString } + def nullCommand2() = Task.command { nullTarget1() } + def nullCommand3() = Task.command { nullTask1() } + def nullCommand4() = Task.command { nullTask2() } - override lazy val millDiscover: Discover[this.type] = Discover[this.type] + override val millDiscover: Discover[this.type] = Discover[this.type] } object duplicates extends TestUtil.BaseModule { object wrapper extends Module { object test1 extends Module { - def test1 = T {} + def test1 = Task {} } object test2 extends TaskModule { override def defaultCommandName() = "test2" - def test2() = T.command {} + def test2() = Task.command {} } } object test3 extends Module { - def test3 = T {} + def test3 = Task {} } object test4 extends TaskModule { override def defaultCommandName() = "test4" - def test4() = T.command {} + def test4() = Task.command {} } - override lazy val millDiscover: Discover[this.type] = Discover[this.type] + + override val millDiscover: Discover[this.type] = Discover[this.type] } object singleCross extends TestUtil.BaseModule { object cross extends mill.Cross[Cross]("210", "211", "212") trait Cross extends Cross.Module[String] { - def suffix = T { crossValue } + def suffix = Task { crossValue } } object cross2 extends mill.Cross[Cross2]("210", "211", "212") trait Cross2 extends Cross.Module[String] { override def millSourcePath = super.millSourcePath / crossValue - def suffix = T { crossValue } + def suffix = Task { crossValue } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object nonStringCross extends TestUtil.BaseModule { object cross extends mill.Cross[Cross](210, 211, 212) trait Cross extends Cross.Module[Int] { - def suffix = T { crossValue } + def suffix = Task { crossValue } } object cross2 extends mill.Cross[Cross2](210L, 211L, 212L) trait Cross2 extends Cross.Module[Long] { override def millSourcePath = super.millSourcePath / crossValue.toString - def suffix = T { crossValue } + def suffix = Task { crossValue } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object crossResolved extends TestUtil.BaseModule { @@ -408,13 +466,15 @@ object TestGraphs { object foo extends mill.Cross[FooModule]("2.10", "2.11", "2.12") trait FooModule extends MyModule { - def suffix = T { crossValue } + def suffix = Task { crossValue } } object bar extends mill.Cross[BarModule]("2.10", "2.11", "2.12") trait BarModule extends MyModule { - def longSuffix = T { "_" + foo().suffix() } + def longSuffix = Task { "_" + foo().suffix() } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object doubleCross extends TestUtil.BaseModule { val crossMatrix = for { @@ -425,66 +485,72 @@ object TestGraphs { object cross extends mill.Cross[Cross](crossMatrix) trait Cross extends Cross.Module2[String, String] { val (scalaVersion, platform) = (crossValue, crossValue2) - def suffix = T { scalaVersion + "_" + platform } + def suffix = Task { scalaVersion + "_" + platform } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object crossExtension extends TestUtil.BaseModule { object myCross extends Cross[MyCrossModule]("a", "b") trait MyCrossModule extends Cross.Module[String] { - def param1 = T { "Param Value: " + crossValue } + def param1 = Task { "Param Value: " + crossValue } } object myCrossExtended extends Cross[MyCrossModuleExtended](("a", 1), ("b", 2)) trait MyCrossModuleExtended extends MyCrossModule with Cross.Module2[String, Int] { - def param2 = T { "Param Value: " + crossValue2 } + def param2 = Task { "Param Value: " + crossValue2 } } object myCrossExtendedAgain extends Cross[MyCrossModuleExtendedAgain](("a", 1, true), ("b", 2, false)) trait MyCrossModuleExtendedAgain extends MyCrossModuleExtended with Cross.Module3[String, Int, Boolean] { - def param3 = T { "Param Value: " + crossValue3 } + def param3 = Task { "Param Value: " + crossValue3 } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object innerCrossModule extends TestUtil.BaseModule { object myCross extends Cross[MyCrossModule]("a", "b") trait MyCrossModule extends Cross.Module[String] { object foo extends CrossValue { - def bar = T { "foo " + crossValue } + def bar = Task { "foo " + crossValue } } object baz extends CrossValue { - def bar = T { "baz " + crossValue } + def bar = Task { "baz " + crossValue } } } object myCross2 extends Cross[MyCrossModule2](("a", 1), ("b", 2)) trait MyCrossModule2 extends Cross.Module2[String, Int] { object foo extends InnerCrossModule2 { - def bar = T { "foo " + crossValue } - def qux = T { "foo " + crossValue2 } + def bar = Task { "foo " + crossValue } + def qux = Task { "foo " + crossValue2 } } object baz extends InnerCrossModule2 { - def bar = T { "baz " + crossValue } - def qux = T { "baz " + crossValue2 } + def bar = Task { "baz " + crossValue } + def qux = Task { "baz " + crossValue2 } } } object myCross3 extends Cross[MyCrossModule3](("a", 1, true), ("b", 2, false)) trait MyCrossModule3 extends Cross.Module3[String, Int, Boolean] { object foo extends InnerCrossModule3 { - def bar = T { "foo " + crossValue } - def qux = T { "foo " + crossValue2 } - def lol = T { "foo " + crossValue3 } + def bar = Task { "foo " + crossValue } + def qux = Task { "foo " + crossValue2 } + def lol = Task { "foo " + crossValue3 } } object baz extends InnerCrossModule3 { - def bar = T { "baz " + crossValue } - def qux = T { "baz " + crossValue2 } - def lol = T { "baz " + crossValue3 } + def bar = Task { "baz " + crossValue } + def qux = Task { "baz " + crossValue2 } + def lol = Task { "baz " + crossValue3 } } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object nestedCrosses extends TestUtil.BaseModule { @@ -496,15 +562,15 @@ object TestGraphs { object cross2 extends mill.Cross[Cross]("jvm", "js", "native") trait Cross extends Cross.Module[String] { val platform = crossValue - def suffix = T { scalaVersion + "_" + platform } + def suffix = Task { scalaVersion + "_" + platform } } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object nestedTaskCrosses extends TestUtil.BaseModule { - // this is somehow necessary to let Discover see our inner (default) commands - // I expected, that the identical inherited `millDiscover` is enough, but it isn't - override lazy val millDiscover: Discover[this.type] = Discover[this.type] + override val millDiscover: Discover[this.type] = Discover[this.type] object cross1 extends mill.Cross[Cross1]("210", "211", "212") trait Cross1 extends mill.Cross.Module[String] { def scalaVersion = crossValue @@ -513,7 +579,7 @@ object TestGraphs { trait Cross2 extends mill.Cross.Module[String] with TaskModule { def platform = crossValue override def defaultCommandName(): String = "suffixCmd" - def suffixCmd(suffix: String = "default"): Command[String] = T.command { + def suffixCmd(suffix: String = "default"): Command[String] = Task.command { scalaVersion + "_" + platform + "_" + suffix } } @@ -523,39 +589,43 @@ object TestGraphs { object StackableOverrides extends TestUtil.BaseModule { trait X extends Module { - def f = T { 1 } + def f = Task { 1 } } trait A extends X { - override def f = T { super.f() + 2 } + override def f = Task { super.f() + 2 } } trait B extends X { - override def f = T { super.f() + 3 } + override def f = Task { super.f() + 3 } } object m extends A with B {} + + val millDiscover: Discover[this.type] = Discover[this.type] } object PrivateTasksInMixedTraits extends TestUtil.BaseModule { trait M1 extends Module { - private def foo = T { "foo-m1" } - def bar = T { foo() } + private def foo = Task { "foo-m1" } + def bar = Task { foo() } } trait M2 extends Module { - private def foo = T { "foo-m2" } - def baz = T { foo() } + private def foo = Task { "foo-m2" } + def baz = Task { foo() } } object mod extends M1 with M2 + + val millDiscover: Discover[this.type] = Discover[this.type] } object TypedModules extends TestUtil.BaseModule { trait TypeA extends Module { - def foo = T { "foo" } + def foo = Task { "foo" } } trait TypeB extends Module { - def bar = T { "bar" } + def bar = Task { "bar" } } trait TypeC extends Module { - def baz = T { "baz" } + def baz = Task { "baz" } } trait TypeAB extends TypeA with TypeB @@ -565,15 +635,17 @@ object TestGraphs { object typeA extends TypeA } object typeAB extends TypeAB + + val millDiscover: Discover[this.type] = Discover[this.type] } object TypedCrossModules extends TestUtil.BaseModule { trait TypeA extends Cross.Module[String] { - def foo = T { crossValue } + def foo = Task { crossValue } } trait TypeB extends Module { - def bar = T { "bar" } + def bar = Task { "bar" } } trait TypeAB extends TypeA with TypeB @@ -590,22 +662,26 @@ object TestGraphs { object typeAB extends Cross[TypeAB]("a", "b") } object nestedAB extends Cross[NestedAB]("a", "b") + + val millDiscover: Discover[this.type] = Discover[this.type] } object TypedInnerModules extends TestUtil.BaseModule { trait TypeA extends Module { - def foo = T { "foo" } + def foo = Task { "foo" } } object typeA extends TypeA object typeB extends Module { - def foo = T { "foo" } + def foo = Task { "foo" } } object inner extends Module { trait TypeA extends Module { - def foo = T { "foo" } + def foo = Task { "foo" } } object typeA extends TypeA } + + val millDiscover: Discover[this.type] = Discover[this.type] } object AbstractModule extends TestUtil.BaseModule { @@ -618,13 +694,14 @@ object TestGraphs { override lazy val tests: ConcreteTests = new ConcreteTests {} trait ConcreteTests extends Tests { object inner extends Module { - def foo = T { "foo" } + def foo = Task { "foo" } object innerer extends Module { - def bar = T { "bar" } + def bar = Task { "bar" } } } } } - } + val millDiscover: Discover[this.type] = Discover[this.type] + } } diff --git a/main/test/src/mill/util/TestUtil.scala b/main/test/src/mill/util/TestUtil.scala index 76278e2fed6..820b7c02b52 100644 --- a/main/test/src/mill/util/TestUtil.scala +++ b/main/test/src/mill/util/TestUtil.scala @@ -24,8 +24,11 @@ object TestUtil extends MillTestKit { object test { def anon(inputs: Task[Int]*): Test = new Test(inputs) - def apply(inputs: Task[Int]*)(implicit ctx: mill.define.Ctx): TestTarget = { - new TestTarget(inputs, pure = inputs.nonEmpty) + def apply(inputs: Task[Int]*)(implicit + ctx: mill.define.Ctx, + name: sourcecode.Name + ): TestTarget = { + new TestTarget(inputs, pure = inputs.nonEmpty, name = name.value) } } @@ -46,8 +49,9 @@ object TestUtil extends MillTestKit { * controlled externally, so you can construct arbitrary dataflow graphs and * test how changes propagate. */ - class TestTarget(taskInputs: Seq[Task[Int]], val pure: Boolean)(implicit ctx0: mill.define.Ctx) - extends TargetImpl[Int]( + class TestTarget(taskInputs: Seq[Task[Int]], val pure: Boolean, val name: String)(implicit + ctx0: mill.define.Ctx + ) extends TargetImpl[Int]( null, ctx0, upickle.default.readwriter[Int], @@ -64,6 +68,11 @@ object TestUtil extends MillTestKit { def exception = testTask.exception override def sideHash = testTask.sideHash + override def hashCode() = name.hashCode() + override def equals(o: Any) = o match { + case o: TestTarget => name == o.name + case _ => false + } } def checkTopological(targets: Agg[Task[_]]) = { diff --git a/main/testkit/src/mill/testkit/MillTestkit.scala b/main/testkit/src/mill/testkit/MillTestkit.scala index 7dea683d357..7dcb6408102 100644 --- a/main/testkit/src/mill/testkit/MillTestkit.scala +++ b/main/testkit/src/mill/testkit/MillTestkit.scala @@ -1,7 +1,7 @@ package mill.testkit import mill._ -import mill.define.{Caller, Discover, InputImpl, TargetImpl} +import mill.define.{Caller, InputImpl, TargetImpl} import mill.api.{DummyInputStream, Result, SystemStreams, Val} import mill.api.Result.OuterStack import mill.api.Strict.Agg @@ -41,7 +41,7 @@ trait MillTestKit { targetDir / "worksources" } - class BaseModule(implicit + abstract class BaseModule(implicit millModuleEnclosing0: sourcecode.Enclosing, millModuleLine0: sourcecode.Line ) extends mill.define.BaseModule(getSrcPathBase() / millModuleEnclosing0.value.split("\\.| |#"))( @@ -49,9 +49,7 @@ trait MillTestKit { implicitly, implicitly, Caller(null) - ) { - lazy val millDiscover: Discover[this.type] = Discover[this.type] - } + ) {} /** * @param module The module under test diff --git a/main/testkit/test/src/mill/testkit/MillTestKitSuite.scala b/main/testkit/test/src/mill/testkit/MillTestKitSuite.scala index ca9aa7b5ba5..9cbd4e38225 100644 --- a/main/testkit/test/src/mill/testkit/MillTestKitSuite.scala +++ b/main/testkit/test/src/mill/testkit/MillTestKitSuite.scala @@ -2,6 +2,7 @@ package mill.testkit import mill.testkit.MillTestKit import mill._ +import mill.define.Discover import utest._ object MillTestKitSuite extends TestSuite { @@ -12,6 +13,8 @@ object MillTestKitSuite extends TestSuite { object build extends testKit.BaseModule { def testTask = T("test") + + val millDiscover: Discover[this.type] = Discover[this.type] } def tests: Tests = Tests { diff --git a/readme.adoc b/readme.adoc index 8a4fc025778..0605ff06326 100644 --- a/readme.adoc +++ b/readme.adoc @@ -483,7 +483,7 @@ __New features__ __Fixes and Improvements__ * Better detect Windows Subsystem for Linux environments {link-pr}/2901[#2901] -* Avoid evaluating `T.input`s twice {link-pr}/2952[#2952] +* Avoid evaluating `Task.input`s twice {link-pr}/2952[#2952] * Deduplicate (anonymous) tasks in results {link-pr}/2959[#2959] * Synchronize `evaluateGroupCached` to avoid concurrent access to cache {link-pr}/2980[#2980] * Properly sanitize Windows reserved names and symbols in evaluator paths {link-pr}/2964[#2964], {link-pr}/2965[#2965] @@ -558,7 +558,7 @@ _Changes since {prev-version}:_ * Various BSP improvements {link-pr}/2814[#2814], {link-pr}/2813[#2813], {link-pr}/2810[#2810], {link-pr}/2771[#2771] -* The `T.workspace` context path now always points to the top-level project directory, also for meta builds {link-pr}/2809[#2809] +* The `Task.workspace` context path now always points to the top-level project directory, also for meta builds {link-pr}/2809[#2809] * Mill now better detects and reports logical cycles in inter-module dependencies {link-pr}/2790[#2790] @@ -782,7 +782,7 @@ It is now significantly lazier, resulting in less of the module tree being un-ne `run` to be easily used in the implementation of other tasks {link-pr}/2452[#2452] -* ``T.input``s are now watched properly with `--watch`, and trigger re-evaluations when the watched value changes {link-pr}/2489[#2489] +* ``Task.input``s are now watched properly with `--watch`, and trigger re-evaluations when the watched value changes {link-pr}/2489[#2489] * Support for Java 20 {link-pr}/2501[#2501] @@ -797,7 +797,7 @@ It is now significantly lazier, resulting in less of the module tree being un-ne * Enabled compilation warnings in `build.sc` {link-pr}/2519[#2519] -* Print out the CLI flags when inspecting ``T.command``s +* Print out the CLI flags when inspecting ``Task.command``s {link-pr}/2522[#2522] _For details refer to @@ -823,7 +823,7 @@ folder in the Mill repo, containing common build setups demonstrating Mill featu * Add some helpers to simplify cross-version/cross-platform modules {#2406}[{link-pr}/2406] -* You can now override `T{...}` ``Target``s with `T.source` or `T.sources`, and vice versa {link-pr}/2402[#2402] +* You can now override `Task {...}` ``Target``s with `Task.source` or `Task.sources`, and vice versa {link-pr}/2402[#2402] * Removed the Ammonite script runner dependency used to evaluate `build.sc` files and instead compile them using Mill {link-pr}/2377[#2377] @@ -1112,7 +1112,7 @@ _Changes since {prev-version}:_ * Lots of documentation improvements, additions and restructurings * `core`: Fixed some rare issues with reading the `.mill-jvm-opts` file -* `core`: We made slight adaptions to the `T.dest` location of target defined in included files, to fix potential colliding cache locations +* `core`: We made slight adaptions to the `Task.dest` location of target defined in included files, to fix potential colliding cache locations * `scalalib`: JAR archives created by Mill now by default contain directory entries * `scalalib`: Updated zinc to 1.8.0 * `scalajslib`: Added support for more `JsEnv` providers @@ -1421,7 +1421,7 @@ _Changes since {prev-version}:_ * Coursier: we now implemented a workaround to tackle concurrent downloads issues * New `+` separator to provide multiple targets (with parameters) via cmdline * New `--import` cmdline option to run ad-hoc plugins without editing of `build.sc` -* New `T.ctx().workspace` API to access the project root directory +* New `Task.ctx().workspace` API to access the project root directory * Various internal improvements and bug fixes * Various refactorings and cleanups @@ -1719,7 +1719,7 @@ and the {link-compare}/0.7.0\...0.7.1[list of commits]._ * `build.sc` files now uses Scala 2.13.2 * Avoid duplicate target resolution with `mill resolve __` * Add ability to pass GPG arguments to publish via `--gpgArgs` -* `-w`/`--watch` now works for `T.source` targets +* `-w`/`--watch` now works for `Task.source` targets _For details refer to {link-milestone}/37?closed=1[milestone 0.7.0] and the {link-compare}/0.6.3\...0.7.0[list of commits]._ @@ -1789,7 +1789,7 @@ and the {link-compare}/0.5.9\...0.6.0[list of commits]._ === 0.5.9 - 2020-01-14 * Bump library versions again -* Alias `T.ctx.*` functions to `T.*`: `T.dest`, `T.log`, etc. +* Alias `Task.ctx.*` functions to `Task.*`: `Task.dest`, `Task.log`, etc. * Bump Mill's client-connect-to-server timeout, to reduce flakiness when the server is taking a moment to start up _For details refer to the {link-compare}/0.5.7\...0.5.9[list of commits]._ @@ -1975,7 +1975,7 @@ https://github.com/lihaoyi/requests-scala[Requests-Scala] available to use in yo [#0-2-8] === 0.2.8 - 2018-09-21 -* `mill inspect` now displays out the doc-comment documentation for a task. +* `mill inspect` now displays out the doc-comment documentation for a Task. * Avoid shutdown hook failures in tests {link-pr}/422[#422] diff --git a/runner/src/mill/runner/MillBuild.scala b/runner/src/mill/runner/MillBuild.scala index 5bbeba1c3c7..a7110d58862 100644 --- a/runner/src/mill/runner/MillBuild.scala +++ b/runner/src/mill/runner/MillBuild.scala @@ -1,6 +1,6 @@ package mill.runner -import mill.T +import mill.{Task, T} import mill.define.{Command, Discover, ExternalModule, Module} import mill.eval.Evaluator.AllBootstrapEvaluators @@ -10,12 +10,12 @@ trait MillBuild extends Module { * Count of the nested build-levels, the main project and all its nested meta-builds. * If you run this on a meta-build, the non-meta-builds are not included. */ - def levelCount(evaluators: AllBootstrapEvaluators): Command[Int] = T.command { + def levelCount(evaluators: AllBootstrapEvaluators): Command[Int] = Task.command { evaluators.value.size } } object MillBuild extends ExternalModule with MillBuild { - override lazy val millDiscover: Discover[this.type] = Discover[this.type] + override val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/runner/src/mill/runner/MillBuildRootModule.scala b/runner/src/mill/runner/MillBuildRootModule.scala index dc8e8030476..1b2603da9df 100644 --- a/runner/src/mill/runner/MillBuildRootModule.scala +++ b/runner/src/mill/runner/MillBuildRootModule.scala @@ -153,7 +153,7 @@ class MillBuildRootModule()(implicit // graph evaluator without needing to be accounted for in the post-compile // bytecode callgraph analysis. def isSimpleTarget = - (calledSig.desc.ret.pretty == classOf[mill.define.Target[_]].getName || + (calledSig.desc.ret.pretty == classOf[mill.define.Task[_]].getName || calledSig.desc.ret.pretty == classOf[mill.define.Worker[_]].getName) && calledSig.desc.args.isEmpty @@ -230,7 +230,7 @@ class MillBuildRootModule()(implicit * By default, these are the dependencies, which Mill provides itself (via [[unmanagedClasspath]]). * We exclude them to avoid incompatible or duplicate artifacts on the classpath. */ - protected def resolveDepsExclusions: T[Seq[(String, String)]] = T { + def resolveDepsExclusions: Task[Seq[(String, String)]] = T { Lib.millAssemblyEmbeddedDeps.toSeq.map(d => (d.dep.module.organization.value, d.dep.module.name.value) ) diff --git a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala index 35514aee6f1..73b12709584 100644 --- a/scalajslib/src/mill/scalajslib/ScalaJSModule.scala +++ b/scalajslib/src/mill/scalajslib/ScalaJSModule.scala @@ -7,7 +7,7 @@ import mill.scalalib.api.ZincWorkerUtil import mill.scalalib.Lib.resolveDependencies import mill.scalalib.{CrossVersion, Dep, DepSyntax, Lib, TestModule} import mill.testrunner.{TestResult, TestRunner, TestRunnerUtils} -import mill.define.{Command, Target, Task} +import mill.define.{Command, Task} import mill.scalajslib.api._ import mill.scalajslib.internal.ScalaJSUtils.getReportMainFilePathRef import mill.scalajslib.worker.{ScalaJSWorker, ScalaJSWorkerExternalModule} @@ -20,22 +20,22 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => trait ScalaJSTests extends ScalaTests with TestScalaJSModule { override def scalaJSVersion = outer.scalaJSVersion() - override def moduleKind: Target[ModuleKind] = outer.moduleKind() - override def moduleSplitStyle: Target[ModuleSplitStyle] = outer.moduleSplitStyle() + override def moduleKind: Task[ModuleKind] = outer.moduleKind() + override def moduleSplitStyle: Task[ModuleSplitStyle] = outer.moduleSplitStyle() override def esFeatures = outer.esFeatures() - override def jsEnvConfig: Target[JsEnvConfig] = outer.jsEnvConfig() - override def scalaJSOptimizer: Target[Boolean] = outer.scalaJSOptimizer() + override def jsEnvConfig: Task[JsEnvConfig] = outer.jsEnvConfig() + override def scalaJSOptimizer: Task[Boolean] = outer.scalaJSOptimizer() } @deprecated("use ScalaJSTests", "0.11.0") type ScalaJSModuleTests = ScalaJSTests @deprecated("use ScalaJSTests", "0.11.0") trait Tests extends ScalaJSTests - def scalaJSBinaryVersion = T { ZincWorkerUtil.scalaJSBinaryVersion(scalaJSVersion()) } + def scalaJSBinaryVersion = Task { ZincWorkerUtil.scalaJSBinaryVersion(scalaJSVersion()) } - def scalaJSWorkerVersion = T { ZincWorkerUtil.scalaJSWorkerVersion(scalaJSVersion()) } + def scalaJSWorkerVersion = Task { ZincWorkerUtil.scalaJSWorkerVersion(scalaJSVersion()) } - override def scalaLibraryIvyDeps = T { + override def scalaLibraryIvyDeps: Task[Loose.Agg[Dep]] = Task { val deps = super.scalaLibraryIvyDeps() if (ZincWorkerUtil.isScala3(scalaVersion())) { // Since Dotty/Scala3, Scala.JS is published with a platform suffix @@ -49,7 +49,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => } else deps } - def scalaJSWorkerClasspath = T { + def scalaJSWorkerClasspath = Task { mill.util.Util.millProjectModule( artifact = s"mill-scalajslib-worker-${scalaJSWorkerVersion()}", repositories = repositoriesTask(), @@ -57,7 +57,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => ) } - def scalaJSJsEnvIvyDeps: Target[Agg[Dep]] = T { + def scalaJSJsEnvIvyDeps: Task[Agg[Dep]] = Task { val dep = jsEnvConfig() match { case _: JsEnvConfig.NodeJs => ivy"${ScalaJSBuildInfo.scalajsEnvNodejs}" @@ -74,7 +74,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => Agg(dep) } - def scalaJSLinkerClasspath: T[Loose.Agg[PathRef]] = T { + def scalaJSLinkerClasspath: T[Loose.Agg[PathRef]] = Task { val commonDeps = Seq( ivy"org.scala-js::scalajs-sbt-test-adapter:${scalaJSVersion()}" ) @@ -100,31 +100,31 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => repositoriesTask(), (commonDeps.iterator ++ envDeps ++ scalajsImportMapDeps) .map(Lib.depToBoundDep(_, mill.main.BuildInfo.scalaVersion, "")), - ctx = Some(T.log) + ctx = Some(Task.log) ) } - def scalaJSToolsClasspath = T { scalaJSWorkerClasspath() ++ scalaJSLinkerClasspath() } + def scalaJSToolsClasspath = Task { scalaJSWorkerClasspath() ++ scalaJSLinkerClasspath() } - def fastLinkJS: Target[Report] = T.persistent { + def fastLinkJS: Task[Report] = Task.persistent { linkTask(isFullLinkJS = false, forceOutJs = false)() } - def fullLinkJS: Target[Report] = T.persistent { + def fullLinkJS: Task[Report] = Task.persistent { linkTask(isFullLinkJS = true, forceOutJs = false)() } @deprecated("Use fastLinkJS instead", "Mill 0.10.12") - def fastOpt: Target[PathRef] = T { + def fastOpt: Task[PathRef] = Task { getReportMainFilePathRef(linkTask(isFullLinkJS = false, forceOutJs = true)()) } @deprecated("Use fullLinkJS instead", "Mill 0.10.12") - def fullOpt: Target[PathRef] = T { + def fullOpt: Task[PathRef] = Task { getReportMainFilePathRef(linkTask(isFullLinkJS = true, forceOutJs = true)()) } - private def linkTask(isFullLinkJS: Boolean, forceOutJs: Boolean): Task[Report] = T.task { + private def linkTask(isFullLinkJS: Boolean, forceOutJs: Boolean): Task[Report] = Task.anon { linkJs( worker = ScalaJSWorkerExternalModule.scalaJSWorker(), toolsClasspath = scalaJSToolsClasspath(), @@ -144,11 +144,12 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => ) } - override def runLocal(args: Task[Args] = T.task(Args())): Command[Unit] = T.command { run(args) } + override def runLocal(args: Task[Args] = Task.anon(Args())): Command[Unit] = + Task.command { run(args)() } - override def run(args: Task[Args] = T.task(Args())): Command[Unit] = T.command { + override def run(args: Task[Args] = Task.anon(Args())): Command[Unit] = Task.command { if (args().value.nonEmpty) { - T.log.error("Passing command line arguments to run is not supported by Scala.js.") + Task.log.error("Passing command line arguments to run is not supported by Scala.js.") } finalMainClassOpt() match { case Left(err) => Result.Failure(err) @@ -163,11 +164,11 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => } - override def runMainLocal(mainClass: String, args: String*): Command[Unit] = T.command[Unit] { + override def runMainLocal(mainClass: String, args: String*): Command[Unit] = Task.command[Unit] { mill.api.Result.Failure("runMain is not supported in Scala.js") } - override def runMain(mainClass: String, args: String*): Command[Unit] = T.command[Unit] { + override def runMain(mainClass: String, args: String*): Command[Unit] = Task.command[Unit] { mill.api.Result.Failure("runMain is not supported in Scala.js") } @@ -211,7 +212,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => ) } - override def mandatoryScalacOptions = T { + override def mandatoryScalacOptions: Task[Seq[String]] = Task { // Don't add flag twice, e.g. if a test suite inherits it both directly // ScalaJSModule as well as from the enclosing non-test ScalaJSModule val scalajsFlag = @@ -224,7 +225,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => super.mandatoryScalacOptions() ++ scalajsFlag } - override def scalacPluginIvyDeps = T { + override def scalacPluginIvyDeps = Task { super.scalacPluginIvyDeps() ++ { if (ZincWorkerUtil.isScala3(scalaVersion())) { Seq.empty @@ -235,7 +236,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => } /** Adds the Scala.js Library as mandatory dependency. */ - override def mandatoryIvyDeps = T { + override def mandatoryIvyDeps = Task { val prev = super.mandatoryIvyDeps() val scalaVer = scalaVersion() val scalaJSVer = scalaJSVersion() @@ -259,37 +260,37 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => // publish artifact with name "mill_sjs0.6.4_2.12" instead of "mill_sjs0.6_2.12" def crossFullScalaJSVersion: T[Boolean] = false - def artifactScalaJSVersion: T[String] = T { + def artifactScalaJSVersion: T[String] = Task { if (crossFullScalaJSVersion()) scalaJSVersion() else scalaJSBinaryVersion() } - override def platformSuffix: Target[String] = s"_sjs${artifactScalaJSVersion()}" + override def platformSuffix: Task[String] = s"_sjs${artifactScalaJSVersion()}" - def jsEnvConfig: Target[JsEnvConfig] = T { JsEnvConfig.NodeJs() } + def jsEnvConfig: Task[JsEnvConfig] = Task { JsEnvConfig.NodeJs() } - def moduleKind: Target[ModuleKind] = T { ModuleKind.NoModule } + def moduleKind: Task[ModuleKind] = Task { ModuleKind.NoModule } - def esFeatures: T[ESFeatures] = T { + def esFeatures: T[ESFeatures] = Task { if (scalaJSVersion().startsWith("0.")) ESFeatures.Defaults.withESVersion(ESVersion.ES5_1) else ESFeatures.Defaults } - def moduleSplitStyle: Target[ModuleSplitStyle] = T { ModuleSplitStyle.FewestModules } + def moduleSplitStyle: Task[ModuleSplitStyle] = Task { ModuleSplitStyle.FewestModules } - def scalaJSOptimizer: Target[Boolean] = T { true } + def scalaJSOptimizer: Task[Boolean] = Task { true } - def scalaJSImportMap: Target[Seq[ESModuleImportMapping]] = T { + def scalaJSImportMap: Task[Seq[ESModuleImportMapping]] = Task { Seq.empty[ESModuleImportMapping] } /** Whether to emit a source map. */ - def scalaJSSourceMap: Target[Boolean] = T { true } + def scalaJSSourceMap: Task[Boolean] = Task { true } /** Name patterns for output. */ - def scalaJSOutputPatterns: Target[OutputPatterns] = T { OutputPatterns.Defaults } + def scalaJSOutputPatterns: Task[OutputPatterns] = Task { OutputPatterns.Defaults } /** * Apply Scala.js-specific minification of the produced .js files. @@ -304,21 +305,21 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => * minifier to be used in conjunction with a general-purpose JavaScript * minifier. */ - def scalaJSMinify: Target[Boolean] = T { true } + def scalaJSMinify: Task[Boolean] = Task { true } override def prepareOffline(all: Flag): Command[Unit] = { val tasks = if (all.value) Seq(scalaJSToolsClasspath) else Seq() - T.command { + Task.command { super.prepareOffline(all)() - T.sequence(tasks)() + Task.sequence(tasks)() () } } @internal - override def bspBuildTargetData: Task[Option[(String, AnyRef)]] = T.task { + override def bspBuildTargetData: Task[Option[(String, AnyRef)]] = Task.anon { Some(( ScalaBuildTarget.dataKind, ScalaBuildTarget( @@ -338,8 +339,7 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer => } trait TestScalaJSModule extends ScalaJSModule with TestModule { - override def resources: T[Seq[PathRef]] = super[ScalaJSModule].resources - def scalaJSTestDeps = T { + def scalaJSTestDeps = Task { defaultResolver().resolveDeps( Loose.Agg( ivy"org.scala-js::scalajs-library:${scalaJSVersion()}", @@ -349,7 +349,7 @@ trait TestScalaJSModule extends ScalaJSModule with TestModule { ) } - def fastLinkJSTest: Target[Report] = T.persistent { + def fastLinkJSTest: Task[Report] = Task.persistent { linkJs( worker = ScalaJSWorkerExternalModule.scalaJSWorker(), toolsClasspath = scalaJSToolsClasspath(), @@ -370,12 +370,12 @@ trait TestScalaJSModule extends ScalaJSModule with TestModule { } override def testLocal(args: String*): Command[(String, Seq[TestResult])] = - T.command { test(args: _*) } + Task.command { test(args: _*)() } override protected def testTask( args: Task[Seq[String]], globSelectors: Task[Seq[String]] - ): Task[(String, Seq[TestResult])] = T.task { + ): Task[(String, Seq[TestResult])] = Task.anon { val (close, framework) = ScalaJSWorkerExternalModule.scalaJSWorker().getFramework( scalaJSToolsClasspath(), @@ -389,10 +389,10 @@ trait TestScalaJSModule extends ScalaJSModule with TestModule { runClasspath().map(_.path), Agg(compile().classes.path), args(), - T.testReporter, + Task.testReporter, TestRunnerUtils.globFilter(globSelectors()) ) - val res = TestModule.handleResults(doneMsg, results, T.ctx(), testReportXml()) + val res = TestModule.handleResults(doneMsg, results, Task.ctx(), testReportXml()) // Hack to try and let the Node.js subprocess finish streaming it's stdout // to the JVM. Without this, the stdout can still be streaming when `close()` // is called, and some of the output is dropped onto the floor. diff --git a/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala b/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala index 840a9cac005..ded55b099fd 100644 --- a/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala +++ b/scalajslib/src/mill/scalajslib/worker/ScalaJSWorker.scala @@ -5,7 +5,7 @@ import mill.scalajslib.api import mill.scalajslib.worker.{api => workerApi} import mill.api.{Ctx, Result, internal} import mill.define.{Discover, Worker} -import mill.{Agg, T} +import mill.{Agg, T, Task} @internal private[scalajslib] class ScalaJSWorker extends AutoCloseable { @@ -219,6 +219,6 @@ private[scalajslib] class ScalaJSWorker extends AutoCloseable { @internal private[scalajslib] object ScalaJSWorkerExternalModule extends mill.define.ExternalModule { - def scalaJSWorker: Worker[ScalaJSWorker] = T.worker { new ScalaJSWorker() } - lazy val millDiscover: Discover[this.type] = Discover[this.type] + def scalaJSWorker: Worker[ScalaJSWorker] = Task.worker { new ScalaJSWorker() } + val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala b/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala index 903975d8709..0d202c3454c 100644 --- a/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/FullOptESModuleTests.scala @@ -17,7 +17,7 @@ object FullOptESModuleTests extends TestSuite { override def moduleKind = ModuleKind.ESModule } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "hello-js-world" diff --git a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala index a899a4d58b6..942b1b13aba 100644 --- a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala +++ b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala @@ -54,7 +54,7 @@ object HelloJSWorldTests extends TestSuite { object buildUTest extends Cross[BuildModuleUtest](matrix) trait BuildModuleUtest extends RootModule { object test extends ScalaJSTests with TestModule.Utest { - override def sources = T.sources { millSourcePath / "src" / "utest" } + override def sources = Task.sources { millSourcePath / "src" / "utest" } val utestVersion = if (ZincWorkerUtil.isScala3(crossScalaVersion)) "0.7.7" else "0.7.5" override def ivyDeps = Agg( ivy"com.lihaoyi::utest::$utestVersion" @@ -65,7 +65,7 @@ object HelloJSWorldTests extends TestSuite { object buildScalaTest extends Cross[BuildModuleScalaTest](matrix) trait BuildModuleScalaTest extends RootModule { object test extends ScalaJSTests with TestModule.ScalaTest { - override def sources = T.sources { millSourcePath / "src" / "scalatest" } + override def sources = Task.sources { millSourcePath / "src" / "scalatest" } override def ivyDeps = Agg( ivy"org.scalatest::scalatest::3.1.2" ) @@ -82,7 +82,7 @@ object HelloJSWorldTests extends TestSuite { object test extends ScalaJSTests with TestModule.Utest } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "hello-js-world" @@ -198,7 +198,7 @@ object HelloJSWorldTests extends TestSuite { } } - def runTests(testTask: define.NamedTask[(String, Seq[TestResult])]) + def runTests(testTask: define.Task[(String, Seq[TestResult])]) : Map[String, Map[String, TestResult]] = { val Left(Result.Failure(_, Some(res))) = helloWorldEvaluator(testTask) diff --git a/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala b/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala index b4adc5d2f2d..922c12d728f 100644 --- a/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/MultiModuleTests.scala @@ -30,7 +30,7 @@ object MultiModuleTests extends TestSuite { override def millSourcePath = workspacePath / "shared" } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } val evaluator = TestEvaluator.static(MultiModule) diff --git a/scalajslib/test/src/mill/scalajslib/NodeJSConfigTests.scala b/scalajslib/test/src/mill/scalajslib/NodeJSConfigTests.scala index a6ae1be92fb..0d9d796d6d0 100644 --- a/scalajslib/test/src/mill/scalajslib/NodeJSConfigTests.scala +++ b/scalajslib/test/src/mill/scalajslib/NodeJSConfigTests.scala @@ -41,21 +41,21 @@ object NodeJSConfigTests extends TestSuite { override def artifactName = "hello-js-world" def scalaJSVersion = NodeJSConfigTests.scalaJSVersion - override def jsEnvConfig = T { JsEnvConfig.NodeJs(args = nodeArgs) } + override def jsEnvConfig = Task { JsEnvConfig.NodeJs(args = nodeArgs) } } object buildUTest extends Cross[BuildModuleUtest](matrix) trait BuildModuleUtest extends RootModule { object test extends ScalaJSTests with TestModule.Utest { - override def sources = T.sources { millSourcePath / "src" / "utest" } + override def sources = Task.sources { millSourcePath / "src" / "utest" } override def ivyDeps = Agg( ivy"com.lihaoyi::utest::$utestVersion" ) - override def jsEnvConfig = T { JsEnvConfig.NodeJs(args = nodeArgs) } + override def jsEnvConfig = Task { JsEnvConfig.NodeJs(args = nodeArgs) } } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "hello-js-world" diff --git a/scalajslib/test/src/mill/scalajslib/OutputPatternsTests.scala b/scalajslib/test/src/mill/scalajslib/OutputPatternsTests.scala index 0796e27ed38..5ce33e1c38a 100644 --- a/scalajslib/test/src/mill/scalajslib/OutputPatternsTests.scala +++ b/scalajslib/test/src/mill/scalajslib/OutputPatternsTests.scala @@ -19,7 +19,7 @@ object OutputPatternsTests extends TestSuite { override def scalaJSOutputPatterns = OutputPatterns.fromJSFile("%s.mjs") } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "hello-js-world" diff --git a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala index fe94911cc3f..4a9dd29c188 100644 --- a/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala +++ b/scalajslib/test/src/mill/scalajslib/RemapEsModuleTests.scala @@ -4,7 +4,7 @@ import mill.api.Result import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} import utest._ -import mill.define.Target +import mill.define.Task import mill.scalajslib.api._ object EsModuleRemapTests extends TestSuite { @@ -21,7 +21,7 @@ object EsModuleRemapTests extends TestSuite { override def scalaJSSourceMap = false override def moduleKind = ModuleKind.ESModule - override def scalaJSImportMap: Target[Seq[ESModuleImportMapping]] = Seq( + override def scalaJSImportMap: Task[Seq[ESModuleImportMapping]] = Seq( ESModuleImportMapping.Prefix("@stdlib/linspace", remapTo) ) } @@ -33,12 +33,12 @@ object EsModuleRemapTests extends TestSuite { override def scalaJSSourceMap = false override def moduleKind = ModuleKind.ESModule - override def scalaJSImportMap: Target[Seq[ESModuleImportMapping]] = Seq( + override def scalaJSImportMap: Task[Seq[ESModuleImportMapping]] = Seq( ESModuleImportMapping.Prefix("@stdlib/linspace", remapTo) ) } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "esModuleRemap" diff --git a/scalajslib/test/src/mill/scalajslib/ScalaTestsErrorTests.scala b/scalajslib/test/src/mill/scalajslib/ScalaTestsErrorTests.scala index f5582116b61..5971fa15f2a 100644 --- a/scalajslib/test/src/mill/scalajslib/ScalaTestsErrorTests.scala +++ b/scalajslib/test/src/mill/scalajslib/ScalaTestsErrorTests.scala @@ -15,7 +15,7 @@ object ScalaTestsErrorTests extends TestSuite { override def hierarchyChecks(): Unit = {} } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } def tests: Tests = Tests { diff --git a/scalajslib/test/src/mill/scalajslib/SmallModulesForTests.scala b/scalajslib/test/src/mill/scalajslib/SmallModulesForTests.scala index b565e04d9c4..e6bb92f6685 100644 --- a/scalajslib/test/src/mill/scalajslib/SmallModulesForTests.scala +++ b/scalajslib/test/src/mill/scalajslib/SmallModulesForTests.scala @@ -19,7 +19,7 @@ object SmallModulesForTests extends TestSuite { override def moduleSplitStyle = ModuleSplitStyle.SmallModulesFor(List("app")) } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "small-modules-for" diff --git a/scalajslib/test/src/mill/scalajslib/SourceMapTests.scala b/scalajslib/test/src/mill/scalajslib/SourceMapTests.scala index 66257e16f01..f1e4c3c32db 100644 --- a/scalajslib/test/src/mill/scalajslib/SourceMapTests.scala +++ b/scalajslib/test/src/mill/scalajslib/SourceMapTests.scala @@ -17,7 +17,7 @@ object SourceMapTests extends TestSuite { override def scalaJSSourceMap = false } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "hello-js-world" diff --git a/scalajslib/test/src/mill/scalajslib/TopLevelExportsTests.scala b/scalajslib/test/src/mill/scalajslib/TopLevelExportsTests.scala index 139a7640a40..77deb785355 100644 --- a/scalajslib/test/src/mill/scalajslib/TopLevelExportsTests.scala +++ b/scalajslib/test/src/mill/scalajslib/TopLevelExportsTests.scala @@ -18,7 +18,7 @@ object TopLevelExportsTests extends TestSuite { override def moduleKind = ModuleKind.ESModule } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } val millSourcePath = os.pwd / "scalajslib" / "test" / "resources" / "top-level-exports" diff --git a/scalalib/src/mill/scalalib/CoursierModule.scala b/scalalib/src/mill/scalalib/CoursierModule.scala index 0b46e22b790..bf009754bd7 100644 --- a/scalalib/src/mill/scalalib/CoursierModule.scala +++ b/scalalib/src/mill/scalalib/CoursierModule.scala @@ -3,7 +3,6 @@ package mill.scalalib import coursier.cache.FileCache import coursier.{Dependency, Repository, Resolve} import coursier.core.Resolution -import mill.T import mill.define.Task import mill.api.PathRef @@ -24,16 +23,16 @@ trait CoursierModule extends mill.Module { * Bind a dependency ([[Dep]]) to the actual module contetxt (e.g. the scala version and the platform suffix) * @return The [[BoundDep]] */ - def bindDependency: Task[Dep => BoundDep] = T.task { dep: Dep => + def bindDependency: Task[Dep => BoundDep] = Task.anon { dep: Dep => BoundDep((resolveCoursierDependency(): @nowarn).apply(dep), dep.force) } @deprecated("To be replaced by bindDependency", "Mill after 0.11.0-M0") - def resolveCoursierDependency: Task[Dep => coursier.Dependency] = T.task { + def resolveCoursierDependency: Task[Dep => coursier.Dependency] = Task.anon { Lib.depToDependencyJava(_: Dep) } - def defaultResolver: Task[CoursierModule.Resolver] = T.task { + def defaultResolver: Task[CoursierModule.Resolver] = Task.anon { new CoursierModule.Resolver( repositories = repositoriesTask(), bind = bindDependency(), @@ -52,7 +51,7 @@ trait CoursierModule extends mill.Module { * @return The [[PathRef]]s to the resolved files. */ def resolveDeps(deps: Task[Agg[BoundDep]], sources: Boolean = false): Task[Agg[PathRef]] = - T.task { + Task.anon { Lib.resolveDependencies( repositories = repositoriesTask(), deps = deps(), @@ -68,12 +67,12 @@ trait CoursierModule extends mill.Module { * Map dependencies before resolving them. * Override this to customize the set of dependencies. */ - def mapDependencies: Task[Dependency => Dependency] = T.task { d: Dependency => d } + def mapDependencies: Task[Dependency => Dependency] = Task.anon { d: Dependency => d } /** * The repositories used to resolved dependencies with [[resolveDeps()]]. */ - def repositoriesTask: Task[Seq[Repository]] = T.task { + def repositoriesTask: Task[Seq[Repository]] = Task.anon { import scala.concurrent.ExecutionContext.Implicits.global val repos = Await.result( Resolve().finalRepositories.future(), @@ -91,7 +90,7 @@ trait CoursierModule extends mill.Module { * For example, the JavaFX artifacts are known to use OS specific properties. * To fix resolution for JavaFX, you could override this task like the following: * {{{ - * override def resolutionCustomizer = T.task { + * override def resolutionCustomizer = Task.anon { * Some( (r: coursier.core.Resolution) => * r.withOsInfo(coursier.core.Activation.Os.fromProperties(sys.props.toMap)) * ) @@ -99,7 +98,7 @@ trait CoursierModule extends mill.Module { * }}} * @return */ - def resolutionCustomizer: Task[Option[Resolution => Resolution]] = T.task { None } + def resolutionCustomizer: Task[Option[Resolution => Resolution]] = Task.anon { None } /** * Customize the coursier file cache. @@ -107,7 +106,7 @@ trait CoursierModule extends mill.Module { * This is rarely needed to be changed, but sometimes e.g you want to load a coursier plugin. * Doing so requires adding to coursier's classpath. To do this you could use the following: * {{{ - * override def coursierCacheCustomizer = T.task { + * override def coursierCacheCustomizer = Task.anon { * Some( (fc: coursier.cache.FileCache[Task]) => * fc.withClassLoaders(Seq(classOf[coursier.cache.protocol.S3Handler].getClassLoader)) * ) @@ -117,7 +116,7 @@ trait CoursierModule extends mill.Module { */ def coursierCacheCustomizer : Task[Option[FileCache[coursier.util.Task] => FileCache[coursier.util.Task]]] = - T.task { None } + Task.anon { None } } object CoursierModule { diff --git a/scalalib/src/mill/scalalib/CrossModuleBase.scala b/scalalib/src/mill/scalalib/CrossModuleBase.scala index 26173331f06..aaaa854d97f 100644 --- a/scalalib/src/mill/scalalib/CrossModuleBase.scala +++ b/scalalib/src/mill/scalalib/CrossModuleBase.scala @@ -1,6 +1,6 @@ package mill.scalalib -import mill.T +import mill.{Task, T} import mill.define.Cross import mill.define.Cross.Resolver import mill.scalalib.api.ZincWorkerUtil @@ -8,7 +8,7 @@ import mill.scalalib.api.ZincWorkerUtil trait CrossModuleBase extends ScalaModule with Cross.Module[String] { def crossScalaVersion: String = crossValue - def scalaVersion = T { crossScalaVersion } + def scalaVersion = Task { crossScalaVersion } protected def scalaVersionDirectoryNames: Seq[String] = ZincWorkerUtil.matchingVersions(crossScalaVersion) diff --git a/scalalib/src/mill/scalalib/CrossSbtModule.scala b/scalalib/src/mill/scalalib/CrossSbtModule.scala index 40f68ad574c..e065ae3d22c 100644 --- a/scalalib/src/mill/scalalib/CrossSbtModule.scala +++ b/scalalib/src/mill/scalalib/CrossSbtModule.scala @@ -1,12 +1,12 @@ package mill.scalalib import mill.api.PathRef -import mill.T +import mill.{Task, T} import mill.scalalib.{CrossModuleBase, SbtModule} trait CrossSbtModule extends SbtModule with CrossModuleBase { outer => - override def sources: T[Seq[PathRef]] = T.sources { + override def sources: T[Seq[PathRef]] = Task.sources { super.sources() ++ scalaVersionDirectoryNames.map(s => PathRef(millSourcePath / "src" / "main" / s"scala-$s") ) @@ -16,7 +16,7 @@ trait CrossSbtModule extends SbtModule with CrossModuleBase { outer => @deprecated("Use CrossSbtTests instead", since = "Mill 0.11.10") trait CrossSbtModuleTests extends SbtModuleTests { override def millSourcePath = outer.millSourcePath - override def sources = T.sources { + override def sources = Task.sources { super.sources() ++ scalaVersionDirectoryNames.map(s => PathRef(millSourcePath / "src" / "test" / s"scala-$s") ) diff --git a/scalalib/src/mill/scalalib/CrossScalaModule.scala b/scalalib/src/mill/scalalib/CrossScalaModule.scala index 077605f238c..d8a99152c7e 100644 --- a/scalalib/src/mill/scalalib/CrossScalaModule.scala +++ b/scalalib/src/mill/scalalib/CrossScalaModule.scala @@ -1,7 +1,7 @@ package mill.scalalib import mill.api.PathRef -import mill.T +import mill.{Task, T} /** * A [[ScalaModule]] which is suited to be used with [[mill.define.Cross]]. @@ -13,7 +13,7 @@ import mill.T * - src-2.12.3 */ trait CrossScalaModule extends ScalaModule with CrossModuleBase { - override def sources: T[Seq[PathRef]] = T.sources { + override def sources: T[Seq[PathRef]] = Task.sources { super.sources() ++ scalaVersionDirectoryNames.map(s => PathRef(millSourcePath / s"src-$s")) } diff --git a/scalalib/src/mill/scalalib/Dependency.scala b/scalalib/src/mill/scalalib/Dependency.scala index f2b6eca79c4..1e0665ae695 100644 --- a/scalalib/src/mill/scalalib/Dependency.scala +++ b/scalalib/src/mill/scalalib/Dependency.scala @@ -1,6 +1,6 @@ package mill.scalalib -import mill.T +import mill.{Task, T} import mill.define.{Command, Discover, ExternalModule} import mill.eval.Evaluator import mill.scalalib.dependency.{DependencyUpdatesImpl, Format} @@ -13,7 +13,7 @@ object Dependency extends ExternalModule { ev: Evaluator, allowPreRelease: Boolean = false ): Command[Seq[ModuleDependenciesUpdates]] = - T.command { + Task.command { DependencyUpdatesImpl( ev, implicitly, @@ -28,7 +28,7 @@ object Dependency extends ExternalModule { ev: Evaluator, allowPreRelease: Boolean = false, format: Format = Format.PerModule - ): Command[Unit] = T.command { + ): Command[Unit] = Task.command { DependencyUpdatesImpl.showAllUpdates(updates(ev, allowPreRelease)(), format) } diff --git a/scalalib/src/mill/scalalib/GenIdea.scala b/scalalib/src/mill/scalalib/GenIdea.scala index 9bdf16fe094..1a0ccd65772 100644 --- a/scalalib/src/mill/scalalib/GenIdea.scala +++ b/scalalib/src/mill/scalalib/GenIdea.scala @@ -1,6 +1,6 @@ package mill.scalalib -import mill.T +import mill.{Task, T} import mill.define.{Command, Discover, ExternalModule} import mill.eval.Evaluator import mill.resolve.SelectMode @@ -9,8 +9,8 @@ import mill.resolve.SelectMode object GenIdea extends ExternalModule { @deprecated("Use mill.idea.GenIdea/idea instead", "Mill 0.11.2") - def idea(ev: Evaluator): Command[Unit] = T.command { - T.log.error( + def idea(ev: Evaluator): Command[Unit] = Task.command { + Task.log.error( "mill.scalalib.GenIdea/idea is deprecated. Please use mill.idea.GenIdea/idea instead." ) mill.main.RunScript.evaluateTasksNamed( @@ -23,5 +23,5 @@ object GenIdea extends ExternalModule { () } - override lazy val millDiscover: Discover[this.type] = Discover[this.type] + override val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/scalalib/src/mill/scalalib/GenIdeaImpl.scala b/scalalib/src/mill/scalalib/GenIdeaImpl.scala index b4e8ee0fcc1..ea176b40790 100755 --- a/scalalib/src/mill/scalalib/GenIdeaImpl.scala +++ b/scalalib/src/mill/scalalib/GenIdeaImpl.scala @@ -14,7 +14,7 @@ import mill.eval.Evaluator import mill.main.BuildInfo import mill.scalalib.GenIdeaModule.{IdeaConfigFile, JavaFacet} import mill.util.Classpath -import mill.{T, scalalib} +import mill.{T, Task, scalalib} import os.{Path, SubPath} /** @@ -108,63 +108,63 @@ case class GenIdeaImpl( case (path, mod) => { // same as input of resolvedIvyDeps - val allIvyDeps = T.task { + val allIvyDeps = Task.anon { mod.transitiveIvyDeps() ++ mod.transitiveCompileIvyDeps() } val scalaCompilerClasspath = mod match { case x: ScalaModule => x.scalaCompilerClasspath case _ => - T.task { + Task.anon { Agg.empty[PathRef] } } - val externalLibraryDependencies = T.task { + val externalLibraryDependencies = Task.anon { mod.defaultResolver().resolveDeps( mod.mandatoryIvyDeps() ) } - val externalDependencies = T.task { + val externalDependencies = Task.anon { mod.resolvedIvyDeps() ++ - T.traverse(mod.transitiveModuleDeps)(_.unmanagedClasspath)().flatten + Task.traverse(mod.transitiveModuleDeps)(_.unmanagedClasspath)().flatten } - val extCompileIvyDeps = T.task { + val extCompileIvyDeps = Task.anon { mod.defaultResolver().resolveDeps(mod.compileIvyDeps()) } val extRunIvyDeps = mod.resolvedRunIvyDeps - val externalSources = T.task { + val externalSources = Task.anon { mod.resolveDeps(allIvyDeps, sources = true)() } val (scalacPluginsIvyDeps, allScalacOptions) = mod match { case mod: ScalaModule => ( - T.task(mod.scalacPluginIvyDeps()), - T.task(mod.allScalacOptions()) + Task.anon(mod.scalacPluginIvyDeps()), + Task.anon(mod.allScalacOptions()) ) - case _ => (T.task { Agg[Dep]() }, T.task { Seq() }) + case _ => (Task.anon { Agg[Dep]() }, Task.anon { Seq() }) } - val scalacPluginDependencies = T.task { + val scalacPluginDependencies = Task.anon { mod.defaultResolver().resolveDeps(scalacPluginsIvyDeps()) } - val facets = T.task { + val facets = Task.anon { mod.ideaJavaModuleFacets(ideaConfigVersion)() } - val configFileContributions = T.task { + val configFileContributions = Task.anon { mod.ideaConfigFiles(ideaConfigVersion)() } - val compilerOutput = T.task { + val compilerOutput = Task.anon { mod.ideaCompileOutput() } - T.task { + Task.anon { val resolvedCp: Agg[Scoped[Path]] = externalDependencies().map(_.path).map(Scoped(_, None)) ++ extCompileIvyDeps() diff --git a/scalalib/src/mill/scalalib/GenIdeaModule.scala b/scalalib/src/mill/scalalib/GenIdeaModule.scala index 699c0516632..29b0796e041 100644 --- a/scalalib/src/mill/scalalib/GenIdeaModule.scala +++ b/scalalib/src/mill/scalalib/GenIdeaModule.scala @@ -1,7 +1,6 @@ package mill.scalalib -import mill.define.Task -import mill.{Module, PathRef, T} +import mill.{Module, PathRef, T, Task} import os.SubPath /** @@ -23,16 +22,16 @@ trait GenIdeaModule extends Module { * @return */ def ideaJavaModuleFacets(ideaConfigVersion: Int): Task[Seq[JavaFacet]] = - T.task { Seq[JavaFacet]() } + Task.anon { Seq[JavaFacet]() } /** * Contribute components to idea config files. */ def ideaConfigFiles(ideaConfigVersion: Int): Task[Seq[IdeaConfigFile]] = - T.task { Seq[IdeaConfigFile]() } + Task.anon { Seq[IdeaConfigFile]() } - def ideaCompileOutput: T[PathRef] = T.persistent { - PathRef(T.dest / "classes") + def ideaCompileOutput: T[PathRef] = Task.persistent { + PathRef(Task.dest / "classes") } } diff --git a/scalalib/src/mill/scalalib/JavaModule.scala b/scalalib/src/mill/scalalib/JavaModule.scala index 60c201e3c67..c4e1282fae7 100644 --- a/scalalib/src/mill/scalalib/JavaModule.scala +++ b/scalalib/src/mill/scalalib/JavaModule.scala @@ -47,11 +47,11 @@ trait JavaModule override def repositoriesTask: Task[Seq[Repository]] = outer.repositoriesTask override def resolutionCustomizer: Task[Option[coursier.Resolution => coursier.Resolution]] = outer.resolutionCustomizer - override def javacOptions: T[Seq[String]] = T { outer.javacOptions() } + override def javacOptions: T[Seq[String]] = Task { outer.javacOptions() } override def zincWorker: ModuleRef[ZincWorkerModule] = outer.zincWorker override def skipIdea: Boolean = outer.skipIdea - override def runUseArgsFile: T[Boolean] = T { outer.runUseArgsFile() } - override def sources = T.sources { + override def runUseArgsFile: T[Boolean] = Task { outer.runUseArgsFile() } + override def sources = Task.sources { for (src <- outer.sources()) yield { PathRef(this.millSourcePath / src.path.relativeTo(outer.millSourcePath)) } @@ -87,7 +87,7 @@ trait JavaModule } def defaultCommandName(): String = "run" - def resolvePublishDependency: Task[Dep => publish.Dependency] = T.task { + def resolvePublishDependency: Task[Dep => publish.Dependency] = Task.anon { Artifact.fromDepJava(_: Dep) } @@ -98,7 +98,7 @@ trait JavaModule */ def mainClass: T[Option[String]] = None - def finalMainClassOpt: T[Either[String, String]] = T { + def finalMainClassOpt: T[Either[String, String]] = Task { mainClass() match { case Some(m) => Right(m) case None => @@ -114,7 +114,7 @@ trait JavaModule } } - def finalMainClass: T[String] = T { + def finalMainClass: T[String] = Task { finalMainClassOpt() match { case Right(main) => Result.Success(main) case Left(msg) => Result.Failure(msg) @@ -125,39 +125,39 @@ trait JavaModule * Mandatory ivy dependencies that are typically always required and shouldn't be removed by * overriding [[ivyDeps]], e.g. the scala-library in the [[ScalaModule]]. */ - def mandatoryIvyDeps: T[Agg[Dep]] = T { Agg.empty[Dep] } + def mandatoryIvyDeps: T[Agg[Dep]] = Task { Agg.empty[Dep] } /** * Any ivy dependencies you want to add to this Module, in the format * ivy"org::name:version" for Scala dependencies or ivy"org:name:version" * for Java dependencies */ - def ivyDeps: T[Agg[Dep]] = T { Agg.empty[Dep] } + def ivyDeps: T[Agg[Dep]] = Task { Agg.empty[Dep] } /** * Aggregation of mandatoryIvyDeps and ivyDeps. * In most cases, instead of overriding this Target you want to override `ivyDeps` instead. */ - def allIvyDeps: T[Agg[Dep]] = T { mandatoryIvyDeps() ++ ivyDeps() } + def allIvyDeps: T[Agg[Dep]] = Task { mandatoryIvyDeps() ++ ivyDeps() } /** * Same as `ivyDeps`, but only present at compile time. Useful for e.g. * macro-related dependencies like `scala-reflect` that doesn't need to be * present at runtime */ - def compileIvyDeps: T[Agg[Dep]] = T { Agg.empty[Dep] } + def compileIvyDeps: T[Agg[Dep]] = Task { Agg.empty[Dep] } /** * Additional dependencies, only present at runtime. Useful for e.g. * selecting different versions of a dependency to use at runtime after your * code has already been compiled. */ - def runIvyDeps: T[Agg[Dep]] = T { Agg.empty[Dep] } + def runIvyDeps: T[Agg[Dep]] = Task { Agg.empty[Dep] } /** * Options to pass to the java compiler */ - def javacOptions: T[Seq[String]] = T { Seq.empty[String] } + def javacOptions: T[Seq[String]] = Task { Seq.empty[String] } /** * The direct dependencies of this module. @@ -229,17 +229,17 @@ trait JavaModule } /** The compile-only transitive ivy dependencies of this module and all it's upstream compile-only modules. */ - def transitiveCompileIvyDeps: T[Agg[BoundDep]] = T { + def transitiveCompileIvyDeps: T[Agg[BoundDep]] = Task { // We never include compile-only dependencies transitively, but we must include normal transitive dependencies! compileIvyDeps().map(bindDependency()) ++ - T.traverse(compileModuleDepsChecked)(_.transitiveIvyDeps)().flatten + Task.traverse(compileModuleDepsChecked)(_.transitiveIvyDeps)().flatten } /** * Show the module dependencies. * @param recursive If `true` include all recursive module dependencies, else only show direct dependencies. */ - def showModuleDeps(recursive: Boolean = false): Command[Unit] = T.command { + def showModuleDeps(recursive: Boolean = false): Command[Unit] = Task.command { val normalDeps = if (recursive) recursiveModuleDeps else moduleDepsChecked val compileDeps = if (recursive) compileModuleDepsChecked.flatMap(_.transitiveModuleDeps).distinct @@ -254,7 +254,7 @@ trait JavaModule else "") } .mkString("\n\t")}" - T.log.outputStream.println(asString) + Task.log.outputStream.println(asString) } /** @@ -262,29 +262,29 @@ trait JavaModule * from disk rather than being downloaded from Maven Central or other package * repositories */ - def unmanagedClasspath: T[Agg[PathRef]] = T { Agg.empty[PathRef] } + def unmanagedClasspath: T[Agg[PathRef]] = Task { Agg.empty[PathRef] } /** * The transitive ivy dependencies of this module and all it's upstream modules. * This is calculated from [[ivyDeps]], [[mandatoryIvyDeps]] and recursively from [[moduleDeps]]. */ - def transitiveIvyDeps: T[Agg[BoundDep]] = T { + def transitiveIvyDeps: T[Agg[BoundDep]] = Task { (ivyDeps() ++ mandatoryIvyDeps()).map(bindDependency()) ++ - T.traverse(moduleDepsChecked)(_.transitiveIvyDeps)().flatten + Task.traverse(moduleDepsChecked)(_.transitiveIvyDeps)().flatten } /** * The upstream compilation output of all this module's upstream modules */ - def upstreamCompileOutput: T[Seq[CompilationResult]] = T { - T.traverse(transitiveModuleCompileModuleDeps)(_.compile) + def upstreamCompileOutput: T[Seq[CompilationResult]] = Task { + Task.traverse(transitiveModuleCompileModuleDeps)(_.compile)() } /** * The transitive version of `localClasspath` */ - def transitiveLocalClasspath: T[Agg[PathRef]] = T { - T.traverse(transitiveModuleCompileModuleDeps)(_.localClasspath)().flatten + def transitiveLocalClasspath: T[Agg[PathRef]] = Task { + Task.traverse(transitiveModuleCompileModuleDeps)(_.localClasspath)().flatten } /** @@ -294,16 +294,16 @@ trait JavaModule * Keep in sync with [[transitiveLocalClasspath]] */ @internal - def bspTransitiveLocalClasspath: T[Agg[UnresolvedPath]] = T { - T.traverse(transitiveModuleCompileModuleDeps)(_.bspLocalClasspath)().flatten + def bspTransitiveLocalClasspath: T[Agg[UnresolvedPath]] = Task { + Task.traverse(transitiveModuleCompileModuleDeps)(_.bspLocalClasspath)().flatten } /** * The transitive version of `compileClasspath` */ - def transitiveCompileClasspath: T[Agg[PathRef]] = T { - T.traverse(transitiveModuleCompileModuleDeps)(m => - T.task { m.localCompileClasspath() ++ Agg(m.compile().classes) } + def transitiveCompileClasspath: T[Agg[PathRef]] = Task { + Task.traverse(transitiveModuleCompileModuleDeps)(m => + Task.anon { m.localCompileClasspath() ++ Agg(m.compile().classes) } )().flatten } @@ -314,9 +314,9 @@ trait JavaModule * Keep in sync with [[transitiveCompileClasspath]] */ @internal - def bspTransitiveCompileClasspath: T[Agg[UnresolvedPath]] = T { - T.traverse(transitiveModuleCompileModuleDeps)(m => - T.task { + def bspTransitiveCompileClasspath: T[Agg[UnresolvedPath]] = Task { + Task.traverse(transitiveModuleCompileModuleDeps)(m => + Task.anon { m.localCompileClasspath().map(p => UnresolvedPath.ResolvedPath(p.path)) ++ Agg(m.bspCompileClassesPath()) } @@ -328,14 +328,14 @@ trait JavaModule * What platform suffix to use for publishing, e.g. `_sjs` for Scala.js * projects */ - def platformSuffix: T[String] = T { "" } + def platformSuffix: T[String] = Task { "" } /** * What shell script to use to launch the executable generated by `assembly`. * Defaults to a generic "universal" launcher that should work for Windows, * OS-X and Linux */ - def prependShellScript: T[String] = T { + def prependShellScript: T[String] = Task { finalMainClassOpt().toOption match { case None => "" case Some(cls) => @@ -357,37 +357,37 @@ trait JavaModule /** * The folders where the source files for this module live */ - def sources: T[Seq[PathRef]] = T.sources { millSourcePath / "src" } + def sources: T[Seq[PathRef]] = Task.sources { millSourcePath / "src" } /** * The folders where the resource files for this module live. * If you need resources to be seen by the compiler, use [[compileResources]]. */ - def resources: T[Seq[PathRef]] = T.sources { millSourcePath / "resources" } + def resources: T[Seq[PathRef]] = Task.sources { millSourcePath / "resources" } /** * The folders where the compile time resource files for this module live. * If your resources files do not necessarily need to be seen by the compiler, * you should use [[resources]] instead. */ - def compileResources: T[Seq[PathRef]] = T.sources { millSourcePath / "compile-resources" } + def compileResources: T[Seq[PathRef]] = Task.sources { millSourcePath / "compile-resources" } /** * Folders containing source files that are generated rather than * hand-written; these files can be generated in this target itself, * or can refer to files generated from other targets */ - def generatedSources: T[Seq[PathRef]] = T { Seq.empty[PathRef] } + def generatedSources: T[Seq[PathRef]] = Task { Seq.empty[PathRef] } /** * The folders containing all source files fed into the compiler */ - def allSources: T[Seq[PathRef]] = T { sources() ++ generatedSources() } + def allSources: T[Seq[PathRef]] = Task { sources() ++ generatedSources() } /** * All individual source files fed into the Java compiler */ - def allSourceFiles: T[Seq[PathRef]] = T { + def allSourceFiles: T[Seq[PathRef]] = Task { Lib.findSourceFiles(allSources(), Seq("java")).map(PathRef(_)) } @@ -395,14 +395,14 @@ trait JavaModule * If `true`, we always show problems (errors, warnings, infos) found in all source files, even when they have not changed since the previous incremental compilation. * When `false`, we report only problems for files which we re-compiled. */ - def zincReportCachedProblems: T[Boolean] = T.input { + def zincReportCachedProblems: T[Boolean] = Task.input { sys.props.getOrElse( "mill.scalalib.JavaModule.zincReportCachedProblems", "false" ).equalsIgnoreCase("true") } - def zincIncrementalCompilation: T[Boolean] = T { + def zincIncrementalCompilation: T[Boolean] = Task { true } @@ -414,7 +414,7 @@ trait JavaModule * * Keep in sync with [[bspCompileClassesPath]] */ - def compile: T[mill.scalalib.api.CompilationResult] = T.persistent { + def compile: T[mill.scalalib.api.CompilationResult] = Task.persistent { zincWorker() .worker() .compileJava( @@ -422,7 +422,7 @@ trait JavaModule sources = allSourceFiles().map(_.path), compileClasspath = compileClasspath().map(_.path), javacOptions = javacOptions(), - reporter = T.reporter.apply(hashCode), + reporter = Task.reporter.apply(hashCode), reportCachedProblems = zincReportCachedProblems(), incrementalCompilation = zincIncrementalCompilation() ) @@ -438,15 +438,15 @@ trait JavaModule @internal def bspCompileClassesPath: T[UnresolvedPath] = if (compile.ctx.enclosing == s"${classOf[JavaModule].getName}#compile") { - T { - T.log.debug( + Task { + Task.log.debug( s"compile target was not overridden, assuming hard-coded classes directory for target ${compile}" ) UnresolvedPath.DestPath(os.sub / "classes", compile.ctx.segments, compile.ctx.foreign) } } else { - T { - T.log.debug( + Task { + Task.log.debug( s"compile target was overridden, need to actually execute compilation to get the compiled classes directory for target ${compile}" ) UnresolvedPath.ResolvedPath(compile().classes.path) @@ -458,7 +458,7 @@ trait JavaModule * * Keep in sync with [[bspLocalRunClasspath]] */ - override def localRunClasspath: T[Seq[PathRef]] = T { + override def localRunClasspath: T[Seq[PathRef]] = Task { super.localRunClasspath() ++ resources() ++ Agg(compile().classes) } @@ -468,7 +468,7 @@ trait JavaModule * * Keep in sync with [[localRunClasspath]] */ - def bspLocalRunClasspath: T[Agg[UnresolvedPath]] = T { + def bspLocalRunClasspath: T[Agg[UnresolvedPath]] = Task { Agg.from(super.localRunClasspath() ++ resources()) .map(p => UnresolvedPath.ResolvedPath(p.path)) ++ Agg(bspCompileClassesPath()) @@ -483,7 +483,7 @@ trait JavaModule * * Keep in sync with [[bspLocalClasspath]] */ - def localClasspath: T[Seq[PathRef]] = T { + def localClasspath: T[Seq[PathRef]] = Task { localCompileClasspath().toSeq ++ localRunClasspath() } @@ -494,7 +494,7 @@ trait JavaModule * Keep in sync with [[localClasspath]] */ @internal - def bspLocalClasspath: T[Agg[UnresolvedPath]] = T { + def bspLocalClasspath: T[Agg[UnresolvedPath]] = Task { (localCompileClasspath()).map(p => UnresolvedPath.ResolvedPath(p.path)) ++ bspLocalRunClasspath() } @@ -505,7 +505,7 @@ trait JavaModule * * Keep in sync with [[bspCompileClasspath]] */ - def compileClasspath: T[Agg[PathRef]] = T { + def compileClasspath: T[Agg[PathRef]] = Task { resolvedIvyDeps() ++ transitiveCompileClasspath() ++ localCompileClasspath() } @@ -515,7 +515,7 @@ trait JavaModule * Keep in sync with [[compileClasspath]] */ @internal - def bspCompileClasspath: T[Agg[UnresolvedPath]] = T { + def bspCompileClasspath: T[Agg[UnresolvedPath]] = Task { resolvedIvyDeps().map(p => UnresolvedPath.ResolvedPath(p.path)) ++ bspTransitiveCompileClasspath() ++ localCompileClasspath().map(p => UnresolvedPath.ResolvedPath(p.path)) @@ -525,14 +525,14 @@ trait JavaModule * The *input* classfiles/resources from this module, used during compilation, * excluding upstream modules and third-party dependencies */ - def localCompileClasspath: T[Agg[PathRef]] = T { + def localCompileClasspath: T[Agg[PathRef]] = Task { compileResources() ++ unmanagedClasspath() } /** * Resolved dependencies based on [[transitiveIvyDeps]] and [[transitiveCompileIvyDeps]]. */ - def resolvedIvyDeps: T[Agg[PathRef]] = T { + def resolvedIvyDeps: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps(transitiveCompileIvyDeps() ++ transitiveIvyDeps()) } @@ -540,11 +540,11 @@ trait JavaModule * All upstream classfiles and resources necessary to build and executable * assembly, but without this module's contribution */ - def upstreamAssemblyClasspath: T[Agg[PathRef]] = T { + def upstreamAssemblyClasspath: T[Agg[PathRef]] = Task { resolvedRunIvyDeps() ++ transitiveLocalClasspath() } - def resolvedRunIvyDeps: T[Agg[PathRef]] = T { + def resolvedRunIvyDeps: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps(runIvyDeps().map(bindDependency()) ++ transitiveIvyDeps()) } @@ -552,7 +552,7 @@ trait JavaModule * All classfiles and resources from upstream modules and dependencies * necessary to run this module's code after compilation */ - override def runClasspath: T[Seq[PathRef]] = T { + override def runClasspath: T[Seq[PathRef]] = Task { super.runClasspath() ++ resolvedRunIvyDeps().toSeq ++ transitiveLocalClasspath() ++ @@ -563,7 +563,7 @@ trait JavaModule * Creates a manifest representation which can be modified or replaced * The default implementation just adds the `Manifest-Version`, `Main-Class` and `Created-By` attributes */ - def manifest: T[JarManifest] = T { + def manifest: T[JarManifest] = Task { Jvm.createManifest(finalMainClassOpt().toOption) } @@ -578,8 +578,8 @@ trait JavaModule * Please use [[upstreamAssembly2]] instead. */ @deprecated("Use upstreamAssembly2 instead, which has a richer return value", "Mill 0.11.8") - def upstreamAssembly: T[PathRef] = T { - T.log.error( + def upstreamAssembly: T[PathRef] = Task { + Task.log.error( s"upstreamAssembly target is deprecated and should no longer used." + s" Please make sure to use upstreamAssembly2 instead." ) @@ -593,9 +593,9 @@ trait JavaModule * This should allow much faster assembly creation in the common case where * upstream dependencies do not change */ - def upstreamAssembly2: T[Assembly] = T { + def upstreamAssembly2: T[Assembly] = Task { Assembly.create( - destJar = T.dest / "out.jar", + destJar = Task.dest / "out.jar", inputPaths = upstreamAssemblyClasspath().map(_.path), manifest = manifest(), assemblyRules = assemblyRules @@ -606,12 +606,12 @@ trait JavaModule * An executable uber-jar/assembly containing all the resources and compiled * classfiles from this module and all it's upstream modules and dependencies */ - def assembly: T[PathRef] = T { + def assembly: T[PathRef] = Task { // detect potential inconsistencies due to `upstreamAssembly` deprecation after 0.11.7 if ( (upstreamAssembly.ctx.enclosing: @nowarn) != s"${classOf[JavaModule].getName}#upstreamAssembly" ) { - T.log.error( + Task.log.error( s"${upstreamAssembly.ctx.enclosing: @nowarn} is overriding a deprecated target which is no longer used." + s" Please make sure to override upstreamAssembly2 instead." ) @@ -621,7 +621,7 @@ trait JavaModule val upstream = upstreamAssembly2() val created = Assembly.create( - destJar = T.dest / "out.jar", + destJar = Task.dest / "out.jar", Agg.from(localClasspath().map(_.path)), manifest(), prependScript, @@ -652,7 +652,7 @@ trait JavaModule * A jar containing only this module's resources and compiled classfiles, * without those from upstream modules and dependencies */ - def jar: T[PathRef] = T { + def jar: T[PathRef] = Task { Jvm.createJar(localClasspath().map(_.path).filter(os.exists), manifest()) } @@ -661,7 +661,7 @@ trait JavaModule * You should not set the `-d` setting for specifying the target directory, * as that is done in the [[docJar]] target. */ - def javadocOptions: T[Seq[String]] = T { Seq[String]() } + def javadocOptions: T[Seq[String]] = Task { Seq[String]() } /** * Directories to be processed by the API documentation tool. @@ -669,7 +669,7 @@ trait JavaModule * Typically includes the source files to generate documentation from. * @see [[docResources]] */ - def docSources: T[Seq[PathRef]] = T.sources(allSources()) + def docSources: T[Seq[PathRef]] = Task.sources(allSources()) /** * Extra directories to be copied into the documentation. @@ -678,21 +678,21 @@ trait JavaModule * on the doc tool that is actually used. * @see [[docSources]] */ - def docResources: T[Seq[PathRef]] = T.sources(millSourcePath / "docs") + def docResources: T[Seq[PathRef]] = Task.sources(millSourcePath / "docs") /** * Control whether `docJar`-target should use a file to pass command line arguments to the javadoc tool. * Defaults to `true` on Windows. * Beware: Using an args-file is probably not supported for very old javadoc versions. */ - def docJarUseArgsFile: T[Boolean] = T { scala.util.Properties.isWin } + def docJarUseArgsFile: T[Boolean] = Task { scala.util.Properties.isWin } /** * The documentation jar, containing all the Javadoc/Scaladoc HTML files, for * publishing to Maven Central */ def docJar: T[PathRef] = T[PathRef] { - val outDir = T.dest + val outDir = Task.dest val javadocDir = outDir / "javadoc" os.makeDir.all(javadocDir) @@ -725,7 +725,7 @@ trait JavaModule deleteOnExit = false, dir = outDir ) - T.log.debug( + Task.log.debug( s"Creating javadoc options file @${argsFile} ..." ) Seq(s"@${argsFile}") @@ -733,12 +733,12 @@ trait JavaModule options } - T.log.info("options: " + cmdArgs) + Task.log.info("options: " + cmdArgs) Jvm.runSubprocess( commandArgs = Seq(Jvm.jdkTool("javadoc")) ++ cmdArgs, envArgs = Map(), - workingDir = T.dest + workingDir = Task.dest ) } @@ -748,7 +748,7 @@ trait JavaModule /** * The source jar, containing only source code for publishing to Maven Central */ - def sourceJar: T[PathRef] = T { + def sourceJar: T[PathRef] = Task { Jvm.createJar( (allSources() ++ resources() ++ compileResources()).map(_.path).filter(os.exists), manifest() @@ -759,7 +759,7 @@ trait JavaModule * Any command-line parameters you want to pass to the forked JVM under `run`, * `test` or `repl` */ - override def forkArgs: T[Seq[String]] = T { + override def forkArgs: T[Seq[String]] = Task { // overridden here for binary compatibility (0.11.x) super.forkArgs() } @@ -768,7 +768,7 @@ trait JavaModule * Any environment variables you want to pass to the forked JVM under `run`, * `test` or `repl` */ - override def forkEnv: T[Map[String, String]] = T { + override def forkEnv: T[Map[String, String]] = Task { // overridden here for binary compatibility (0.11.x) super.forkEnv() } @@ -778,7 +778,7 @@ trait JavaModule * code, without the Mill process. Useful for deployment & other places where * you do not want a build tool running */ - def launcher = T { + def launcher = Task { Result.Success( Jvm.createLauncher( finalMainClass(), @@ -803,7 +803,7 @@ trait JavaModule additionalDeps: Task[Agg[BoundDep]], whatDependsOn: List[JavaOrScalaModule] ): Task[Unit] = - T.task { + Task.anon { val (flattened: Seq[Dependency], resolution: Resolution) = Lib.resolveDependenciesMetadata( repositoriesTask(), additionalDeps() ++ transitiveIvyDeps(), @@ -852,51 +852,51 @@ trait JavaModule if (invalidModules.isEmpty) { (args.withCompile, args.withRuntime) match { case (Flag(true), Flag(true)) => - T.command { + Task.command { printDepsTree( args.inverse.value, - T.task { + Task.anon { transitiveCompileIvyDeps() ++ runIvyDeps().map(bindDependency()) }, validModules - ) + )() } case (Flag(true), Flag(false)) => - T.command { - printDepsTree(args.inverse.value, transitiveCompileIvyDeps, validModules) + Task.command { + printDepsTree(args.inverse.value, transitiveCompileIvyDeps, validModules)() } case (Flag(false), Flag(true)) => - T.command { + Task.command { printDepsTree( args.inverse.value, - T.task { runIvyDeps().map(bindDependency()) }, + Task.anon { runIvyDeps().map(bindDependency()) }, validModules - ) + )() } case _ => - T.command { - printDepsTree(args.inverse.value, T.task { Agg.empty[BoundDep] }, validModules) + Task.command { + printDepsTree(args.inverse.value, Task.anon { Agg.empty[BoundDep] }, validModules)() } } } else { - T.command { + Task.command { val msg = invalidModules.mkString("\n") Result.Failure[Unit](msg) } } } - override def runUseArgsFile: T[Boolean] = T { + override def runUseArgsFile: T[Boolean] = Task { // overridden here for binary compatibility (0.11.x) super.runUseArgsFile() } - override def runLocal(args: Task[Args] = T.task(Args())): Command[Unit] = { + override def runLocal(args: Task[Args] = Task.anon(Args())): Command[Unit] = { // overridden here for binary compatibility (0.11.x) super.runLocal(args) } - override def run(args: Task[Args] = T.task(Args())): Command[Unit] = { + override def run(args: Task[Args] = Task.anon(Args())): Command[Unit] = { // overridden here for binary compatibility (0.11.x) super.run(args) } @@ -943,8 +943,8 @@ trait JavaModule * that would otherwise run forever */ def runBackground(args: String*): Command[Unit] = { - val task = runBackgroundTask(finalMainClass, T.task { Args(args) }) - T.command { task } + val task = runBackgroundTask(finalMainClass, Task.anon { Args(args) }) + Task.command { task() } } /** @@ -992,7 +992,7 @@ trait JavaModule */ def artifactSuffix: T[String] = platformSuffix() - override def forkWorkingDir: T[Path] = T { + override def forkWorkingDir: T[Path] = Task { // overridden here for binary compatibility (0.11.x) super.forkWorkingDir() } @@ -1002,7 +1002,7 @@ trait JavaModule * This means, if zinc needs to remove a class file, it will also remove files * which match the class file basename and a listed file extension. */ - def zincAuxiliaryClassFileExtensions: T[Seq[String]] = T { Seq.empty[String] } + def zincAuxiliaryClassFileExtensions: T[Seq[String]] = Task { Seq.empty[String] } /** * @param all If `true` fetches also source dependencies @@ -1010,13 +1010,13 @@ trait JavaModule override def prepareOffline(all: Flag): Command[Unit] = { val tasks = if (all.value) Seq( - T.task { + Task.anon { defaultResolver().resolveDeps( transitiveCompileIvyDeps() ++ transitiveIvyDeps(), sources = true ) }, - T.task { + Task.anon { defaultResolver().resolveDeps( runIvyDeps().map(bindDependency()) ++ transitiveIvyDeps(), sources = true @@ -1025,12 +1025,12 @@ trait JavaModule ) else Seq() - T.command { + Task.command { super.prepareOffline(all)() resolvedIvyDeps() zincWorker().prepareOffline(all)() resolvedRunIvyDeps() - T.sequence(tasks)() + Task.sequence(tasks)() () } } @@ -1043,7 +1043,7 @@ trait JavaModule ) @internal - override def bspBuildTargetData: Task[Option[(String, AnyRef)]] = T.task { + override def bspBuildTargetData: Task[Option[(String, AnyRef)]] = Task.anon { Some(( JvmBuildTarget.dataKind, JvmBuildTarget( diff --git a/scalalib/src/mill/scalalib/MavenModule.scala b/scalalib/src/mill/scalalib/MavenModule.scala index 80a7871c2bd..b8ba8ba8705 100644 --- a/scalalib/src/mill/scalalib/MavenModule.scala +++ b/scalalib/src/mill/scalalib/MavenModule.scala @@ -1,6 +1,6 @@ package mill.scalalib -import mill.T +import mill.{Task, T} /** * A [[JavaModule]] with a Maven compatible directory layout. @@ -9,10 +9,10 @@ import mill.T */ trait MavenModule extends JavaModule { outer => - override def sources = T.sources( + override def sources = Task.sources( millSourcePath / "src" / "main" / "java" ) - override def resources = T.sources { + override def resources = Task.sources { millSourcePath / "src" / "main" / "resources" } @@ -22,10 +22,10 @@ trait MavenModule extends JavaModule { outer => override def millSourcePath = outer.millSourcePath override def intellijModulePath: os.Path = outer.millSourcePath / "src" / "test" - override def sources = T.sources( + override def sources = Task.sources( millSourcePath / "src" / "test" / "java" ) - override def resources = T.sources { + override def resources = Task.sources { millSourcePath / "src" / "test" / "resources" } } diff --git a/scalalib/src/mill/scalalib/OfflineSupportModule.scala b/scalalib/src/mill/scalalib/OfflineSupportModule.scala index e765a7fb8e5..80707911f30 100644 --- a/scalalib/src/mill/scalalib/OfflineSupportModule.scala +++ b/scalalib/src/mill/scalalib/OfflineSupportModule.scala @@ -1,7 +1,7 @@ package mill.scalalib import mainargs.Flag -import mill.T +import mill.{Task, T} import mill.define.Command trait OfflineSupportModule extends mill.Module { @@ -10,7 +10,7 @@ trait OfflineSupportModule extends mill.Module { * Prepare the module for working offline. This should typically fetch (missing) resources like ivy dependencies. * @param all If `true`, it also fetches resources not always needed. */ - def prepareOffline(all: Flag): Command[Unit] = T.command { + def prepareOffline(all: Flag): Command[Unit] = Task.command { // nothing to do } diff --git a/scalalib/src/mill/scalalib/PlatformScalaModule.scala b/scalalib/src/mill/scalalib/PlatformScalaModule.scala index b283f4fbf0b..0482e079aaa 100644 --- a/scalalib/src/mill/scalalib/PlatformScalaModule.scala +++ b/scalalib/src/mill/scalalib/PlatformScalaModule.scala @@ -26,7 +26,7 @@ trait PlatformScalaModule extends ScalaModule { .collect { case l: mill.define.Segment.Label => l.value } .last - override def sources: T[Seq[PathRef]] = T.sources { + override def sources: T[Seq[PathRef]] = Task.sources { super.sources().flatMap { source => val platformPath = PathRef(source.path / _root_.os.up / s"${source.path.last}-${platformScalaSuffix}") diff --git a/scalalib/src/mill/scalalib/PublishModule.scala b/scalalib/src/mill/scalalib/PublishModule.scala index cf5a943bee8..27a9984d90f 100644 --- a/scalalib/src/mill/scalalib/PublishModule.scala +++ b/scalalib/src/mill/scalalib/PublishModule.scala @@ -1,7 +1,7 @@ package mill package scalalib -import mill.define.{Command, ExternalModule, Target, Task} +import mill.define.{Command, ExternalModule, Task} import mill.api.{JarManifest, PathRef, Result} import mill.scalalib.PublishModule.checkSonatypeCreds import mill.scalalib.publish.SonatypeHelpers.{ @@ -54,13 +54,13 @@ trait PublishModule extends JavaModule { outer => * * @since Mill after 0.10.0-M5 */ - def versionScheme: Target[Option[VersionScheme]] = T { None } + def versionScheme: Task[Option[VersionScheme]] = Task { None } - def publishSelfDependency: Target[Artifact] = T { + def publishSelfDependency: Task[Artifact] = Task { Artifact(pomSettings().organization, artifactId(), publishVersion()) } - def publishXmlDeps: Task[Agg[Dependency]] = T.task { + def publishXmlDeps: Task[Agg[Dependency]] = Task.anon { val ivyPomDeps = (ivyDeps() ++ mandatoryIvyDeps()).map(resolvePublishDependency().apply(_)) val compileIvyPomDeps = compileIvyDeps() @@ -68,10 +68,10 @@ trait PublishModule extends JavaModule { outer => .filter(!ivyPomDeps.contains(_)) .map(_.copy(scope = Scope.Provided)) - val modulePomDeps = T.sequence(moduleDepsChecked.collect { + val modulePomDeps = Task.sequence(moduleDepsChecked.collect { case m: PublishModule => m.publishSelfDependency })() - val compileModulePomDeps = T.sequence(compileModuleDepsChecked.collect { + val compileModulePomDeps = Task.sequence(compileModuleDepsChecked.collect { case m: PublishModule => m.publishSelfDependency })() @@ -80,7 +80,7 @@ trait PublishModule extends JavaModule { outer => compileModulePomDeps.map(Dependency(_, Scope.Provided)) } - def pom: Target[PathRef] = T { + def pom: Task[PathRef] = Task { val pom = Pom( artifactMetadata(), publishXmlDeps(), @@ -89,33 +89,33 @@ trait PublishModule extends JavaModule { outer => publishProperties(), packagingType = pomPackagingType ) - val pomPath = T.dest / s"${artifactId()}-${publishVersion()}.pom" + val pomPath = Task.dest / s"${artifactId()}-${publishVersion()}.pom" os.write.over(pomPath, pom) PathRef(pomPath) } - def ivy: Target[PathRef] = T { + def ivy: Task[PathRef] = Task { val ivy = Ivy(artifactMetadata(), publishXmlDeps(), extraPublish()) - val ivyPath = T.dest / "ivy.xml" + val ivyPath = Task.dest / "ivy.xml" os.write.over(ivyPath, ivy) PathRef(ivyPath) } - def artifactMetadata: Target[Artifact] = T { + def artifactMetadata: Task[Artifact] = Task { Artifact(pomSettings().organization, artifactId(), publishVersion()) } /** * Extra artifacts to publish. */ - def extraPublish: Target[Seq[PublishInfo]] = T { Seq.empty[PublishInfo] } + def extraPublish: Task[Seq[PublishInfo]] = Task { Seq.empty[PublishInfo] } /** * Properties to be published with the published pom/ivy XML. * Use `super.publishProperties() ++` when overriding to avoid losing default properties. * @since Mill after 0.10.0-M5 */ - def publishProperties: Target[Map[String, String]] = T { + def publishProperties: Task[Map[String, String]] = Task { versionScheme().map(_.toProperty).toMap } @@ -124,9 +124,9 @@ trait PublishModule extends JavaModule { outer => * @param localIvyRepo The local ivy repository. * If not defined, the default resolution is used (probably `$HOME/.ivy2/local`). */ - def publishLocal(localIvyRepo: String = null): define.Command[Unit] = T.command { - publishLocalTask(T.task { - Option(localIvyRepo).map(os.Path(_, T.workspace)) + def publishLocal(localIvyRepo: String = null): define.Command[Unit] = Task.command { + publishLocalTask(Task.anon { + Option(localIvyRepo).map(os.Path(_, Task.workspace)) })() Result.Success(()) } @@ -134,11 +134,11 @@ trait PublishModule extends JavaModule { outer => /** * Publish artifacts the local ivy repository. */ - def publishLocalCached: T[Seq[PathRef]] = T { - publishLocalTask(T.task(None))().map(p => PathRef(p).withRevalidateOnce) + def publishLocalCached: T[Seq[PathRef]] = Task { + publishLocalTask(Task.anon(None))().map(p => PathRef(p).withRevalidateOnce) } - private def publishLocalTask(localIvyRepo: Task[Option[os.Path]]): Task[Seq[Path]] = T.task { + private def publishLocalTask(localIvyRepo: Task[Option[os.Path]]): Task[Seq[Path]] = Task.anon { val publisher = localIvyRepo() match { case None => LocalIvyPublisher case Some(path) => new LocalIvyPublisher(path) @@ -160,9 +160,9 @@ trait PublishModule extends JavaModule { outer => * @return [[PathRef]]s to published files. */ def publishM2Local(m2RepoPath: String = (os.home / ".m2" / "repository").toString()) - : Command[Seq[PathRef]] = T.command { - publishM2LocalTask(T.task { - os.Path(m2RepoPath, T.workspace) + : Command[Seq[PathRef]] = Task.command { + publishM2LocalTask(Task.anon { + os.Path(m2RepoPath, Task.workspace) })() } @@ -170,13 +170,13 @@ trait PublishModule extends JavaModule { outer => * Publish artifacts to the local Maven repository. * @return [[PathRef]]s to published files. */ - def publishM2LocalCached: T[Seq[PathRef]] = T { - publishM2LocalTask(T.task { - os.Path(os.home / ".m2" / "repository", T.workspace) + def publishM2LocalCached: T[Seq[PathRef]] = Task { + publishM2LocalTask(Task.anon { + os.Path(os.home / ".m2" / "repository", Task.workspace) })() } - private def publishM2LocalTask(m2RepoPath: Task[os.Path]): Task[Seq[PathRef]] = T.task { + private def publishM2LocalTask(m2RepoPath: Task[os.Path]): Task[Seq[PathRef]] = Task.anon { val path = m2RepoPath() new LocalM2Publisher(path) .publish( @@ -194,10 +194,10 @@ trait PublishModule extends JavaModule { outer => def sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots" def publishArtifacts: T[PublishModule.PublishData] = { - val baseNameTask: Task[String] = T.task { s"${artifactId()}-${publishVersion()}" } + val baseNameTask: Task[String] = Task.anon { s"${artifactId()}-${publishVersion()}" } val defaultPayloadTask: Task[Seq[(PathRef, String)]] = pomPackagingType match { - case PackagingType.Pom => T.task { Seq.empty[(PathRef, String)] } - case PackagingType.Jar | _ => T.task { + case PackagingType.Pom => Task.anon { Seq.empty[(PathRef, String)] } + case PackagingType.Jar | _ => Task.anon { val baseName = baseNameTask() Seq( jar() -> s"$baseName.jar", @@ -207,7 +207,7 @@ trait PublishModule extends JavaModule { outer => ) } } - T { + Task { val baseName = baseNameTask() PublishModule.PublishData( meta = artifactMetadata(), @@ -245,7 +245,7 @@ trait PublishModule extends JavaModule { outer => connectTimeout: Int = 5000, awaitTimeout: Int = 120 * 1000, stagingRelease: Boolean = true - ): define.Command[Unit] = T.command { + ): define.Command[Unit] = Task.command { val PublishModule.PublishData(artifactInfo, artifacts) = publishArtifacts() new SonatypePublisher( sonatypeUri, @@ -255,15 +255,15 @@ trait PublishModule extends JavaModule { outer => if (gpgArgs.isEmpty) PublishModule.defaultGpgArgs else gpgArgs, readTimeout, connectTimeout, - T.log, - T.workspace, - T.env, + Task.log, + Task.workspace, + Task.env, awaitTimeout, stagingRelease ).publish(artifacts.map { case (a, b) => (a.path, b) }, artifactInfo, release) } - override def manifest: T[JarManifest] = T { + override def manifest: T[JarManifest] = Task { import java.util.jar.Attributes.Name val pom = pomSettings() super.manifest().add( @@ -317,8 +317,8 @@ object PublishModule extends ExternalModule { connectTimeout: Int = 5000, awaitTimeout: Int = 120 * 1000, stagingRelease: Boolean = true - ): Command[Unit] = T.command { - val x: Seq[(Seq[(os.Path, String)], Artifact)] = T.sequence(publishArtifacts.value)().map { + ): Command[Unit] = Task.command { + val x: Seq[(Seq[(os.Path, String)], Artifact)] = Task.sequence(publishArtifacts.value)().map { case PublishModule.PublishData(a, s) => (s.map { case (p, f) => (p.path, f) }, a) } new SonatypePublisher( @@ -329,9 +329,9 @@ object PublishModule extends ExternalModule { getFinalGpgArgs(gpgArgs), readTimeout, connectTimeout, - T.log, - T.workspace, - T.env, + Task.log, + Task.workspace, + Task.env, awaitTimeout, stagingRelease ).publishAll( @@ -349,10 +349,10 @@ object PublishModule extends ExternalModule { argsAsString.split(",").toIndexedSeq } - private def getSonatypeCredsFromEnv: Task[(String, String)] = T.task { + private def getSonatypeCredsFromEnv: Task[(String, String)] = Task.anon { (for { - username <- T.env.get(USERNAME_ENV_VARIABLE_NAME) - password <- T.env.get(PASSWORD_ENV_VARIABLE_NAME) + username <- Task.env.get(USERNAME_ENV_VARIABLE_NAME) + password <- Task.env.get(PASSWORD_ENV_VARIABLE_NAME) } yield { Result.Success((username, password)) }).getOrElse( @@ -368,7 +368,7 @@ object PublishModule extends ExternalModule { (username, password) <- getSonatypeCredsFromEnv } yield s"$username:$password" } else { - T.task { + Task.anon { if (sonatypeCreds.split(":").length >= 2) { Result.Success(sonatypeCreds) } else { diff --git a/scalalib/src/mill/scalalib/RunModule.scala b/scalalib/src/mill/scalalib/RunModule.scala index 20b841b8ed7..c8b99975ad4 100644 --- a/scalalib/src/mill/scalalib/RunModule.scala +++ b/scalalib/src/mill/scalalib/RunModule.scala @@ -14,26 +14,26 @@ trait RunModule extends WithZincWorker { /** * Any command-line parameters you want to pass to the forked JVM. */ - def forkArgs: T[Seq[String]] = T { Seq.empty[String] } + def forkArgs: T[Seq[String]] = Task { Seq.empty[String] } /** * Any environment variables you want to pass to the forked JVM. */ - def forkEnv: T[Map[String, String]] = T.input { T.env } + def forkEnv: T[Map[String, String]] = Task.input { Task.env } - def forkWorkingDir: T[os.Path] = T { T.workspace } + def forkWorkingDir: T[os.Path] = Task { Task.workspace } /** * All classfiles and resources including upstream modules and dependencies * necessary to run this module's code. */ - def runClasspath: T[Seq[PathRef]] = T { Seq.empty[PathRef] } + def runClasspath: T[Seq[PathRef]] = Task { Seq.empty[PathRef] } /** * The elements of the run classpath which are local to this module. * This is typically the output of a compilation step and bundles runtime resources. */ - def localRunClasspath: T[Seq[PathRef]] = T { Seq.empty[PathRef] } + def localRunClasspath: T[Seq[PathRef]] = Task { Seq.empty[PathRef] } /** * Allows you to specify an explicit main class to use for the `run` command. @@ -42,11 +42,11 @@ trait RunModule extends WithZincWorker { */ def mainClass: T[Option[String]] = None - def allLocalMainClasses: T[Seq[String]] = T { + def allLocalMainClasses: T[Seq[String]] = Task { zincWorker().worker().discoverMainClasses(localRunClasspath().map(_.path)) } - def finalMainClassOpt: T[Either[String, String]] = T { + def finalMainClassOpt: T[Either[String, String]] = Task { mainClass() match { case Some(m) => Right(m) case None => @@ -62,7 +62,7 @@ trait RunModule extends WithZincWorker { } } - def finalMainClass: T[String] = T { + def finalMainClass: T[String] = Task { finalMainClassOpt() match { case Right(main) => Result.Success(main) case Left(msg) => Result.Failure(msg) @@ -72,13 +72,13 @@ trait RunModule extends WithZincWorker { /** * Control whether `run*`-targets should use an args file to pass command line args, if possible. */ - def runUseArgsFile: T[Boolean] = T { scala.util.Properties.isWin } + def runUseArgsFile: T[Boolean] = Task { scala.util.Properties.isWin } /** * Runs this module's code in a subprocess and waits for it to finish */ - def run(args: Task[Args] = T.task(Args())): Command[Unit] = T.command { - runForkedTask(finalMainClass, args) + def run(args: Task[Args] = Task.anon(Args())): Command[Unit] = Task.command { + runForkedTask(finalMainClass, args)() } /** @@ -87,39 +87,39 @@ trait RunModule extends WithZincWorker { * since the code can dirty the parent Mill process and potentially leave it * in a bad state. */ - def runLocal(args: Task[Args] = T.task(Args())): Command[Unit] = T.command { - runLocalTask(finalMainClass, args) + def runLocal(args: Task[Args] = Task.anon(Args())): Command[Unit] = Task.command { + runLocalTask(finalMainClass, args)() } /** * Same as `run`, but lets you specify a main class to run */ def runMain(mainClass: String, args: String*): Command[Unit] = { - val task = runForkedTask(T.task { mainClass }, T.task { Args(args) }) - T.command { task } + val task = runForkedTask(Task.anon { mainClass }, Task.anon { Args(args) }) + Task.command { task() } } /** * Same as `runBackground`, but lets you specify a main class to run */ def runMainBackground(mainClass: String, args: String*): Command[Unit] = { - val task = runBackgroundTask(T.task { mainClass }, T.task { Args(args) }) - T.command { task } + val task = runBackgroundTask(Task.anon { mainClass }, Task.anon { Args(args) }) + Task.command { task() } } /** * Same as `runLocal`, but lets you specify a main class to run */ def runMainLocal(mainClass: String, args: String*): Command[Unit] = { - val task = runLocalTask(T.task { mainClass }, T.task { Args(args) }) - T.command { task } + val task = runLocalTask(Task.anon { mainClass }, Task.anon { Args(args) }) + Task.command { task() } } /** * Runs this module's code in a subprocess and waits for it to finish */ - def runForkedTask(mainClass: Task[String], args: Task[Args] = T.task(Args())): Task[Unit] = - T.task { + def runForkedTask(mainClass: Task[String], args: Task[Args] = Task.anon(Args())): Task[Unit] = + Task.anon { try Result.Success( Jvm.runSubprocess( mainClass(), @@ -136,8 +136,8 @@ trait RunModule extends WithZincWorker { } } - def runLocalTask(mainClass: Task[String], args: Task[Args] = T.task(Args())): Task[Unit] = - T.task { + def runLocalTask(mainClass: Task[String], args: Task[Args] = Task.anon(Args())): Task[Unit] = + Task.anon { Jvm.runLocal( mainClass(), runClasspath().map(_.path), @@ -145,10 +145,10 @@ trait RunModule extends WithZincWorker { ) } - def runBackgroundTask(mainClass: Task[String], args: Task[Args] = T.task(Args())): Task[Unit] = - T.task { + def runBackgroundTask(mainClass: Task[String], args: Task[Args] = Task.anon(Args())): Task[Unit] = + Task.anon { doRunBackground( - taskDest = T.dest, + taskDest = Task.dest, runClasspath = runClasspath(), zwBackgroundWrapperClasspath = zincWorker().backgroundWrapperClasspath(), forkArgs = forkArgs(), @@ -156,12 +156,12 @@ trait RunModule extends WithZincWorker { finalMainClass = mainClass(), forkWorkingDir = forkWorkingDir(), runUseArgsFile = runUseArgsFile(), - backgroundOutputs = backgroundOutputs(T.dest) - )(args().value: _*)(T.ctx()) + backgroundOutputs = backgroundOutputs(Task.dest) + )(args().value: _*)(Task.ctx()) // Make sure to sleep a bit in the Mill test suite to allow the servers we // start time to initialize before we proceed with the following commands - if (T.env.contains("MILL_TEST_SUITE")) { + if (Task.env.contains("MILL_TEST_SUITE")) { println("runBackgroundTask SLEEPING 10000") Thread.sleep(5000) } diff --git a/scalalib/src/mill/scalalib/SbtModule.scala b/scalalib/src/mill/scalalib/SbtModule.scala index be9bf0df839..0f64691d200 100644 --- a/scalalib/src/mill/scalalib/SbtModule.scala +++ b/scalalib/src/mill/scalalib/SbtModule.scala @@ -1,13 +1,13 @@ package mill.scalalib -import mill.T +import mill.{Task, T} /** * A [[ScalaModule]] with sbt compatible directory layout. */ trait SbtModule extends ScalaModule with MavenModule { - override def sources = T.sources( + override def sources = Task.sources( millSourcePath / "src" / "main" / "scala", millSourcePath / "src" / "main" / "java" ) @@ -15,7 +15,7 @@ trait SbtModule extends ScalaModule with MavenModule { type SbtTests = SbtModuleTests @deprecated("Use SbtTests instead", since = "Mill 0.11.10") trait SbtModuleTests extends ScalaTests with MavenTests { - override def sources = T.sources( + override def sources = Task.sources( millSourcePath / "src" / "test" / "scala", millSourcePath / "src" / "test" / "java" ) diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala index ac78703feb1..4899ad7d7c2 100644 --- a/scalalib/src/mill/scalalib/ScalaModule.scala +++ b/scalalib/src/mill/scalalib/ScalaModule.scala @@ -29,12 +29,12 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => type ScalaModuleTests = ScalaTests trait ScalaTests extends JavaModuleTests with ScalaModule { - override def scalaOrganization: Target[String] = outer.scalaOrganization() - override def scalaVersion: Target[String] = outer.scalaVersion() - override def scalacPluginIvyDeps: Target[Agg[Dep]] = outer.scalacPluginIvyDeps() - override def scalacPluginClasspath: Target[Agg[PathRef]] = outer.scalacPluginClasspath() - override def scalacOptions: Target[Seq[String]] = outer.scalacOptions() - override def mandatoryScalacOptions: Target[Seq[String]] = outer.mandatoryScalacOptions() + override def scalaOrganization: Task[String] = outer.scalaOrganization() + override def scalaVersion: Task[String] = outer.scalaVersion() + override def scalacPluginIvyDeps: Task[Agg[Dep]] = outer.scalacPluginIvyDeps() + override def scalacPluginClasspath: Task[Agg[PathRef]] = outer.scalacPluginClasspath() + override def scalacOptions: Task[Seq[String]] = outer.scalacOptions() + override def mandatoryScalacOptions: Task[Seq[String]] = outer.mandatoryScalacOptions() } /** @@ -42,7 +42,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => * * @return */ - def scalaOrganization: T[String] = T { + def scalaOrganization: T[String] = Task { if (ZincWorkerUtil.isDotty(scalaVersion())) "ch.epfl.lamp" else @@ -52,7 +52,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => /** * All individual source files fed into the Zinc compiler. */ - override def allSourceFiles: T[Seq[PathRef]] = T { + override def allSourceFiles: T[Seq[PathRef]] = Task { Lib.findSourceFiles(allSources(), Seq("scala", "java")).map(PathRef(_)) } @@ -61,7 +61,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => */ def scalaVersion: T[String] - override def mapDependencies: Task[coursier.Dependency => coursier.Dependency] = T.task { + override def mapDependencies: Task[coursier.Dependency => coursier.Dependency] = Task.anon { super.mapDependencies().andThen { d: coursier.Dependency => val artifacts = if (ZincWorkerUtil.isDotty(scalaVersion())) @@ -82,12 +82,12 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => } override def resolveCoursierDependency: Task[Dep => coursier.Dependency] = - T.task { + Task.anon { Lib.depToDependency(_: Dep, scalaVersion(), platformSuffix()) } override def resolvePublishDependency: Task[Dep => publish.Dependency] = - T.task { + Task.anon { publish.Artifact.fromDep( _: Dep, scalaVersion(), @@ -107,12 +107,12 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => """The option to pass to the scala compiler, e.g. "-Xlint:help". Default: "-help"""" ) args: String* - ): Command[Unit] = T.command { + ): Command[Unit] = Task.command { val sv = scalaVersion() // TODO: do we need to handle compiler plugins? val options: Seq[String] = if (args.isEmpty) Seq("-help") else args - T.log.info( + Task.log.info( s"""Output of scalac version: ${sv} | with options: ${options.mkString(" ")} |""".stripMargin @@ -160,20 +160,20 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => /** * Allows you to make use of Scala compiler plugins. */ - def scalacPluginIvyDeps: Target[Agg[Dep]] = T { Agg.empty[Dep] } + def scalacPluginIvyDeps: Task[Agg[Dep]] = Task { Agg.empty[Dep] } - def scalaDocPluginIvyDeps: Target[Agg[Dep]] = T { scalacPluginIvyDeps() } + def scalaDocPluginIvyDeps: Task[Agg[Dep]] = Task { scalacPluginIvyDeps() } /** * Mandatory command-line options to pass to the Scala compiler * that shouldn't be removed by overriding `scalacOptions` */ - protected def mandatoryScalacOptions: Target[Seq[String]] = T { Seq.empty[String] } + protected def mandatoryScalacOptions: Task[Seq[String]] = Task { Seq.empty[String] } /** * Scalac options to activate the compiler plugins. */ - private def enablePluginScalacOptions: Target[Seq[String]] = T { + private def enablePluginScalacOptions: Task[Seq[String]] = Task { val resolvedJars = defaultResolver().resolveDeps( scalacPluginIvyDeps().map(_.exclude("*" -> "*")) @@ -184,7 +184,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => /** * Scalac options to activate the compiler plugins for ScalaDoc generation. */ - private def enableScalaDocPluginScalacOptions: Target[Seq[String]] = T { + private def enableScalaDocPluginScalacOptions: Task[Seq[String]] = Task { val resolvedJars = defaultResolver().resolveDeps( scalaDocPluginIvyDeps().map(_.exclude("*" -> "*")) ) @@ -195,20 +195,20 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => * Command-line options to pass to the Scala compiler defined by the user. * Consumers should use `allScalacOptions` to read them. */ - override def scalacOptions: Target[Seq[String]] = T { Seq.empty[String] } + override def scalacOptions: Task[Seq[String]] = Task { Seq.empty[String] } /** * Aggregation of all the options passed to the Scala compiler. * In most cases, instead of overriding this Target you want to override `scalacOptions` instead. */ - def allScalacOptions: Target[Seq[String]] = T { + def allScalacOptions: Task[Seq[String]] = Task { mandatoryScalacOptions() ++ enablePluginScalacOptions() ++ scalacOptions() } /** * Options to pass directly into Scaladoc. */ - def scalaDocOptions: T[Seq[String]] = T { + def scalaDocOptions: T[Seq[String]] = Task { val defaults = if (ZincWorkerUtil.isDottyOrScala3(scalaVersion())) Seq( @@ -224,14 +224,14 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => * additional jars here if you have some copiler plugin that isn't present * on maven central */ - def scalacPluginClasspath: T[Agg[PathRef]] = T { + def scalacPluginClasspath: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps(scalacPluginIvyDeps()) } /** * Classpath of the scaladoc (or dottydoc) tool. */ - def scalaDocClasspath: T[Agg[PathRef]] = T { + def scalaDocClasspath: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps( Lib.scalaDocIvyDeps(scalaOrganization(), scalaVersion()) ) @@ -240,25 +240,25 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => /** * The ivy coordinates of Scala's own standard library */ - def scalaDocPluginClasspath: T[Agg[PathRef]] = T { + def scalaDocPluginClasspath: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps( scalaDocPluginIvyDeps() ) } - def scalaLibraryIvyDeps: T[Agg[Dep]] = T { + def scalaLibraryIvyDeps: T[Agg[Dep]] = Task { Lib.scalaRuntimeIvyDeps(scalaOrganization(), scalaVersion()) } /** Adds the Scala Library is a mandatory dependency. */ - override def mandatoryIvyDeps: T[Agg[Dep]] = T { + override def mandatoryIvyDeps: T[Agg[Dep]] = Task { super.mandatoryIvyDeps() ++ scalaLibraryIvyDeps() } /** * Classpath of the Scala Compiler & any compiler plugins */ - def scalaCompilerClasspath: T[Agg[PathRef]] = T { + def scalaCompilerClasspath: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps( Lib.scalaCompilerIvyDeps(scalaOrganization(), scalaVersion()) ++ scalaLibraryIvyDeps() @@ -266,9 +266,9 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => } // Keep in sync with [[bspCompileClassesPath]] - override def compile: T[CompilationResult] = T.persistent { + override def compile: T[CompilationResult] = Task.persistent { val sv = scalaVersion() - if (sv == "2.12.4") T.log.error( + if (sv == "2.12.4") Task.log.error( """Attention: Zinc is known to not work properly for Scala version 2.12.4. |You may want to select another version. Upgrading to a more recent Scala version is recommended. |For details, see: https://github.com/sbt/zinc/issues/1010""".stripMargin @@ -285,7 +285,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => scalacOptions = allScalacOptions(), compilerClasspath = scalaCompilerClasspath(), scalacPluginClasspath = scalacPluginClasspath(), - reporter = T.reporter.apply(hashCode), + reporter = Task.reporter.apply(hashCode), reportCachedProblems = zincReportCachedProblems(), incrementalCompilation = zincIncrementalCompilation(), auxiliaryClassFileExtensions = zincAuxiliaryClassFileExtensions() @@ -294,31 +294,31 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => /** the path to the compiled classes without forcing the compilation. */ @internal - override def bspCompileClassesPath: Target[UnresolvedPath] = + override def bspCompileClassesPath: Task[UnresolvedPath] = if (compile.ctx.enclosing == s"${classOf[ScalaModule].getName}#compile") { - T { - T.log.debug( + Task { + Task.log.debug( s"compile target was not overridden, assuming hard-coded classes directory for target ${compile}" ) UnresolvedPath.DestPath(os.sub / "classes", compile.ctx.segments, compile.ctx.foreign) } } else { - T { - T.log.debug( + Task { + Task.log.debug( s"compile target was overridden, need to actually execute compilation to get the compiled classes directory for target ${compile}" ) UnresolvedPath.ResolvedPath(compile().classes.path) } } - override def docSources: T[Seq[PathRef]] = T.sources { + override def docSources: T[Seq[PathRef]] = Task.sources { if ( ZincWorkerUtil.isScala3(scalaVersion()) && !ZincWorkerUtil.isScala3Milestone(scalaVersion()) ) Seq(compile().classes) else allSources() } - override def docJar: T[PathRef] = T { + override def docJar: T[PathRef] = Task { val compileCp = Seq( "-classpath", compileClasspath() @@ -329,7 +329,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => ) def packageWithZinc(options: Seq[String], files: Seq[os.Path], javadocDir: os.Path) = { - if (files.isEmpty) Result.Success(createJar(Agg(javadocDir))(T.dest)) + if (files.isEmpty) Result.Success(createJar(Agg(javadocDir))(Task.dest)) else { zincWorker() .worker() @@ -341,7 +341,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => options ++ compileCp ++ scalaDocOptions() ++ files.map(_.toString()) ) match { - case true => Result.Success(createJar(Agg(javadocDir))(T.dest)) + case true => Result.Success(createJar(Agg(javadocDir))(Task.dest)) case false => Result.Failure("docJar generation failed") } } @@ -350,7 +350,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => if ( ZincWorkerUtil.isDotty(scalaVersion()) || ZincWorkerUtil.isScala3Milestone(scalaVersion()) ) { // dottydoc - val javadocDir = T.dest / "javadoc" + val javadocDir = Task.dest / "javadoc" os.makeDir.all(javadocDir) for { @@ -374,14 +374,14 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => ) } else if (ZincWorkerUtil.isScala3(scalaVersion())) { // scaladoc 3 - val javadocDir = T.dest / "javadoc" + val javadocDir = Task.dest / "javadoc" os.makeDir.all(javadocDir) // Scaladoc 3 allows including static files in documentation, but it only // supports one directory. Hence, to allow users to generate files // dynamically, we consolidate all files from all `docSources` into one // directory. - val combinedStaticDir = T.dest / "static" + val combinedStaticDir = Task.dest / "static" os.makeDir.all(combinedStaticDir) for { @@ -410,7 +410,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => javadocDir ) } else { // scaladoc 2 - val javadocDir = T.dest / "javadoc" + val javadocDir = Task.dest / "javadoc" os.makeDir.all(javadocDir) packageWithZinc( @@ -431,7 +431,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => * Opens up a Scala console with your module and all dependencies present, * for you to test and operate your code interactively. */ - def console(): Command[Unit] = T.command { + def console(): Command[Unit] = Task.command { if (!Util.isInteractive()) { Result.Failure("console needs to be run with the -i/--interactive flag") } else { @@ -460,26 +460,26 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => * Ammonite's version used in the `repl` command is by default * set to the one Mill is built against. */ - def ammoniteVersion: T[String] = T { + def ammoniteVersion: T[String] = Task { Versions.ammonite } /** * Dependencies that are necessary to run the Ammonite Scala REPL */ - def ammoniteReplClasspath: T[Seq[PathRef]] = T { + def ammoniteReplClasspath: T[Seq[PathRef]] = Task { localClasspath() ++ transitiveLocalClasspath() ++ unmanagedClasspath() ++ resolvedAmmoniteReplIvyDeps() } - def resolvedAmmoniteReplIvyDeps = T { + def resolvedAmmoniteReplIvyDeps = Task { defaultResolver().resolveDeps { val scaVersion = scalaVersion() val ammVersion = ammoniteVersion() if (scaVersion != BuildInfo.scalaVersion && ammVersion == Versions.ammonite) { - T.log.info( + Task.log.info( s"""Resolving Ammonite Repl ${ammVersion} for Scala ${scaVersion} ... |If you encounter dependency resolution failures, please review/override `def ammoniteVersion` to select a compatible release.""".stripMargin ) @@ -491,7 +491,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => } @internal - private[scalalib] def ammoniteMainClass: Task[String] = T.task { + private[scalalib] def ammoniteMainClass: Task[String] = Task.anon { Version(ammoniteVersion()) match { case v: ValidVersion if Version.versionOrdering.compare(v, Version("2.4.1")) <= 0 => "ammonite.Main" @@ -504,12 +504,12 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => * for you to test and operate your code interactively. * Use [[ammoniteVersion]] to customize the Ammonite version to use. */ - def repl(replOptions: String*): Command[Unit] = T.command { - if (T.log.inStream == DummyInputStream) { + def repl(replOptions: String*): Command[Unit] = Task.command { + if (Task.log.inStream == DummyInputStream) { Result.Failure("repl needs to be run with the -i/--interactive flag") } else { val mainClass = ammoniteMainClass() - T.log.debug(s"Using ammonite main class: ${mainClass}") + Task.log.debug(s"Using ammonite main class: ${mainClass}") SystemStreams.withStreams(SystemStreams.original) { Jvm.runSubprocess( mainClass = mainClass, @@ -533,12 +533,12 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => /** * What Scala version string to use when publishing */ - def artifactScalaVersion: T[String] = T { + def artifactScalaVersion: T[String] = Task { if (crossFullScalaVersion()) scalaVersion() else ZincWorkerUtil.scalaBinaryVersion(scalaVersion()) } - override def zincAuxiliaryClassFileExtensions: T[Seq[String]] = T { + override def zincAuxiliaryClassFileExtensions: T[Seq[String]] = Task { super.zincAuxiliaryClassFileExtensions() ++ ( if (ZincWorkerUtil.isScala3(scalaVersion())) Seq("tasty") else Seq.empty[String] @@ -558,7 +558,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => if (all.value) Seq(ammonite) else Seq() - T.command { + Task.command { super.prepareOffline(all)() // resolve the compile bridge jar defaultResolver().resolveDeps( @@ -572,12 +572,12 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => scalaOrganization(), repositoriesTask() ) - T.sequence(tasks)() + Task.sequence(tasks)() () } } - override def manifest: T[JarManifest] = T { + override def manifest: T[JarManifest] = Task { super.manifest().add("Scala-Version" -> scalaVersion()) } @@ -589,7 +589,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => ) @internal - override def bspBuildTargetData: Task[Option[(String, AnyRef)]] = T.task { + override def bspBuildTargetData: Task[Option[(String, AnyRef)]] = Task.anon { Some(( "scala", ScalaBuildTarget( @@ -615,13 +615,13 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => override def semanticDbScalaVersion: T[String] = scalaVersion() - override protected def semanticDbPluginClasspath = T { + override protected def semanticDbPluginClasspath = Task { defaultResolver().resolveDeps( scalacPluginIvyDeps() ++ semanticDbPluginIvyDeps() ) } - override def semanticDbData: T[PathRef] = T.persistent { + override def semanticDbData: T[PathRef] = Task.persistent { val sv = scalaVersion() val scalacOptions = ( @@ -632,7 +632,7 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => } else { Seq( "-Yrangepos", - s"-P:semanticdb:sourceroot:${T.workspace}", + s"-P:semanticdb:sourceroot:${Task.workspace}", "-Ystop-after:semanticdb-typer" ) } @@ -642,8 +642,8 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => val javacOpts = SemanticDbJavaModule.javacOptionsTask(javacOptions(), semanticDbJavaVersion()) - T.log.debug(s"effective scalac options: ${scalacOptions}") - T.log.debug(s"effective javac options: ${javacOpts}") + Task.log.debug(s"effective scalac options: ${scalacOptions}") + Task.log.debug(s"effective javac options: ${javacOpts}") zincWorker().worker() .compileMixed( @@ -665,8 +665,8 @@ trait ScalaModule extends JavaModule with TestModule.ScalaModuleBase { outer => .map(compileRes => SemanticDbJavaModule.copySemanticdbFiles( compileRes.classes.path, - T.workspace, - T.dest / "data" + Task.workspace, + Task.dest / "data" ) ) } diff --git a/scalalib/src/mill/scalalib/SemanticDbJavaModule.scala b/scalalib/src/mill/scalalib/SemanticDbJavaModule.scala index 346c1eb383c..a0267e83f83 100644 --- a/scalalib/src/mill/scalalib/SemanticDbJavaModule.scala +++ b/scalalib/src/mill/scalalib/SemanticDbJavaModule.scala @@ -1,12 +1,12 @@ package mill.scalalib import mill.api.{PathRef, Result, experimental} -import mill.define.{ModuleRef, Target} +import mill.define.ModuleRef import mill.main.BuildInfo import mill.scalalib.api.{CompilationResult, Versions, ZincWorkerUtil} import mill.scalalib.bsp.BspBuildTarget import mill.util.Version -import mill.{Agg, T} +import mill.{Agg, T, Task} import scala.util.Properties @@ -22,18 +22,18 @@ trait SemanticDbJavaModule extends CoursierModule { def javacOptions: T[Seq[String]] def compileClasspath: T[Agg[PathRef]] - def semanticDbVersion: T[String] = T.input { + def semanticDbVersion: T[String] = Task.input { val builtin = SemanticDbJavaModule.buildTimeSemanticDbVersion - val requested = T.env.getOrElse[String]( + val requested = Task.env.getOrElse[String]( "SEMANTICDB_VERSION", SemanticDbJavaModule.contextSemanticDbVersion.get().getOrElse(builtin) ) Version.chooseNewest(requested, builtin)(Version.IgnoreQualifierOrdering) } - def semanticDbJavaVersion: T[String] = T.input { + def semanticDbJavaVersion: T[String] = Task.input { val builtin = SemanticDbJavaModule.buildTimeJavaSemanticDbVersion - val requested = T.env.getOrElse[String]( + val requested = Task.env.getOrElse[String]( "JAVASEMANTICDB_VERSION", SemanticDbJavaModule.contextJavaSemanticDbVersion.get().getOrElse(builtin) ) @@ -42,7 +42,7 @@ trait SemanticDbJavaModule extends CoursierModule { def semanticDbScalaVersion: T[String] = BuildInfo.scalaVersion - protected def semanticDbPluginIvyDeps: T[Agg[Dep]] = T { + protected def semanticDbPluginIvyDeps: T[Agg[Dep]] = Task { val sv = semanticDbScalaVersion() val semDbVersion = semanticDbVersion() if (!ZincWorkerUtil.isScala3(sv) && semDbVersion.isEmpty) { @@ -62,7 +62,7 @@ trait SemanticDbJavaModule extends CoursierModule { } } - private def semanticDbJavaPluginIvyDeps: T[Agg[Dep]] = T { + private def semanticDbJavaPluginIvyDeps: T[Agg[Dep]] = Task { val sv = semanticDbJavaVersion() if (sv.isEmpty) { val msg = @@ -82,28 +82,28 @@ trait SemanticDbJavaModule extends CoursierModule { /** * Scalac options to activate the compiler plugins. */ - protected def semanticDbEnablePluginScalacOptions: T[Seq[String]] = T { + protected def semanticDbEnablePluginScalacOptions: T[Seq[String]] = Task { val resolvedJars = defaultResolver().resolveDeps( semanticDbPluginIvyDeps().map(_.exclude("*" -> "*")) ) resolvedJars.iterator.map(jar => s"-Xplugin:${jar.path}").toSeq } - protected def semanticDbPluginClasspath: T[Agg[PathRef]] = T { + protected def semanticDbPluginClasspath: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps(semanticDbPluginIvyDeps()) } - protected def resolvedSemanticDbJavaPluginIvyDeps: T[Agg[PathRef]] = T { + protected def resolvedSemanticDbJavaPluginIvyDeps: T[Agg[PathRef]] = Task { defaultResolver().resolveDeps(semanticDbJavaPluginIvyDeps()) } - def semanticDbData: T[PathRef] = T.persistent { + def semanticDbData: T[PathRef] = Task.persistent { val javacOpts = SemanticDbJavaModule.javacOptionsTask(javacOptions(), semanticDbJavaVersion()) // we currently assume, we don't do incremental java compilation - os.remove.all(T.dest / "classes") + os.remove.all(Task.dest / "classes") - T.log.debug(s"effective javac options: ${javacOpts}") + Task.log.debug(s"effective javac options: ${javacOpts}") zincWorker().worker() .compileJava( @@ -116,13 +116,13 @@ trait SemanticDbJavaModule extends CoursierModule { reportCachedProblems = zincReportCachedProblems(), incrementalCompilation = zincIncrementalCompilation() ).map(r => - SemanticDbJavaModule.copySemanticdbFiles(r.classes.path, T.workspace, T.dest / "data") + SemanticDbJavaModule.copySemanticdbFiles(r.classes.path, Task.workspace, Task.dest / "data") ) } // keep in sync with bspCompiledClassesAndSemanticDbFiles - def compiledClassesAndSemanticDbFiles: Target[PathRef] = T { - val dest = T.dest + def compiledClassesAndSemanticDbFiles: Task[PathRef] = Task { + val dest = Task.dest val classes = compile().classes.path val sems = semanticDbData().path if (os.exists(sems)) os.copy(sems, dest, mergeFolders = true) @@ -131,12 +131,12 @@ trait SemanticDbJavaModule extends CoursierModule { } // keep in sync with compiledClassesAndSemanticDbFiles - def bspCompiledClassesAndSemanticDbFiles: Target[UnresolvedPath] = { + def bspCompiledClassesAndSemanticDbFiles: Task[UnresolvedPath] = { if ( compiledClassesAndSemanticDbFiles.ctx.enclosing == s"${classOf[SemanticDbJavaModule].getName}#compiledClassesAndSemanticDbFiles" ) { - T { - T.log.debug( + Task { + Task.log.debug( s"compiledClassesAndSemanticDbFiles target was not overridden, assuming hard-coded classes directory for target ${compiledClassesAndSemanticDbFiles}" ) UnresolvedPath.DestPath( @@ -146,8 +146,8 @@ trait SemanticDbJavaModule extends CoursierModule { ) } } else { - T { - T.log.debug( + Task { + Task.log.debug( s"compiledClassesAndSemanticDbFiles target was overridden, need to actually execute compilation to get the compiled classes directory for target ${compiledClassesAndSemanticDbFiles}" ) UnresolvedPath.ResolvedPath(compiledClassesAndSemanticDbFiles().path) diff --git a/scalalib/src/mill/scalalib/TestModule.scala b/scalalib/src/mill/scalalib/TestModule.scala index 6cf615286c3..79cbcb3dff6 100644 --- a/scalalib/src/mill/scalalib/TestModule.scala +++ b/scalalib/src/mill/scalalib/TestModule.scala @@ -1,11 +1,11 @@ package mill.scalalib import mill.api.{Ctx, PathRef, Result} -import mill.define.{Command, Task, TaskModule} +import mill.define.{Command, TaskModule} import mill.scalalib.bsp.{BspBuildTarget, BspModule} import mill.testrunner.{Framework, TestArgs, TestResult, TestRunner, TestRunnerUtils} import mill.util.Jvm -import mill.{Agg, T} +import mill.{Agg, T, Task} import sbt.testing.Status import java.time.format.DateTimeFormatter @@ -28,7 +28,7 @@ trait TestModule * The classpath containing the tests. This is most likely the output of the compilation target. * By default this uses the result of [[localRunClasspath]], which is most likely the result of a local compilation. */ - def testClasspath: T[Seq[PathRef]] = T { localRunClasspath() } + def testClasspath: T[Seq[PathRef]] = Task { localRunClasspath() } /** * The test framework to use. @@ -46,7 +46,7 @@ trait TestModule */ def testFramework: T[String] - def discoveredTestClasses: T[Seq[String]] = T { + def discoveredTestClasses: T[Seq[String]] = Task { val classes = Jvm.inprocess( runClasspath().map(_.path), classLoaderOverrideSbtTesting = true, @@ -71,14 +71,14 @@ trait TestModule * @see [[testCached]] */ def test(args: String*): Command[(String, Seq[TestResult])] = - T.command { - testTask(T.task { args }, T.task { Seq.empty[String] })() + Task.command { + testTask(Task.anon { args }, Task.anon { Seq.empty[String] })() } /** * Args to be used by [[testCached]]. */ - def testCachedArgs: T[Seq[String]] = T { Seq[String]() } + def testCachedArgs: T[Seq[String]] = Task { Seq[String]() } /** * Discovers and runs the module's tests in a subprocess, reporting the @@ -86,8 +86,8 @@ trait TestModule * If no input has changed since the last run, no test were executed. * @see [[test()]] */ - def testCached: T[(String, Seq[TestResult])] = T { - testTask(testCachedArgs, T.task { Seq.empty[String] })() + def testCached: T[(String, Seq[TestResult])] = Task { + testTask(testCachedArgs, Task.anon { Seq.empty[String] })() } /** @@ -106,8 +106,8 @@ trait TestModule val (s, t) = args.splitAt(pos) (s, t.tail) } - T.command { - testTask(T.task { testArgs }, T.task { selector })() + Task.command { + testTask(Task.anon { testArgs }, Task.anon { selector })() } } @@ -115,7 +115,7 @@ trait TestModule * Controls whether the TestRunner should receive it's arguments via an args-file instead of a as long parameter list. * Defaults to what `runUseArgsFile` return. */ - def testUseArgsFile: T[Boolean] = T { runUseArgsFile() || scala.util.Properties.isWin } + def testUseArgsFile: T[Boolean] = Task { runUseArgsFile() || scala.util.Properties.isWin } /** * Sets the file name for the generated JUnit-compatible test report. @@ -140,8 +140,8 @@ trait TestModule args: Task[Seq[String]], globSelectors: Task[Seq[String]] ): Task[(String, Seq[TestResult])] = - T.task { - val outputPath = T.dest / "out.json" + Task.anon { + val outputPath = Task.dest / "out.json" val useArgsFile = testUseArgsFile() val (jvmArgs, props: Map[String, String]) = @@ -169,9 +169,9 @@ trait TestModule arguments = args(), sysProps = props, outputPath = outputPath, - colored = T.log.colored, + colored = Task.log.colored, testCp = testClasspath().map(_.path), - home = T.home, + home = Task.home, globSelectors = selectors ) @@ -179,7 +179,7 @@ trait TestModule .map(_.path.toNIO.toUri.toURL) .mkString(",") - val argsFile = T.dest / "testargs" + val argsFile = Task.dest / "testargs" os.write(argsFile, upickle.default.write(testArgs)) val mainArgs = Seq(testRunnerClasspathArg, argsFile.toString) @@ -193,7 +193,7 @@ trait TestModule jvmArgs = jvmArgs, envArgs = Map( "MILL_TEST_RESOURCE_FOLDER" -> resources().map(_.path).mkString(";"), - "MILL_TEST_DEST_FOLDER" -> T.dest.toString() + "MILL_TEST_DEST_FOLDER" -> Task.dest.toString() ) ++ forkEnv(), mainArgs = mainArgs, workingDir = if (testSandboxWorkingDir()) T.dest / "sandbox" else forkWorkingDir(), @@ -212,7 +212,7 @@ trait TestModule Result.Failure( s"Test selector does not match any test: ${selectors.mkString(" ")}" + "\nRun discoveredTestClasses to see available tests" ) - } else TestModule.handleResults(doneMsg, results, T.ctx(), testReportXml()) + } else TestModule.handleResults(doneMsg, results, Task.ctx(), testReportXml()) } catch { case e: Throwable => Result.Failure("Test reporting failed: " + e) @@ -223,15 +223,15 @@ trait TestModule * Discovers and runs the module's tests in-process in an isolated classloader, * reporting the results to the console */ - def testLocal(args: String*): Command[(String, Seq[TestResult])] = T.command { + def testLocal(args: String*): Command[(String, Seq[TestResult])] = Task.command { val (doneMsg, results) = TestRunner.runTestFramework( Framework.framework(testFramework()), runClasspath().map(_.path), Agg.from(testClasspath().map(_.path)), args, - T.testReporter + Task.testReporter ) - TestModule.handleResults(doneMsg, results, T.ctx(), testReportXml()) + TestModule.handleResults(doneMsg, results, Task.ctx(), testReportXml()) } override def bspBuildTarget: BspBuildTarget = { @@ -256,7 +256,7 @@ object TestModule { */ trait TestNg extends TestModule { override def testFramework: T[String] = "mill.testng.TestNGFramework" - override def ivyDeps: T[Agg[Dep]] = T { + override def ivyDeps: T[Agg[Dep]] = Task { super.ivyDeps() ++ Agg( ivy"com.lihaoyi:mill-contrib-testng:${mill.api.BuildInfo.millVersion}" ) @@ -269,7 +269,7 @@ object TestModule { */ trait Junit4 extends TestModule { override def testFramework: T[String] = "com.novocode.junit.JUnitFramework" - override def ivyDeps: T[Agg[Dep]] = T { + override def ivyDeps: T[Agg[Dep]] = Task { super.ivyDeps() ++ Agg(ivy"${mill.scalalib.api.Versions.sbtTestInterface}") } } @@ -280,7 +280,7 @@ object TestModule { */ trait Junit5 extends TestModule { override def testFramework: T[String] = "com.github.sbt.junit.jupiter.api.JupiterFramework" - override def ivyDeps: T[Agg[Dep]] = T { + override def ivyDeps: T[Agg[Dep]] = Task { super.ivyDeps() ++ Agg(ivy"${mill.scalalib.api.Versions.jupiterInterface}") } } @@ -299,7 +299,7 @@ object TestModule { */ trait Specs2 extends ScalaModuleBase with TestModule { override def testFramework: T[String] = "org.specs2.runner.Specs2Framework" - override def scalacOptions = T { + override def scalacOptions = Task { super.scalacOptions() ++ Seq("-Yrangepos") } } diff --git a/scalalib/src/mill/scalalib/UnidocModule.scala b/scalalib/src/mill/scalalib/UnidocModule.scala index 078af652c9e..e04217e2e34 100644 --- a/scalalib/src/mill/scalalib/UnidocModule.scala +++ b/scalalib/src/mill/scalalib/UnidocModule.scala @@ -11,14 +11,14 @@ trait UnidocModule extends ScalaModule { def unidocVersion: T[Option[String]] = None - def unidocCommon(local: Boolean) = T.task { + def unidocCommon(local: Boolean) = Task.anon { def unidocCompileClasspath = - Seq(compile().classes) ++ T.traverse(moduleDeps)(_.compileClasspath)().flatten + Seq(compile().classes) ++ Task.traverse(moduleDeps)(_.compileClasspath)().flatten val unidocSourceFiles = - allSourceFiles() ++ T.traverse(moduleDeps)(_.allSourceFiles)().flatten + allSourceFiles() ++ Task.traverse(moduleDeps)(_.allSourceFiles)().flatten - T.log.info(s"Staging scaladoc for ${unidocSourceFiles.length} files") + Task.log.info(s"Staging scaladoc for ${unidocSourceFiles.length} files") // the details of the options and zincWorker call are significantly // different between scala-2 scaladoc and scala-3 scaladoc @@ -27,7 +27,7 @@ trait UnidocModule extends ScalaModule { "-doc-title", "Mill", "-d", - T.dest.toString, + Task.dest.toString, "-classpath", unidocCompileClasspath.map(_.path).mkString(sys.props("path.separator")) ) ++ @@ -41,7 +41,7 @@ trait UnidocModule extends ScalaModule { "-doc-source-url", url + "€{FILE_PATH}.scala", "-sourcepath", - T.workspace.toString + Task.workspace.toString ) } @@ -52,24 +52,24 @@ trait UnidocModule extends ScalaModule { scalacPluginClasspath(), options ++ unidocSourceFiles.map(_.path.toString) ) match { - case true => mill.api.Result.Success(PathRef(T.dest)) + case true => mill.api.Result.Success(PathRef(Task.dest)) case false => mill.api.Result.Failure("unidoc generation failed") } } - def unidocLocal = T { + def unidocLocal = Task { unidocCommon(true)() - PathRef(T.dest) + PathRef(Task.dest) } - def unidocSite = T { + def unidocSite = Task { unidocCommon(false)() for { sourceUrl <- unidocSourceUrl() - p <- os.walk(T.dest) if p.ext == "scala" + p <- os.walk(Task.dest) if p.ext == "scala" } { - os.write(p, os.read(p).replace(s"file://${T.workspace}", sourceUrl)) + os.write(p, os.read(p).replace(s"file://${Task.workspace}", sourceUrl)) } - PathRef(T.dest) + PathRef(Task.dest) } } diff --git a/scalalib/src/mill/scalalib/ZincWorkerModule.scala b/scalalib/src/mill/scalalib/ZincWorkerModule.scala index 0ce66219da3..7f15aa140a3 100644 --- a/scalalib/src/mill/scalalib/ZincWorkerModule.scala +++ b/scalalib/src/mill/scalalib/ZincWorkerModule.scala @@ -15,7 +15,7 @@ import mill.util.Util.millProjectModule * A default implementation of [[ZincWorkerModule]] */ object ZincWorkerModule extends ExternalModule with ZincWorkerModule with CoursierModule { - lazy val millDiscover = Discover[this.type] + lazy val millDiscover: Discover[this.type] = Discover[this.type] } /** @@ -23,19 +23,19 @@ object ZincWorkerModule extends ExternalModule with ZincWorkerModule with Coursi */ trait ZincWorkerModule extends mill.Module with OfflineSupportModule { self: CoursierModule => - def classpath: T[Agg[PathRef]] = T { + def classpath: T[Agg[PathRef]] = Task { millProjectModule("mill-scalalib-worker", repositoriesTask()) } - def scalalibClasspath: T[Agg[PathRef]] = T { + def scalalibClasspath: T[Agg[PathRef]] = Task { millProjectModule("mill-scalalib", repositoriesTask()) } - def testrunnerEntrypointClasspath: T[Agg[PathRef]] = T { + def testrunnerEntrypointClasspath: T[Agg[PathRef]] = Task { millProjectModule("mill-testrunner-entrypoint", repositoriesTask(), artifactSuffix = "") } - def backgroundWrapperClasspath: T[Agg[PathRef]] = T { + def backgroundWrapperClasspath: T[Agg[PathRef]] = Task { millProjectModule( "mill-scalalib-backgroundwrapper", repositoriesTask(), @@ -43,10 +43,10 @@ trait ZincWorkerModule extends mill.Module with OfflineSupportModule { self: Cou ) } - def zincLogDebug: T[Boolean] = T.input(T.ctx().log.debugEnabled) + def zincLogDebug: T[Boolean] = Task.input(Task.ctx().log.debugEnabled) - def worker: Worker[ZincWorkerApi] = T.worker { - val jobs = T.ctx() match { + def worker: Worker[ZincWorkerApi] = Task.worker { + val jobs = Task.ctx() match { case j: Ctx.Jobs => j.jobs case _ => 1 } @@ -71,7 +71,7 @@ trait ZincWorkerModule extends mill.Module with OfflineSupportModule { self: Cou ) .newInstance( Left(( - T.ctx(), + Task.ctx(), (x: String, y: String) => scalaCompilerBridgeJar(x, y, repositoriesTask()) .asSuccess @@ -167,14 +167,14 @@ trait ZincWorkerModule extends mill.Module with OfflineSupportModule { self: Cou } else dep } - override def prepareOffline(all: Flag): Command[Unit] = T.command { + override def prepareOffline(all: Flag): Command[Unit] = Task.command { super.prepareOffline(all)() classpath() () } def prepareOfflineCompiler(scalaVersion: String, scalaOrganization: String): Command[Unit] = - T.command { + Task.command { classpath() scalaCompilerBridgeJar(scalaVersion, scalaOrganization, repositoriesTask()) () diff --git a/scalalib/src/mill/scalalib/bsp/BspModule.scala b/scalalib/src/mill/scalalib/bsp/BspModule.scala index 461cac10676..67c48422551 100644 --- a/scalalib/src/mill/scalalib/bsp/BspModule.scala +++ b/scalalib/src/mill/scalalib/bsp/BspModule.scala @@ -36,7 +36,7 @@ trait BspModule extends Module { * - [[ScalaBuildTarget]] */ @internal - def bspBuildTargetData: Task[Option[(String, AnyRef)]] = T.task { None } + def bspBuildTargetData: Task[Option[(String, AnyRef)]] = Task.anon { None } } diff --git a/scalalib/src/mill/scalalib/bsp/ScalaMetalsSupport.scala b/scalalib/src/mill/scalalib/bsp/ScalaMetalsSupport.scala index 2db73ff3438..3a523786082 100644 --- a/scalalib/src/mill/scalalib/bsp/ScalaMetalsSupport.scala +++ b/scalalib/src/mill/scalalib/bsp/ScalaMetalsSupport.scala @@ -1,8 +1,7 @@ package mill.scalalib.bsp import mill.api.experimental -import mill.{Agg, T} -import mill.define.Target +import mill.{Agg, T, Task} import mill.scalalib.{Dep, DepSyntax, ScalaModule} import mill.api.Result import mill.scalalib.api.ZincWorkerUtil @@ -16,7 +15,7 @@ import mill.scalalib.api.ZincWorkerUtil ) trait ScalaMetalsSupport extends ScalaModule { - override def scalacPluginIvyDeps: Target[Agg[Dep]] = T { + override def scalacPluginIvyDeps: Task[Agg[Dep]] = Task { val sv = scalaVersion() val semDbVersion = semanticDbVersion() val superRes = super.scalacPluginIvyDeps() @@ -40,18 +39,18 @@ trait ScalaMetalsSupport extends ScalaModule { } /** Adds some options and configures the semanticDB plugin. */ - override def mandatoryScalacOptions: Target[Seq[String]] = T { + override def mandatoryScalacOptions: Task[Seq[String]] = Task { super.mandatoryScalacOptions() ++ { if (ZincWorkerUtil.isScala3(scalaVersion())) { Seq("-Xsemanticdb") } else { - Seq("-Yrangepos", s"-P:semanticdb:sourceroot:${T.workspace}") + Seq("-Yrangepos", s"-P:semanticdb:sourceroot:${Task.workspace}") } } } /** Filters options unsupported by Metals. */ - override def allScalacOptions: Target[Seq[String]] = T { + override def allScalacOptions: Task[Seq[String]] = Task { super.allScalacOptions().filterNot(_ == "-Xfatal-warnings") } } diff --git a/scalalib/src/mill/scalalib/dependency/versions/VersionsFinder.scala b/scalalib/src/mill/scalalib/dependency/versions/VersionsFinder.scala index 6fa52636b9d..57b0813e605 100644 --- a/scalalib/src/mill/scalalib/dependency/versions/VersionsFinder.scala +++ b/scalalib/src/mill/scalalib/dependency/versions/VersionsFinder.scala @@ -1,11 +1,11 @@ package mill.scalalib.dependency.versions -import mill.define.{BaseModule, Task} +import mill.define.BaseModule import mill.eval.Evaluator import mill.scalalib.dependency.metadata.{MetadataLoader, MetadataLoaderFactory} import mill.scalalib.{JavaModule, Lib} import mill.api.Ctx.{Home, Log} -import mill.T +import mill.{Task, T} import java.util.concurrent.atomic.AtomicInteger @@ -40,8 +40,10 @@ private[dependency] object VersionsFinder { private def resolveDeps(progress: Progress)( javaModule: JavaModule ): Task[ResolvedDependencies] = - T.task { - T.log.ticker(s"Resolving dependencies [${progress.next()}/${progress.count}]: ${javaModule}") + Task.anon { + Task.log.ticker( + s"Resolving dependencies [${progress.next()}/${progress.count}]: ${javaModule}" + ) val bindDependency = javaModule.bindDependency() val deps = javaModule.ivyDeps() @@ -61,7 +63,7 @@ private[dependency] object VersionsFinder { mapDependencies = Some(mapDeps), customizer = custom, coursierCacheCustomizer = cacheCustom, - ctx = Some(T.log) + ctx = Some(Task.log) ) (javaModule, metadataLoaders, dependencies) @@ -69,11 +71,11 @@ private[dependency] object VersionsFinder { private def resolveVersions(progres: Progress)( resolvedDependencies: ResolvedDependencies - ): Task[ModuleDependenciesVersions] = T.task { + ): Task[ModuleDependenciesVersions] = Task.anon { val (javaModule, metadataLoaders, dependencies) = resolvedDependencies val versions = dependencies.map { dependency => - T.log.ticker( + Task.log.ticker( s"Analyzing dependencies [${progres.next()}/${progres.count}]: ${javaModule} / ${dependency.module}" ) val currentVersion = Version(dependency.version) diff --git a/scalalib/src/mill/scalalib/giter8/Giter8Module.scala b/scalalib/src/mill/scalalib/giter8/Giter8Module.scala index 900e3974a3e..4a2efa76abf 100644 --- a/scalalib/src/mill/scalalib/giter8/Giter8Module.scala +++ b/scalalib/src/mill/scalalib/giter8/Giter8Module.scala @@ -1,6 +1,6 @@ package mill.scalalib.giter8 -import mill.T +import mill.{Task, T} import mill.define.{Command, Discover, ExternalModule} import mill.util.Jvm import mill.scalalib.api.ZincWorkerUtil @@ -9,13 +9,13 @@ import mill.main.BuildInfo import mill.api.Loose object Giter8Module extends ExternalModule with Giter8Module { - lazy val millDiscover: Discover[this.type] = Discover[this.type] + val millDiscover: Discover[this.type] = Discover[this.type] } trait Giter8Module extends CoursierModule { - def init(args: String*): Command[Unit] = T.command { - T.log.info("Creating a new project...") + def init(args: String*): Command[Unit] = Task.command { + Task.log.info("Creating a new project...") val giter8Dependencies = defaultResolver().resolveDeps { val scalaBinVersion = ZincWorkerUtil.scalaBinaryVersion(BuildInfo.scalaVersion) Loose.Agg(ivy"org.foundweekends.giter8:giter8_${scalaBinVersion}:0.14.0" @@ -26,7 +26,7 @@ trait Giter8Module extends CoursierModule { "giter8.Giter8", giter8Dependencies.map(_.path), mainArgs = args, - workingDir = T.workspace + workingDir = Task.workspace ) } } diff --git a/scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala b/scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala index 46ecea74d22..0480ab42c42 100644 --- a/scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala +++ b/scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala @@ -7,7 +7,7 @@ import mill.scalalib._ trait ScalafmtModule extends JavaModule { - def reformat(): Command[Unit] = T.command { + def reformat(): Command[Unit] = Task.command { ScalafmtWorkerModule .worker() .reformat( @@ -16,7 +16,7 @@ trait ScalafmtModule extends JavaModule { ) } - def checkFormat(): Command[Unit] = T.command { + def checkFormat(): Command[Unit] = Task.command { ScalafmtWorkerModule .worker() .checkFormat( @@ -25,13 +25,13 @@ trait ScalafmtModule extends JavaModule { ) } - def scalafmtConfig: T[Seq[PathRef]] = T.sources( - T.workspace / ".scalafmt.conf", + def scalafmtConfig: T[Seq[PathRef]] = Task.sources( + Task.workspace / ".scalafmt.conf", os.pwd / ".scalafmt.conf" ) // TODO: Do we want provide some defaults or write a default file? - private[ScalafmtModule] def resolvedScalafmtConfig: Task[PathRef] = T.task { + private[ScalafmtModule] def resolvedScalafmtConfig: Task[PathRef] = Task.anon { val locs = scalafmtConfig() locs.find(p => os.exists(p.path)) match { case None => Result.Failure( @@ -69,8 +69,8 @@ trait ScalafmtModule extends JavaModule { object ScalafmtModule extends ExternalModule with ScalafmtModule { def reformatAll(sources: mill.main.Tasks[Seq[PathRef]]): Command[Unit] = - T.command { - val files = T.sequence(sources.value)().flatMap(filesToFormat) + Task.command { + val files = Task.sequence(sources.value)().flatMap(filesToFormat) ScalafmtWorkerModule .worker() .reformat( @@ -80,8 +80,8 @@ object ScalafmtModule extends ExternalModule with ScalafmtModule { } def checkFormatAll(sources: mill.main.Tasks[Seq[PathRef]]): Command[Unit] = - T.command { - val files = T.sequence(sources.value)().flatMap(filesToFormat) + Task.command { + val files = Task.sequence(sources.value)().flatMap(filesToFormat) ScalafmtWorkerModule .worker() .checkFormat( @@ -90,5 +90,5 @@ object ScalafmtModule extends ExternalModule with ScalafmtModule { ) } - lazy val millDiscover: Discover[this.type] = Discover[this.type] + val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/scalalib/src/mill/scalalib/scalafmt/ScalafmtWorker.scala b/scalalib/src/mill/scalalib/scalafmt/ScalafmtWorker.scala index e141581d491..52c36f15bc2 100644 --- a/scalalib/src/mill/scalalib/scalafmt/ScalafmtWorker.scala +++ b/scalalib/src/mill/scalalib/scalafmt/ScalafmtWorker.scala @@ -9,9 +9,9 @@ import scala.collection.mutable import mill.api.Result object ScalafmtWorkerModule extends ExternalModule { - def worker: Worker[ScalafmtWorker] = T.worker { new ScalafmtWorker() } + def worker: Worker[ScalafmtWorker] = Task.worker { new ScalafmtWorker() } - lazy val millDiscover: Discover[this.type] = Discover[this.type] + val millDiscover: Discover[this.type] = Discover[this.type] } private[scalafmt] class ScalafmtWorker extends AutoCloseable { diff --git a/scalalib/test/src/mill/scalalib/AssemblyTests.scala b/scalalib/test/src/mill/scalalib/AssemblyTests.scala index f42797b0c32..e05cd1901e3 100644 --- a/scalalib/test/src/mill/scalalib/AssemblyTests.scala +++ b/scalalib/test/src/mill/scalalib/AssemblyTests.scala @@ -3,6 +3,7 @@ package mill.scalalib import scala.util.Properties import mill._ import mill.api.Result +import mill.define.Discover import mill.eval.Evaluator import mill.util.{Jvm, TestEvaluator, TestUtil} import utest._ @@ -20,7 +21,7 @@ object AssemblyTests extends TestSuite { object TestCase extends TestUtil.BaseModule { trait Setup extends ScalaModule { def scalaVersion = "2.13.11" - def sources = T.sources(T.workspace / "src") + def sources = Task.sources(Task.workspace / "src") def ivyDeps = super.ivyDeps() ++ Agg( ivy"com.lihaoyi::scalatags:0.8.2", ivy"com.lihaoyi::mainargs:0.4.0", @@ -51,6 +52,7 @@ object AssemblyTests extends TestSuite { object large extends Setup with ExtraDeps } + val millDiscover: Discover[this.type] = Discover[this.type] } val sources = Map( diff --git a/scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala b/scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala index c40ccdb1ddc..92a0555a270 100644 --- a/scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala +++ b/scalalib/test/src/mill/scalalib/CoursierMirrorTests.scala @@ -1,7 +1,8 @@ package mill.scalalib +import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} -import mill.eval.{Evaluator} +import mill.eval.Evaluator import utest._ import utest.framework.TestPath @@ -13,6 +14,8 @@ object CoursierMirrorTests extends TestSuite { object core extends ScalaModule { def scalaVersion = "2.13.12" } + + val millDiscover: Discover[this.type] = Discover[this.type] } def workspaceTest[T]( diff --git a/scalalib/test/src/mill/scalalib/CrossVersionTests.scala b/scalalib/test/src/mill/scalalib/CrossVersionTests.scala index 281155f658e..fe60c696107 100644 --- a/scalalib/test/src/mill/scalalib/CrossVersionTests.scala +++ b/scalalib/test/src/mill/scalalib/CrossVersionTests.scala @@ -1,6 +1,7 @@ package mill.scalalib import mill.Agg +import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} import utest._ import utest.framework.TestPath @@ -116,6 +117,7 @@ object CrossVersionTests extends TestSuite { |""".stripMargin } + val millDiscover: Discover[this.type] = Discover[this.type] } def init()(implicit tp: TestPath) = { diff --git a/scalalib/test/src/mill/scalalib/CycleTests.scala b/scalalib/test/src/mill/scalalib/CycleTests.scala index 9cc85725395..49c3822f99b 100644 --- a/scalalib/test/src/mill/scalalib/CycleTests.scala +++ b/scalalib/test/src/mill/scalalib/CycleTests.scala @@ -1,9 +1,10 @@ package mill.scalalib import mill.api.BuildScriptException +import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} import utest.framework.TestPath -import utest.{TestSuite, Tests, intercept, test, assert} +import utest.{TestSuite, Tests, assert, intercept, test} object CycleTests extends TestSuite { @@ -28,6 +29,8 @@ object CycleTests extends TestSuite { object f extends JavaModule { override def compileModuleDeps = Seq(f) } + + val millDiscover: Discover[this.type] = Discover[this.type] } def workspaceTest[T](m: TestUtil.BaseModule)(t: TestEvaluator => T)(implicit tp: TestPath): T = { diff --git a/scalalib/test/src/mill/scalalib/DottyDocTests.scala b/scalalib/test/src/mill/scalalib/DottyDocTests.scala index 60d46471d2d..1543101077f 100644 --- a/scalalib/test/src/mill/scalalib/DottyDocTests.scala +++ b/scalalib/test/src/mill/scalalib/DottyDocTests.scala @@ -1,6 +1,7 @@ package mill.scalalib import mill._ +import mill.define.Discover import utest._ import utest.framework.TestPath import mill.util.{TestEvaluator, TestUtil} @@ -15,6 +16,8 @@ object DottyDocTests extends TestSuite { object static extends ScalaModule { def scalaVersion = "0.24.0-RC1" } + + val millDiscover: Discover[this.type] = Discover[this.type] } // a project without static docs (i.e. only api docs, no markdown files) @@ -22,17 +25,21 @@ object DottyDocTests extends TestSuite { object empty extends ScalaModule { def scalaVersion = "0.24.0-RC1" } + + val millDiscover: Discover[this.type] = Discover[this.type] } // a project with multiple static doc folders object MultiDocsModule extends TestBase { object multidocs extends ScalaModule { def scalaVersion = "0.24.0-RC1" - def docResources = T.sources( + def docResources = Task.sources( millSourcePath / "docs1", millSourcePath / "docs2" ) } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "dottydoc" diff --git a/scalalib/test/src/mill/scalalib/HelloJavaTests.scala b/scalalib/test/src/mill/scalalib/HelloJavaTests.scala index 84dd9b33a87..ec4bb054848 100644 --- a/scalalib/test/src/mill/scalalib/HelloJavaTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloJavaTests.scala @@ -2,6 +2,7 @@ package mill package scalalib import mill.api.Result +import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} import utest._ import utest.framework.TestPath @@ -20,11 +21,13 @@ object HelloJavaTests extends TestSuite { override def moduleDeps = Seq(core) object test extends JavaModuleTests with TestModule.Junit4 object testJunit5 extends JavaModuleTests with TestModule.Junit5 { - override def ivyDeps: T[Agg[Dep]] = T { + override def ivyDeps: T[Agg[Dep]] = Task { super.ivyDeps() ++ Agg(ivy"org.junit.jupiter:junit-jupiter-params:5.7.0") } } } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "hello-java" diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala index 72ab9e79988..43c964595df 100644 --- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala +++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala @@ -6,7 +6,7 @@ import scala.jdk.CollectionConverters._ import scala.util.{Properties, Using} import mill._ import mill.api.Result -import mill.define.NamedTask +import mill.define.{Discover, NamedTask} import mill.eval.{Evaluator, EvaluatorPaths} import mill.util.{TestEvaluator, TestUtil} import utest._ @@ -30,7 +30,7 @@ object HelloWorldTests extends TestSuite { trait HelloWorldModule extends scalalib.ScalaModule { def scalaVersion = scala212Version - override def semanticDbVersion: T[String] = T { + override def semanticDbVersion: T[String] = Task { // The latest semanticDB release for Scala 2.12.6 "4.1.9" } @@ -44,14 +44,20 @@ object HelloWorldTests extends TestSuite { object HelloWorld extends HelloBase { object core extends HelloWorldModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object SemanticWorld extends HelloBase { object core extends SemanticModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldNonPrecompiledBridge extends HelloBase { object core extends HelloWorldModule { override def scalaVersion = "2.12.1" } + + val millDiscover: Discover[this.type] = Discover[this.type] } object CrossHelloWorld extends HelloBase { object core extends Cross[HelloWorldCross]( @@ -62,6 +68,8 @@ object HelloWorldTests extends TestSuite { scala213Version ) trait HelloWorldCross extends CrossScalaModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object CrossModuleDeps extends HelloBase { object stable extends Cross[Stable](scala212Version, scala32Version) @@ -71,20 +79,28 @@ object HelloWorldTests extends TestSuite { trait CuttingEdge extends CrossScalaModule { def moduleDeps = Seq(stable()) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldDefaultMain extends HelloBase { object core extends HelloWorldModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldWithoutMain extends HelloBase { object core extends HelloWorldModule { override def mainClass = None } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldWithMain extends HelloBase { object core extends HelloWorldModuleWithMain + + val millDiscover: Discover[this.type] = Discover[this.type] } val akkaHttpDeps = Agg(ivy"com.typesafe.akka::akka-http:10.0.13") @@ -94,6 +110,8 @@ object HelloWorldTests extends TestSuite { override def ivyDeps = akkaHttpDeps override def assemblyRules = Seq(Assembly.Rule.Append("reference.conf")) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldAkkaHttpExclude extends HelloBase { @@ -101,6 +119,8 @@ object HelloWorldTests extends TestSuite { override def ivyDeps = akkaHttpDeps override def assemblyRules = Seq(Assembly.Rule.Exclude("reference.conf")) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldAkkaHttpAppendPattern extends HelloBase { @@ -108,6 +128,8 @@ object HelloWorldTests extends TestSuite { override def ivyDeps = akkaHttpDeps override def assemblyRules = Seq(Assembly.Rule.AppendPattern(".*.conf")) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldAkkaHttpExcludePattern extends HelloBase { @@ -115,6 +137,8 @@ object HelloWorldTests extends TestSuite { override def ivyDeps = akkaHttpDeps override def assemblyRules = Seq(Assembly.Rule.ExcludePattern(".*.conf")) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldAkkaHttpRelocate extends HelloBase { @@ -122,6 +146,8 @@ object HelloWorldTests extends TestSuite { override def ivyDeps = akkaHttpDeps override def assemblyRules = Seq(Assembly.Rule.Relocate("akka.**", "shaded.akka.@1")) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldAkkaHttpNoRules extends HelloBase { @@ -129,6 +155,8 @@ object HelloWorldTests extends TestSuite { override def ivyDeps = akkaHttpDeps override def assemblyRules = Seq.empty } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldMultiAppend extends HelloBase { @@ -137,6 +165,8 @@ object HelloWorldTests extends TestSuite { override def assemblyRules = Seq(Assembly.Rule.Append("reference.conf")) } object model extends HelloWorldModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldMultiExclude extends HelloBase { @@ -145,6 +175,8 @@ object HelloWorldTests extends TestSuite { override def assemblyRules = Seq(Assembly.Rule.Exclude("reference.conf")) } object model extends HelloWorldModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldMultiAppendPattern extends HelloBase { @@ -153,6 +185,8 @@ object HelloWorldTests extends TestSuite { override def assemblyRules = Seq(Assembly.Rule.AppendPattern(".*.conf")) } object model extends HelloWorldModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldMultiAppendByPatternWithSeparator extends HelloBase { @@ -161,6 +195,8 @@ object HelloWorldTests extends TestSuite { override def assemblyRules = Seq(Assembly.Rule.AppendPattern(".*.conf", "\n")) } object model extends HelloWorldModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldMultiExcludePattern extends HelloBase { @@ -169,6 +205,8 @@ object HelloWorldTests extends TestSuite { override def assemblyRules = Seq(Assembly.Rule.ExcludePattern(".*.conf")) } object model extends HelloWorldModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldMultiNoRules extends HelloBase { @@ -177,18 +215,24 @@ object HelloWorldTests extends TestSuite { override def assemblyRules = Seq.empty } object model extends HelloWorldModule + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldWarnUnused extends HelloBase { object core extends HelloWorldModule { override def scalacOptions = T(Seq("-Ywarn-unused")) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldFatalWarnings extends HelloBase { object core extends HelloWorldModule { override def scalacOptions = T(Seq("-Ywarn-unused", "-Xfatal-warnings")) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldWithDocVersion extends HelloBase { @@ -196,6 +240,8 @@ object HelloWorldTests extends TestSuite { override def scalacOptions = T(Seq("-Ywarn-unused", "-Xfatal-warnings")) override def scalaDocOptions = super.scalaDocOptions() ++ Seq("-doc-version", "1.2.3") } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldOnlyDocVersion extends HelloBase { @@ -203,18 +249,24 @@ object HelloWorldTests extends TestSuite { override def scalacOptions = T(Seq("-Ywarn-unused", "-Xfatal-warnings")) override def scalaDocOptions = T(Seq("-doc-version", "1.2.3")) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldDocTitle extends HelloBase { object core extends HelloWorldModule { override def scalaDocOptions = T(Seq("-doc-title", "Hello World")) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldScalaOverride extends HelloBase { object core extends HelloWorldModule { - override def scalaVersion: Target[String] = scala213Version + override def scalaVersion: Task[String] = scala213Version } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldIvyDeps extends HelloBase { @@ -225,6 +277,8 @@ object HelloWorldTests extends TestSuite { override def moduleDeps = Seq(moduleA) override def ivyDeps = Agg(ivy"com.lihaoyi::sourcecode:0.1.4") } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldTypeLevel extends HelloBase { @@ -243,6 +297,8 @@ object HelloWorldTests extends TestSuite { ivy"com.typesafe.genjavadoc:::genjavadoc-plugin:0.11" ) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldMacros212 extends HelloBase { @@ -255,6 +311,8 @@ object HelloWorldTests extends TestSuite { ivy"org.scalamacros:::paradise:2.1.0" ) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldMacros213 extends HelloBase { @@ -263,6 +321,8 @@ object HelloWorldTests extends TestSuite { override def ivyDeps = Agg(ivy"com.github.julien-truffaut::monocle-macro::2.1.0") override def scalacOptions = super.scalacOptions() ++ Seq("-Ymacro-annotations") } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldFlags extends HelloBase { @@ -273,6 +333,8 @@ object HelloWorldTests extends TestSuite { "-Ypartial-unification" ) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloWorldColorOutput extends HelloBase { @@ -283,6 +345,8 @@ object HelloWorldTests extends TestSuite { "-Vimplicits" ) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object HelloScalacheck extends HelloBase { @@ -293,6 +357,8 @@ object HelloWorldTests extends TestSuite { override def testFramework = "org.scalacheck.ScalaCheckFramework" } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object Dotty213 extends HelloBase { @@ -301,6 +367,8 @@ object HelloWorldTests extends TestSuite { override def ivyDeps = Agg(ivy"org.scala-lang.modules::scala-xml:1.2.0".withDottyCompat(scalaVersion())) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object AmmoniteReplMainClass extends HelloBase { @@ -312,22 +380,27 @@ object HelloWorldTests extends TestSuite { override def scalaVersion = T("2.13.5") override def ammoniteVersion = T("2.5.0") } + + val millDiscover: Discover[this.type] = Discover[this.type] } object ValidatedTarget extends HelloBase { - private def mkDirWithFile = T.task { - os.write(T.dest / "dummy", "dummy", createFolders = true) - PathRef(T.dest) - } - def uncheckedPathRef: T[PathRef] = T { mkDirWithFile() } - def uncheckedSeqPathRef: T[Seq[PathRef]] = T { Seq(mkDirWithFile()) } - def uncheckedAggPathRef: T[Agg[PathRef]] = T { Agg(mkDirWithFile()) } - def uncheckedTuplePathRef: T[Tuple1[PathRef]] = T { Tuple1(mkDirWithFile()) } - - def checkedPathRef: T[PathRef] = T { mkDirWithFile().withRevalidateOnce } - def checkedSeqPathRef: T[Seq[PathRef]] = T { Seq(mkDirWithFile()).map(_.withRevalidateOnce) } - def checkedAggPathRef: T[Agg[PathRef]] = T { Agg(mkDirWithFile()).map(_.withRevalidateOnce) } - def checkedTuplePathRef: T[Tuple1[PathRef]] = T { Tuple1(mkDirWithFile().withRevalidateOnce) } + private def mkDirWithFile = Task.anon { + os.write(Task.dest / "dummy", "dummy", createFolders = true) + PathRef(Task.dest) + } + def uncheckedPathRef: T[PathRef] = Task { mkDirWithFile() } + def uncheckedSeqPathRef: T[Seq[PathRef]] = Task { Seq(mkDirWithFile()) } + def uncheckedAggPathRef: T[Agg[PathRef]] = Task { Agg(mkDirWithFile()) } + def uncheckedTuplePathRef: T[Tuple1[PathRef]] = Task { Tuple1(mkDirWithFile()) } + + def checkedPathRef: T[PathRef] = Task { mkDirWithFile().withRevalidateOnce } + def checkedSeqPathRef: T[Seq[PathRef]] = Task { Seq(mkDirWithFile()).map(_.withRevalidateOnce) } + def checkedAggPathRef: T[Agg[PathRef]] = Task { Agg(mkDirWithFile()).map(_.withRevalidateOnce) } + def checkedTuplePathRef: T[Tuple1[PathRef]] = + Task { Tuple1(mkDirWithFile().withRevalidateOnce) } + + val millDiscover: Discover[this.type] = Discover[this.type] } object MultiModuleClasspaths extends HelloBase { @@ -337,7 +410,7 @@ object HelloWorldTests extends TestSuite { def ivyDeps = Agg(ivy"com.lihaoyi::sourcecode:0.2.2") def compileIvyDeps = Agg(ivy"com.lihaoyi::geny:0.4.2") def runIvyDeps = Agg(ivy"com.lihaoyi::utest:0.8.4") - def unmanagedClasspath = T { Agg(PathRef(millSourcePath / "unmanaged")) } + def unmanagedClasspath = Task { Agg(PathRef(millSourcePath / "unmanaged")) } } trait BarModule extends ScalaModule { def scalaVersion = "2.13.12" @@ -345,7 +418,7 @@ object HelloWorldTests extends TestSuite { def ivyDeps = Agg(ivy"com.lihaoyi::sourcecode:0.2.1") def compileIvyDeps = Agg(ivy"com.lihaoyi::geny:0.4.1") def runIvyDeps = Agg(ivy"com.lihaoyi::utest:0.8.4") - def unmanagedClasspath = T { Agg(PathRef(millSourcePath / "unmanaged")) } + def unmanagedClasspath = Task { Agg(PathRef(millSourcePath / "unmanaged")) } } trait QuxModule extends ScalaModule { def scalaVersion = "2.13.12" @@ -353,7 +426,7 @@ object HelloWorldTests extends TestSuite { def ivyDeps = Agg(ivy"com.lihaoyi::sourcecode:0.2.0") def compileIvyDeps = Agg(ivy"com.lihaoyi::geny:0.4.0") def runIvyDeps = Agg(ivy"com.lihaoyi::utest:0.8.4") - def unmanagedClasspath = T { Agg(PathRef(millSourcePath / "unmanaged")) } + def unmanagedClasspath = Task { Agg(PathRef(millSourcePath / "unmanaged")) } } object ModMod extends Module { object foo extends FooModule @@ -382,6 +455,8 @@ object HelloWorldTests extends TestSuite { def moduleDeps = Seq(bar) } } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "hello-world" @@ -829,7 +904,7 @@ object HelloWorldTests extends TestSuite { "runIfMainClassProvided" - workspaceTest(HelloWorldWithMain) { eval => val runResult = eval.outPath / "core" / "run.dest" / "hello-mill" val Right((_, evalCount)) = eval.apply( - HelloWorldWithMain.core.run(T.task(Args(runResult.toString))) + HelloWorldWithMain.core.run(Task.anon(Args(runResult.toString))) ) assert(evalCount > 0) @@ -851,7 +926,7 @@ object HelloWorldTests extends TestSuite { // discovered by Zinc and used val runResult = eval.outPath / "core" / "run.dest" / "hello-mill" val Right((_, evalCount)) = eval.apply( - HelloWorldWithoutMain.core.run(T.task(Args(runResult.toString))) + HelloWorldWithoutMain.core.run(Task.anon(Args(runResult.toString))) ) assert(evalCount > 0) @@ -867,7 +942,7 @@ object HelloWorldTests extends TestSuite { "runIfMainClassProvided" - workspaceTest(HelloWorldWithMain) { eval => val runResult = eval.outPath / "core" / "run.dest" / "hello-mill" val Right((_, evalCount)) = eval.apply( - HelloWorldWithMain.core.runLocal(T.task(Args(runResult.toString))) + HelloWorldWithMain.core.runLocal(Task.anon(Args(runResult.toString))) ) assert(evalCount > 0) @@ -880,7 +955,7 @@ object HelloWorldTests extends TestSuite { "runWithDefaultMain" - workspaceTest(HelloWorldDefaultMain) { eval => val runResult = eval.outPath / "core" / "run.dest" / "hello-mill" val Right((_, evalCount)) = eval.apply( - HelloWorldDefaultMain.core.runLocal(T.task(Args(runResult.toString))) + HelloWorldDefaultMain.core.runLocal(Task.anon(Args(runResult.toString))) ) assert(evalCount > 0) @@ -956,7 +1031,7 @@ object HelloWorldTests extends TestSuite { } "assemblyRules" - { - def checkAppend[M <: TestUtil.BaseModule](module: M, target: Target[PathRef]) = + def checkAppend[M <: TestUtil.BaseModule](module: M, target: Task[PathRef]) = workspaceTest(module) { eval => val Right((result, _)) = eval.apply(target) @@ -985,7 +1060,7 @@ object HelloWorldTests extends TestSuite { def checkAppendMulti[M <: TestUtil.BaseModule]( module: M, - target: Target[PathRef] + target: Task[PathRef] ): Unit = workspaceTest( module, @@ -1012,7 +1087,7 @@ object HelloWorldTests extends TestSuite { def checkAppendWithSeparator[M <: TestUtil.BaseModule]( module: M, - target: Target[PathRef] + target: Task[PathRef] ): Unit = workspaceTest( module, @@ -1052,7 +1127,7 @@ object HelloWorldTests extends TestSuite { def checkExclude[M <: TestUtil.BaseModule]( module: M, - target: Target[PathRef], + target: Task[PathRef], resourcePath: os.Path = resourcePath ) = workspaceTest(module, resourcePath) { eval => @@ -1084,7 +1159,7 @@ object HelloWorldTests extends TestSuite { def checkRelocate[M <: TestUtil.BaseModule]( module: M, - target: Target[PathRef], + target: Task[PathRef], resourcePath: os.Path = resourcePath ) = workspaceTest(module, resourcePath) { eval => @@ -1326,7 +1401,7 @@ object HelloWorldTests extends TestSuite { "validated" - { "PathRef" - { - def check(t: Target[PathRef], flip: Boolean) = + def check(t: Task[PathRef], flip: Boolean) = workspaceTest(ValidatedTarget, debug = true) { eval => // we reconstruct faulty behavior val Right((result, _)) = eval.apply(t) @@ -1346,7 +1421,7 @@ object HelloWorldTests extends TestSuite { "checked" - check(ValidatedTarget.checkedPathRef, true) } "SeqPathRef" - { - def check(t: Target[Seq[PathRef]], flip: Boolean) = workspaceTest(ValidatedTarget) { eval => + def check(t: Task[Seq[PathRef]], flip: Boolean) = workspaceTest(ValidatedTarget) { eval => // we reconstruct faulty behavior val Right((result, _)) = eval.apply(t) assert( @@ -1365,7 +1440,7 @@ object HelloWorldTests extends TestSuite { "checked" - check(ValidatedTarget.checkedSeqPathRef, true) } "AggPathRef" - { - def check(t: Target[Agg[PathRef]], flip: Boolean) = workspaceTest(ValidatedTarget) { eval => + def check(t: Task[Agg[PathRef]], flip: Boolean) = workspaceTest(ValidatedTarget) { eval => // we reconstruct faulty behavior val Right((result, _)) = eval.apply(t) assert( @@ -1384,7 +1459,7 @@ object HelloWorldTests extends TestSuite { "checked" - check(ValidatedTarget.checkedAggPathRef, true) } "other" - { - def check(t: Target[Tuple1[PathRef]], flip: Boolean) = workspaceTest(ValidatedTarget) { + def check(t: Task[Tuple1[PathRef]], flip: Boolean) = workspaceTest(ValidatedTarget) { eval => // we reconstruct faulty behavior val Right((result, _)) = eval.apply(t) diff --git a/scalalib/test/src/mill/scalalib/PublishModuleTests.scala b/scalalib/test/src/mill/scalalib/PublishModuleTests.scala index 50961ecf539..e2d6ca894c3 100644 --- a/scalalib/test/src/mill/scalalib/PublishModuleTests.scala +++ b/scalalib/test/src/mill/scalalib/PublishModuleTests.scala @@ -1,7 +1,8 @@ package mill.scalalib -import mill.{Agg, T} +import mill.{Agg, T, Task} import mill.api.{PathRef, Result} +import mill.define.Discover import mill.eval.Evaluator import mill.scalalib.publish.{ Developer, @@ -29,7 +30,7 @@ object PublishModuleTests extends TestSuite { trait HelloScalaModule extends ScalaModule { def scalaVersion = scala212Version - override def semanticDbVersion: T[String] = T { + override def semanticDbVersion: T[String] = Task { // The latest semanticDB release for Scala 2.12.6 "4.1.9" } @@ -50,10 +51,12 @@ object PublishModuleTests extends TestSuite { ) override def versionScheme = Some(VersionScheme.EarlySemVer) - def checkSonatypeCreds(sonatypeCreds: String) = T.command { - PublishModule.checkSonatypeCreds(sonatypeCreds) + def checkSonatypeCreds(sonatypeCreds: String) = Task.command { + PublishModule.checkSonatypeCreds(sonatypeCreds)() } } + + val millDiscover: Discover[this.type] = Discover[this.type] } object PomOnly extends PublishBase { @@ -75,10 +78,12 @@ object PublishModuleTests extends TestSuite { ivy"org.slf4j:slf4j-api:2.0.7" ) // ensure, these target wont be called - override def jar: T[PathRef] = T { ???.asInstanceOf[PathRef] } - override def docJar: T[PathRef] = T { ???.asInstanceOf[PathRef] } - override def sourceJar: T[PathRef] = T { ???.asInstanceOf[PathRef] } + override def jar: T[PathRef] = Task { ???.asInstanceOf[PathRef] } + override def docJar: T[PathRef] = Task { ???.asInstanceOf[PathRef] } + override def sourceJar: T[PathRef] = Task { ???.asInstanceOf[PathRef] } } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "publish" diff --git a/scalalib/test/src/mill/scalalib/ScalaDoc3Tests.scala b/scalalib/test/src/mill/scalalib/ScalaDoc3Tests.scala index 490cfdb985b..c8adf428f88 100644 --- a/scalalib/test/src/mill/scalalib/ScalaDoc3Tests.scala +++ b/scalalib/test/src/mill/scalalib/ScalaDoc3Tests.scala @@ -1,6 +1,7 @@ package mill.scalalib import mill._ +import mill.define.Discover import utest._ import utest.framework.TestPath import mill.util.{TestEvaluator, TestUtil} @@ -15,6 +16,8 @@ object ScalaDoc3Tests extends TestSuite { object static extends ScalaModule { def scalaVersion = "3.0.0-RC1" } + + val millDiscover: Discover[this.type] = Discover[this.type] } // a project without static docs (i.e. only api docs, no markdown files) @@ -22,17 +25,21 @@ object ScalaDoc3Tests extends TestSuite { object empty extends ScalaModule { def scalaVersion = "3.0.0-RC1" } + + val millDiscover: Discover[this.type] = Discover[this.type] } // a project with multiple static doc folders object MultiDocsModule extends TestBase { object multidocs extends ScalaModule { def scalaVersion = "3.0.0-RC1" - def docResources = T.sources( + def docResources = Task.sources( millSourcePath / "docs1", millSourcePath / "docs2" ) } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "scaladoc3" diff --git a/scalalib/test/src/mill/scalalib/ScalaVersionsRangesTests.scala b/scalalib/test/src/mill/scalalib/ScalaVersionsRangesTests.scala index 6915d5c55b5..0c5185a6e47 100644 --- a/scalalib/test/src/mill/scalalib/ScalaVersionsRangesTests.scala +++ b/scalalib/test/src/mill/scalalib/ScalaVersionsRangesTests.scala @@ -1,8 +1,8 @@ package mill.scalalib import mill._ +import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} - import utest._ import utest.framework.TestPath @@ -17,6 +17,8 @@ object ScalaVersionsRangesTests extends TestSuite { def ivyDeps = Agg(ivy"com.lihaoyi::utest:0.8.4") } } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "scala-versions-ranges" diff --git a/scalalib/test/src/mill/scalalib/TestClassLoaderTests.scala b/scalalib/test/src/mill/scalalib/TestClassLoaderTests.scala index a6ab2888100..83ca46b7020 100644 --- a/scalalib/test/src/mill/scalalib/TestClassLoaderTests.scala +++ b/scalalib/test/src/mill/scalalib/TestClassLoaderTests.scala @@ -1,7 +1,7 @@ package mill.scalalib -import mill.{Agg, T} - +import mill.define.Discover +import mill.{Agg, T, Task} import mill.util.{TestEvaluator, TestUtil} import utest._ import utest.framework.TestPath @@ -13,12 +13,14 @@ object TestClassLoaderTests extends TestSuite { def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) object test extends ScalaTests with TestModule.Utest { - override def ivyDeps = T { + override def ivyDeps = Task { super.ivyDeps() ++ Agg( ivy"com.lihaoyi::utest:${sys.props.getOrElse("TEST_UTEST_VERSION", ???)}" ) } } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "classloader-test" diff --git a/scalalib/test/src/mill/scalalib/TestRunnerTests.scala b/scalalib/test/src/mill/scalalib/TestRunnerTests.scala index f1c153e6574..5fbb57c8c7a 100644 --- a/scalalib/test/src/mill/scalalib/TestRunnerTests.scala +++ b/scalalib/test/src/mill/scalalib/TestRunnerTests.scala @@ -1,8 +1,9 @@ package mill.scalalib import mill.api.Result +import mill.define.Discover import mill.util.{TestEvaluator, TestUtil} -import mill.{Agg, T} +import mill.{Agg, T, Task} import os.Path import sbt.testing.Status import utest._ @@ -18,7 +19,7 @@ object TestRunnerTests extends TestSuite { def scalaVersion = sys.props.getOrElse("TEST_SCALA_2_13_VERSION", ???) object utest extends ScalaTests with TestModule.Utest { - override def ivyDeps = T { + override def ivyDeps = Task { super.ivyDeps() ++ Agg( ivy"com.lihaoyi::utest:${sys.props.getOrElse("TEST_UTEST_VERSION", ???)}" ) @@ -26,7 +27,7 @@ object TestRunnerTests extends TestSuite { } object scalatest extends ScalaTests with TestModule.ScalaTest { - override def ivyDeps = T { + override def ivyDeps = Task { super.ivyDeps() ++ Agg( ivy"org.scalatest::scalatest:${sys.props.getOrElse("TEST_SCALATEST_VERSION", ???)}" ) @@ -34,7 +35,7 @@ object TestRunnerTests extends TestSuite { } trait DoneMessage extends ScalaTests { - override def ivyDeps = T { + override def ivyDeps = Task { super.ivyDeps() ++ Agg( ivy"org.scala-sbt:test-interface:${sys.props.getOrElse("TEST_TEST_INTERFACE_VERSION", ???)}" ) @@ -51,13 +52,15 @@ object TestRunnerTests extends TestSuite { } object ziotest extends ScalaTests with TestModule.ZioTest { - override def ivyDeps = T { + override def ivyDeps = Task { super.ivyDeps() ++ Agg( ivy"dev.zio::zio-test:${sys.props.getOrElse("TEST_ZIOTEST_VERSION", ???)}", ivy"dev.zio::zio-test-sbt:${sys.props.getOrElse("TEST_ZIOTEST_VERSION", ???)}" ) } } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "testrunner" diff --git a/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala b/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala index c126f3c58cf..d998ff7b8ce 100644 --- a/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala +++ b/scalalib/test/src/mill/scalalib/bsp/BspModuleTests.scala @@ -1,13 +1,13 @@ package mill.scalalib.bsp -import mill.define.Cross +import mill.define.{Cross, Discover} import mill.eval.EvaluatorPaths -import mill.{Agg, T} +import mill.{Agg, T, Task} import mill.scalalib.{DepSyntax, JavaModule, ScalaModule} import mill.util.{TestEvaluator, TestUtil} import os.FilePath import utest.framework.TestPath -import utest.{TestSuite, Tests, test, _} +import utest._ object BspModuleTests extends TestSuite { @@ -28,6 +28,8 @@ object BspModuleTests extends TestSuite { override def moduleDeps = Seq(HelloBsp) override def ivyDeps = Agg(ivy"ch.qos.logback:logback-classic:1.1.10") } + + val millDiscover: Discover[this.type] = Discover[this.type] } object InterDeps extends BspBase { @@ -42,6 +44,8 @@ object BspModuleTests extends TestSuite { .filter(c => c < crossValue) .map(i => Mod(i)) } + + val millDiscover: Discover[this.type] = Discover[this.type] } def workspaceTest[T](m: TestUtil.BaseModule)(t: TestEvaluator => T)(implicit tp: TestPath): T = { diff --git a/scalalib/test/src/mill/scalalib/giter8/Giter8Tests.scala b/scalalib/test/src/mill/scalalib/giter8/Giter8Tests.scala index 4e387069b79..4435c2a3eb8 100644 --- a/scalalib/test/src/mill/scalalib/giter8/Giter8Tests.scala +++ b/scalalib/test/src/mill/scalalib/giter8/Giter8Tests.scala @@ -3,6 +3,7 @@ package mill.scalalib.giter8 import mill.util.{TestEvaluator, TestUtil} import utest._ import mill.api.Loose.Agg +import mill.define.Discover import os.Path object Giter8Tests extends TestSuite { @@ -19,6 +20,8 @@ object Giter8Tests extends TestSuite { object g8Module extends TestUtil.BaseModule with Giter8Module { override def millSourcePath: Path = rootDir + + val millDiscover: Discover[this.type] = Discover[this.type] } val evaluator = new TestEvaluator(g8Module) diff --git a/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala b/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala index 700b08c739d..9d92c42e074 100644 --- a/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala +++ b/scalalib/test/src/mill/scalalib/scalafmt/ScalafmtTests.scala @@ -1,6 +1,7 @@ package mill.scalalib.scalafmt import mill._ +import mill.define.Discover import mill.main.Tasks import mill.scalalib.ScalaModule import mill.util.{TestEvaluator, TestUtil} @@ -24,11 +25,13 @@ object ScalafmtTests extends TestSuite { object core extends ScalaModule with ScalafmtModule with BuildSrcModule { def scalaVersion: T[String] = sys.props.getOrElse("TEST_SCALA_2_12_VERSION", ???) - def buildSources: T[Seq[PathRef]] = T.sources { + def buildSources: T[Seq[PathRef]] = Task.sources { millSourcePath / "util.sc" } } + + val millDiscover: Discover[this.type] = Discover[this.type] } val resourcePath = os.pwd / "scalalib" / "test" / "resources" / "scalafmt" diff --git a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala index 8e4a1646da6..b09992aebd6 100644 --- a/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala +++ b/scalanativelib/src/mill/scalanativelib/ScalaNativeModule.scala @@ -4,7 +4,7 @@ package scalanativelib import mainargs.Flag import mill.api.Loose.Agg import mill.api.{Result, internal} -import mill.define.{Command, Target, Task} +import mill.define.{Command, Task} import mill.util.Jvm import mill.util.Util.millProjectModule import mill.scalalib.api.ZincWorkerUtil @@ -33,17 +33,17 @@ trait ScalaNativeModule extends ScalaModule { outer => type ScalaNativeModuleTests = ScalaNativeTests trait ScalaNativeTests extends ScalaTests with TestScalaNativeModule { override def scalaNativeVersion = outer.scalaNativeVersion() - override def releaseMode = T { outer.releaseMode() } - override def logLevel: Target[NativeLogLevel] = outer.logLevel() + override def releaseMode: Task[ReleaseMode] = Task { outer.releaseMode() } + override def logLevel: Task[NativeLogLevel] = outer.logLevel() } def scalaNativeBinaryVersion = - T { ZincWorkerUtil.scalaNativeBinaryVersion(scalaNativeVersion()) } + Task { ZincWorkerUtil.scalaNativeBinaryVersion(scalaNativeVersion()) } def scalaNativeWorkerVersion = - T { ZincWorkerUtil.scalaNativeWorkerVersion(scalaNativeVersion()) } + Task { ZincWorkerUtil.scalaNativeWorkerVersion(scalaNativeVersion()) } - def scalaNativeWorkerClasspath = T { + def scalaNativeWorkerClasspath = Task { millProjectModule( s"mill-scalanativelib-worker-${scalaNativeWorkerVersion()}", repositoriesTask(), @@ -51,7 +51,7 @@ trait ScalaNativeModule extends ScalaModule { outer => ) } - def toolsIvyDeps = T { + def toolsIvyDeps = Task { scalaNativeVersion() match { case v @ ("0.4.0" | "0.4.1") => Result.Failure(s"Scala Native $v is not supported. Please update to 0.4.2+") @@ -66,7 +66,7 @@ trait ScalaNativeModule extends ScalaModule { outer => } } - def nativeIvyDeps: T[Agg[Dep]] = T { + def nativeIvyDeps: T[Agg[Dep]] = Task { val scalaVersionSpecific = { val version = if (scalaNativeVersion().startsWith("0.4")) scalaNativeVersion() @@ -84,7 +84,7 @@ trait ScalaNativeModule extends ScalaModule { outer => ) ++ scalaVersionSpecific } - override def scalaLibraryIvyDeps = T { + override def scalaLibraryIvyDeps: Task[Agg[Dep]] = Task { super.scalaLibraryIvyDeps().map(dep => dep.copy(cross = dep.cross match { case c: CrossVersion.Constant => c.copy(platformed = false) @@ -95,29 +95,29 @@ trait ScalaNativeModule extends ScalaModule { outer => } /** Adds [[nativeIvyDeps]] as mandatory dependencies. */ - override def mandatoryIvyDeps = T { + override def mandatoryIvyDeps = Task { super.mandatoryIvyDeps() ++ nativeIvyDeps() } - def bridgeFullClassPath: T[Agg[PathRef]] = T { + def bridgeFullClassPath: T[Agg[PathRef]] = Task { Lib.resolveDependencies( repositoriesTask(), toolsIvyDeps().map(Lib.depToBoundDep(_, mill.main.BuildInfo.scalaVersion, "")), - ctx = Some(T.log) + ctx = Some(Task.log) ).map(t => (scalaNativeWorkerClasspath() ++ t)) } - private[scalanativelib] def scalaNativeBridge = T.task { + private[scalanativelib] def scalaNativeBridge = Task.anon { ScalaNativeWorkerExternalModule.scalaNativeWorker().bridge(bridgeFullClassPath()) } - override def scalacPluginIvyDeps: T[Agg[Dep]] = T { + override def scalacPluginIvyDeps: T[Agg[Dep]] = Task { super.scalacPluginIvyDeps() ++ Agg( ivy"org.scala-native:::nscplugin:${scalaNativeVersion()}" ) } - def logLevel: Target[NativeLogLevel] = T { NativeLogLevel.Info } + def logLevel: Task[NativeLogLevel] = Task { NativeLogLevel.Info } private def readEnvVariable[T]( env: Map[String, String], @@ -138,55 +138,55 @@ trait ScalaNativeModule extends ScalaModule { outer => } } - protected def releaseModeInput: Target[Option[ReleaseMode]] = T.input { - readEnvVariable[ReleaseMode](T.env, "SCALANATIVE_MODE", ReleaseMode.values, _.value) + protected def releaseModeInput: Task[Option[ReleaseMode]] = Task.input { + readEnvVariable[ReleaseMode](Task.env, "SCALANATIVE_MODE", ReleaseMode.values, _.value) } - def releaseMode: Target[ReleaseMode] = T { + def releaseMode: Task[ReleaseMode] = Task { releaseModeInput().getOrElse(ReleaseMode.Debug) } - def nativeWorkdir = T { T.dest } + def nativeWorkdir = Task { Task.dest } // Location of the clang compiler - def nativeClang = T { + def nativeClang = Task { os.Path( scalaNativeBridge().discoverClang() ) } // Location of the clang++ compiler - def nativeClangPP = T { + def nativeClangPP = Task { os.Path( scalaNativeBridge().discoverClangPP() ) } // GC choice, either "none", "boehm", "immix" or "commix" - protected def nativeGCInput: Target[Option[String]] = T.input { - T.env.get("SCALANATIVE_GC") + protected def nativeGCInput: Task[Option[String]] = Task.input { + Task.env.get("SCALANATIVE_GC") } - def nativeGC = T { + def nativeGC = Task { nativeGCInput().getOrElse( scalaNativeBridge().defaultGarbageCollector() ) } - def nativeTarget: Target[Option[String]] = T { None } + def nativeTarget: Task[Option[String]] = Task { None } // Options that are passed to clang during compilation - def nativeCompileOptions = T { + def nativeCompileOptions = Task { scalaNativeBridge().discoverCompileOptions() } // Options that are passed to clang during linking - def nativeLinkingOptions = T { + def nativeLinkingOptions = Task { scalaNativeBridge().discoverLinkingOptions() } // Whether to link `@stub` methods, or ignore them - def nativeLinkStubs = T { false } + def nativeLinkStubs: Task[Boolean] = Task { false } /** * Shall the resource files be embedded in the resulting binary file? Allows @@ -194,32 +194,32 @@ trait ScalaNativeModule extends ScalaModule { outer => * not embed files with certain extensions, including ".c", ".h", ".scala" * and ".class". */ - def nativeEmbedResources = T { false } + def nativeEmbedResources: Task[Boolean] = Task { false } /** Shall we use the incremental compilation? */ - def nativeIncrementalCompilation = T { false } + def nativeIncrementalCompilation: Task[Boolean] = Task { false } /** Shall linker dump intermediate NIR after every phase? */ - def nativeDump = T { false } + def nativeDump: Task[Boolean] = Task { false } // The LTO mode to use used during a release build - protected def nativeLTOInput: Target[Option[LTO]] = T.input { - readEnvVariable[LTO](T.env, "SCALANATIVE_LTO", LTO.values, _.value) + protected def nativeLTOInput: Task[Option[LTO]] = Task.input { + readEnvVariable[LTO](Task.env, "SCALANATIVE_LTO", LTO.values, _.value) } - def nativeLTO: Target[LTO] = T { nativeLTOInput().getOrElse(LTO.None) } + def nativeLTO: Task[LTO] = Task { nativeLTOInput().getOrElse(LTO.None) } // Shall we optimize the resulting NIR code? - protected def nativeOptimizeInput: Target[Option[Boolean]] = T.input { - readEnvVariable[Boolean](T.env, "SCALANATIVE_OPTIMIZE", Seq(true, false), _.toString) + protected def nativeOptimizeInput: Task[Option[Boolean]] = Task.input { + readEnvVariable[Boolean](Task.env, "SCALANATIVE_OPTIMIZE", Seq(true, false), _.toString) } - def nativeOptimize: Target[Boolean] = T { nativeOptimizeInput().getOrElse(true) } + def nativeOptimize: Task[Boolean] = Task { nativeOptimizeInput().getOrElse(true) } /** Build target for current compilation */ - def nativeBuildTarget: Target[BuildTarget] = T { BuildTarget.Application } + def nativeBuildTarget: Task[BuildTarget] = Task { BuildTarget.Application } - private def nativeConfig: Task[NativeConfig] = T.task { + private def nativeConfig: Task[NativeConfig] = Task.anon { val classpath = runClasspath().map(_.path).filter(_.toIO.exists).toList scalaNativeBridge().config( @@ -264,15 +264,15 @@ trait ScalaNativeModule extends ScalaModule { outer => } // Generates native binary - def nativeLink = T { + def nativeLink = Task { os.Path(scalaNativeBridge().nativeLink( nativeConfig().config, - T.dest.toIO + Task.dest.toIO )) } // Runs the native binary - override def run(args: Task[Args] = T.task(Args())) = T.command { + override def run(args: Task[Args] = Task.anon(Args())) = Task.command { Jvm.runSubprocess( commandArgs = Vector(nativeLink().toString) ++ args().value, envArgs = forkEnv(), @@ -281,7 +281,7 @@ trait ScalaNativeModule extends ScalaModule { outer => } @internal - override def bspBuildTargetData: Task[Option[(String, AnyRef)]] = T.task { + override def bspBuildTargetData: Task[Option[(String, AnyRef)]] = Task.anon { Some(( ScalaBuildTarget.dataKind, ScalaBuildTarget( @@ -295,7 +295,7 @@ trait ScalaNativeModule extends ScalaModule { outer => )) } - override def transitiveIvyDeps: T[Agg[BoundDep]] = T { + override def transitiveIvyDeps: T[Agg[BoundDep]] = Task { // Exclude cross published version dependencies leading to conflicts in Scala 3 vs 2.13 // When using Scala 3 exclude Scala 2.13 standard native libraries, @@ -330,9 +330,9 @@ trait ScalaNativeModule extends ScalaModule { outer => bridgeFullClassPath ) else Seq() - T.command { + Task.command { super.prepareOffline(all)() - T.sequence(tasks)() + Task.sequence(tasks)() () } } @@ -343,12 +343,13 @@ trait ScalaNativeModule extends ScalaModule { outer => } trait TestScalaNativeModule extends ScalaNativeModule with TestModule { - override def resources: T[Seq[PathRef]] = super[ScalaNativeModule].resources - override def testLocal(args: String*) = T.command { test(args: _*) } + override def testLocal(args: String*): Command[(String, Seq[TestResult])] = + Task.command { test(args: _*)() } + override protected def testTask( args: Task[Seq[String]], globSeletors: Task[Seq[String]] - ): Task[(String, Seq[TestResult])] = T.task { + ): Task[(String, Seq[TestResult])] = Task.anon { val (close, framework) = scalaNativeBridge().getFramework( nativeLink().toIO, @@ -362,10 +363,10 @@ trait TestScalaNativeModule extends ScalaNativeModule with TestModule { runClasspath().map(_.path), Agg(compile().classes.path), args(), - T.testReporter, + Task.testReporter, TestRunnerUtils.globFilter(globSeletors()) ) - val res = TestModule.handleResults(doneMsg, results, T.ctx(), testReportXml()) + val res = TestModule.handleResults(doneMsg, results, Task.ctx(), testReportXml()) // Hack to try and let the Scala Native subprocess finish streaming it's stdout // to the JVM. Without this, the stdout can still be streaming when `close()` // is called, and some of the output is dropped onto the floor. diff --git a/scalanativelib/src/mill/scalanativelib/worker/ScalaNativeWorker.scala b/scalanativelib/src/mill/scalanativelib/worker/ScalaNativeWorker.scala index ed731eb20bb..89b87bb118c 100644 --- a/scalanativelib/src/mill/scalanativelib/worker/ScalaNativeWorker.scala +++ b/scalanativelib/src/mill/scalanativelib/worker/ScalaNativeWorker.scala @@ -1,7 +1,7 @@ package mill.scalanativelib.worker import mill.define.{Discover, Worker} -import mill.{Agg, PathRef, T} +import mill.{Agg, PathRef, T, Task} import mill.scalanativelib.worker.{api => workerApi} private[scalanativelib] class ScalaNativeWorker extends AutoCloseable { @@ -41,6 +41,6 @@ private[scalanativelib] class ScalaNativeWorker extends AutoCloseable { } private[scalanativelib] object ScalaNativeWorkerExternalModule extends mill.define.ExternalModule { - def scalaNativeWorker: Worker[ScalaNativeWorker] = T.worker { new ScalaNativeWorker() } - lazy val millDiscover: Discover[this.type] = Discover[this.type] + def scalaNativeWorker: Worker[ScalaNativeWorker] = Task.worker { new ScalaNativeWorker() } + val millDiscover: Discover[this.type] = Discover[this.type] } diff --git a/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala b/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala index 5cbae38ddf8..4afebf636a1 100644 --- a/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala +++ b/scalanativelib/test/src/mill/scalanativelib/HelloNativeWorldTests.scala @@ -56,7 +56,7 @@ object HelloNativeWorldTests extends TestSuite { trait RootModule extends HelloNativeWorldModule { override def artifactName = "hello-native-world" def scalaNativeVersion = sNativeVersion - def releaseMode = T { mode } + def releaseMode = Task { mode } def pomSettings = PomSettings( organization = "com.lihaoyi", description = "hello native world ready for real world publishing", @@ -70,7 +70,7 @@ object HelloNativeWorldTests extends TestSuite { object buildUTest extends Cross[BuildModuleUtest](matrix) trait BuildModuleUtest extends RootModule { object test extends ScalaNativeTests with TestModule.Utest { - override def sources = T.sources { millSourcePath / "src" / "utest" } + override def sources = Task.sources { millSourcePath / "src" / "utest" } override def ivyDeps = super.ivyDeps() ++ Agg( ivy"com.lihaoyi::utest::${ if (scalaNativeVersion().startsWith("0.4")) utestForNative04Version @@ -172,7 +172,7 @@ object HelloNativeWorldTests extends TestSuite { ) } - def runTests(testTask: define.NamedTask[(String, Seq[TestResult])]) + def runTests(testTask: define.Task[(String, Seq[TestResult])]) : Map[String, Map[String, TestResult]] = { val Left(Result.Failure(_, Some(res))) = helloWorldEvaluator(testTask) diff --git a/scalanativelib/test/src/mill/scalanativelib/ScalaTestsErrorTests.scala b/scalanativelib/test/src/mill/scalanativelib/ScalaTestsErrorTests.scala index 37336c2d7da..0a9a2cbfb76 100644 --- a/scalanativelib/test/src/mill/scalanativelib/ScalaTestsErrorTests.scala +++ b/scalanativelib/test/src/mill/scalanativelib/ScalaTestsErrorTests.scala @@ -17,7 +17,7 @@ object ScalaTestsErrorTests extends TestSuite { } } - override lazy val millDiscover = Discover[this.type] + override lazy val millDiscover: Discover[this.type] = Discover[this.type] } def tests: Tests = Tests {