Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Make run command arguments Tasks #2452

Merged
merged 22 commits into from
May 1, 2023
1 change: 0 additions & 1 deletion bsp/src/mill/bsp/BSP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import mill.util.PrintLogger
import os.Path

object BSP extends ExternalModule with CoursierModule with BspServerStarter {
import mill.main.TokenReaders._

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

Expand Down
5 changes: 2 additions & 3 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ import com.google.gson.JsonObject
import mill.T
import mill.api.{DummyTestReporter, PathRef, Result, Strict, internal}
import mill.define.Segment.Label
import mill.define.{Discover, ExternalModule, Module, Segments, Task}
import mill.define.{Args, Discover, ExternalModule, Module, Segments, Task}
import mill.eval.Evaluator
import mill.main.{BspServerResult, MainModule}
import mill.main.TokenReaders._
import mill.scalalib.{JavaModule, SemanticDbJavaModule, TestModule}
import mill.scalalib.bsp.{BspModule, JvmBuildTarget, MillBuildModule, ScalaBuildTarget}
import mill.scalalib.internal.ModuleUtils
Expand Down Expand Up @@ -538,7 +537,7 @@ class MillBuildServer(
case m: JavaModule => m
}.get
val args = params.getArguments.getOrElse(Seq.empty[String])
val runTask = module.run(args: _*)
val runTask = module.run(T.task(Args(args)))
val runResult = evaluator.evaluate(
Strict.Agg(runTask),
Utils.getBspLoggedReporterPool(runParams.getOriginId, bspIdByModule, client),
Expand Down
6 changes: 4 additions & 2 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ object Deps {
val lambdaTest = ivy"de.tototec:de.tobiasroeser.lambdatest:0.8.0"
val log4j2Core = ivy"org.apache.logging.log4j:log4j-core:2.20.0"
val osLib = ivy"com.lihaoyi::os-lib:0.9.1"
val mainargs = ivy"com.lihaoyi::mainargs:0.4.0"
val pprint = ivy"com.lihaoyi::pprint:0.8.1"
val mainargs = ivy"com.lihaoyi::mainargs:0.5.0"
val millModuledefsVersion = "0.10.9"
val millModuledefsString = s"com.lihaoyi::mill-moduledefs:${millModuledefsVersion}"
val millModuledefs = ivy"${millModuledefsString}"
Expand Down Expand Up @@ -649,6 +650,7 @@ object main extends MillModule {
override def ivyDeps = Agg(
Deps.osLib,
Deps.upickle,
Deps.pprint,
Deps.fansi,
Deps.sbtTestInterface
)
Expand Down Expand Up @@ -730,7 +732,7 @@ object main extends MillModule {
}

object testkit extends MillInternalModule with MillAutoTestSetup {
def moduleDeps = Seq(eval, util)
def moduleDeps = Seq(eval, util, main)
}

def testModuleDeps = super.testModuleDeps ++ Seq(testkit)
Expand Down
54 changes: 36 additions & 18 deletions ci/mill-bootstrap.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/build.sc b/build.sc
index 9bde15da2b..419ffbcab4 100644
index b6b06b7584..8c62146aef 100644
--- a/build.sc
+++ b/build.sc
@@ -2,30 +2,21 @@
@@ -2,34 +2,26 @@
import $file.ci.shared
import $file.ci.upload
import $ivy.`org.scalaj::scalaj-http:2.4.2`
Expand All @@ -25,7 +25,8 @@ index 9bde15da2b..419ffbcab4 100644
import coursier.maven.MavenRepository
-import de.tobiasroeser.mill.vcs.version.VcsVersion
import mill._
import mill.define.{Command, Source, Sources, Target, Task}
-import mill.define.{Command, Source, Sources, Target, Task}
+import mill.{Command, Source, Sources, Target, Task}
import mill.eval.Evaluator
import mill.main.MainModule
import mill.scalalib._
Expand All @@ -37,7 +38,13 @@ index 9bde15da2b..419ffbcab4 100644

import scala.util.control.NonFatal
import mill.T
@@ -163,12 +154,8 @@ object Deps {
-import mill.define.{Discover, ExternalModule, Input, Module, Task}
+import mill.define.{Discover, ExternalModule}
+import mill.{Input, Module, Task}
import mill.api.{Logger, Result}
import os.{CommandResult, SubprocessException}

@@ -164,12 +156,8 @@ object Deps {
val requests = ivy"com.lihaoyi::requests:0.8.0"
}

Expand All @@ -52,7 +59,7 @@ index 9bde15da2b..419ffbcab4 100644
def millBinPlatform: T[String] = T {
val tag = millLastTag()
if (tag.contains("-M")) tag
@@ -217,8 +204,8 @@ val buildBridgeScalaVersions =
@@ -218,8 +206,8 @@ val buildBridgeScalaVersions =
if (!buildAllCompilerBridges) Seq()
else bridgeScalaVersions

Expand All @@ -63,7 +70,7 @@ index 9bde15da2b..419ffbcab4 100644
def scalaVersion = crossScalaVersion
def publishVersion = bridgeVersion
def artifactName = T { "mill-scala-compiler-bridge" }
@@ -237,239 +224,25 @@ class BridgeModule(val crossScalaVersion: String) extends PublishModule with Cro
@@ -238,239 +226,25 @@ class BridgeModule(val crossScalaVersion: String) extends PublishModule with Cro
def generatedSources = T {
import mill.scalalib.api.ZincWorkerUtil.{grepJar, scalaBinaryVersion}
val resolvedJars = resolveDeps(
Expand Down Expand Up @@ -308,7 +315,7 @@ index 9bde15da2b..419ffbcab4 100644
def commonPomSettings(artifactName: String) = {
PomSettings(
description = artifactName,
@@ -523,27 +296,8 @@ trait MillCoursierModule extends CoursierModule {
@@ -524,27 +298,8 @@ trait MillCoursierModule extends CoursierModule {
)
}

Expand Down Expand Up @@ -337,7 +344,7 @@ index 9bde15da2b..419ffbcab4 100644
}

/** A Module compiled with applied Mill-specific compiler plugins: mill-moduledefs. */
@@ -859,8 +613,10 @@ object scalajslib extends MillModule with BuildInfo {
@@ -861,8 +616,10 @@ object scalajslib extends MillModule with BuildInfo {
override def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("1")
Expand All @@ -349,7 +356,7 @@ index 9bde15da2b..419ffbcab4 100644
override def ivyDeps = Agg(
Deps.Scalajs_1.scalajsLinker,
Deps.Scalajs_1.scalajsSbtTestAdapter,
@@ -926,8 +682,10 @@ object contrib extends MillModule {
@@ -928,8 +685,10 @@ object contrib extends MillModule {

object api extends MillPublishModule

Expand All @@ -362,7 +369,7 @@ index 9bde15da2b..419ffbcab4 100644
override def sources = T.sources {
// We want to avoid duplicating code as long as the Play APIs allow.
// But if newer Play versions introduce incompatibilities,
@@ -1117,8 +875,9 @@ object scalanativelib extends MillModule {
@@ -1119,8 +878,9 @@ object scalanativelib extends MillModule {
override def ivyDeps = Agg(Deps.sbtTestInterface)
}
object worker extends Cross[WorkerModule]("0.4")
Expand All @@ -374,7 +381,7 @@ index 9bde15da2b..419ffbcab4 100644
override def moduleDeps = Seq(scalanativelib.`worker-api`)
override def ivyDeps = scalaNativeWorkerVersion match {
case "0.4" =>
@@ -1293,7 +1052,9 @@ trait IntegrationTestModule extends MillScalaModule {
@@ -1295,7 +1055,9 @@ trait IntegrationTestModule extends MillScalaModule {
}
}

Expand All @@ -385,7 +392,7 @@ index 9bde15da2b..419ffbcab4 100644
object local extends ModeModule
object fork extends ModeModule
object server extends ModeModule
@@ -1307,15 +1068,15 @@ object example extends MillScalaModule {
@@ -1309,15 +1071,15 @@ object example extends MillScalaModule {

def moduleDeps = Seq(integration)

Expand All @@ -409,7 +416,7 @@ index 9bde15da2b..419ffbcab4 100644
def sources = T.sources()
def testRepoRoot: T[PathRef] = T.source(millSourcePath)
def compile = example.compile()
@@ -1365,7 +1126,7 @@ object example extends MillScalaModule {
@@ -1367,7 +1129,7 @@ object example extends MillScalaModule {
val title =
if (seenCode) ""
else {
Expand All @@ -418,7 +425,7 @@ index 9bde15da2b..419ffbcab4 100644
val exampleDashed = examplePath.segments.mkString("-")
val download = s"{mill-download-url}/$label-$exampleDashed.zip[download]"
val browse = s"{mill-example-url}/$examplePath[browse]"
@@ -1396,9 +1157,9 @@ object example extends MillScalaModule {
@@ -1398,9 +1160,9 @@ object example extends MillScalaModule {
}

object integration extends MillScalaModule {
Expand All @@ -431,7 +438,18 @@ index 9bde15da2b..419ffbcab4 100644

def moduleDeps = Seq(scalalib, scalajslib, scalanativelib, runner.test)

@@ -1707,67 +1468,11 @@ object docs extends Module {
@@ -1681,8 +1443,8 @@ object dev extends MillModule {
mill.modules.Jvm.createJar(Agg(), mill.modules.Jvm.JarManifest(manifestEntries))
}

- def run(args: String*) = T.command {
- args match {
+ def run(args: Task[Args] = T.task(Args())) = T.command {
+ args().value match {
case Nil => mill.api.Result.Failure("Need to pass in cwd as first argument to dev.run")
case wd0 +: rest =>
val wd = os.Path(wd0, T.workspace)
@@ -1709,67 +1471,11 @@ object docs extends Module {
def moduleDeps = build.millInternal.modules.collect { case m: MillApiModule => m }

def unidocSourceUrl = T {
Expand Down Expand Up @@ -500,7 +518,7 @@ index 9bde15da2b..419ffbcab4 100644
private val npmExe = if (scala.util.Properties.isWin) "npm.cmd" else "npm"
private val antoraExe = if (scala.util.Properties.isWin) "antora.cmd" else "antora"
def npmBase: T[os.Path] = T.persistent { T.dest }
@@ -1820,7 +1525,7 @@ object docs extends Module {
@@ -1822,7 +1528,7 @@ object docs extends Module {

val contribReadmes = T.traverse(contrib.contribModules)(m =>
T.task {
Expand All @@ -509,7 +527,7 @@ index 9bde15da2b..419ffbcab4 100644
}
)()

@@ -2050,7 +1755,7 @@ def exampleZips: Target[Seq[PathRef]] = T {
@@ -2052,7 +1758,7 @@ def exampleZips: Target[Seq[PathRef]] = T {
examplePath = exampleMod.millSourcePath
} yield {
val example = examplePath.subRelativeTo(T.workspace)
Expand All @@ -518,7 +536,7 @@ index 9bde15da2b..419ffbcab4 100644
os.copy(examplePath, T.dest / exampleStr, createFolders = true)
os.copy(launcher().path, T.dest / exampleStr / "mill")
val zip = T.dest / s"$exampleStr.zip"
@@ -2059,49 +1764,7 @@ def exampleZips: Target[Seq[PathRef]] = T {
@@ -2061,49 +1767,7 @@ def exampleZips: Target[Seq[PathRef]] = T {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,5 @@ object ArtifactoryPublishModule extends ExternalModule {
}
}

import mill.main.TokenReaders._

lazy val millDiscover: mill.define.Discover[this.type] = mill.define.Discover[this.type]
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,5 @@ object BintrayPublishModule extends ExternalModule {
}
}

import mill.main.TokenReaders._

lazy val millDiscover: mill.define.Discover[this.type] = mill.define.Discover[this.type]
}
2 changes: 1 addition & 1 deletion contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mill.contrib.bloop
import bloop.config.{Config => BloopConfig, Tag => BloopTag}
import mill._
import mill.api.Result
import mill.define.{Module => MillModule, _}
import mill.define.{Module => MillModule, ExternalModule, Discover}
import mill.eval.Evaluator
import mill.scalalib.internal.ModuleUtils
import mill.scalajslib.ScalaJSModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ object BuildInfoTests extends TestSuite {
"run" - workspaceTest(BuildInfoPlain, "scala") { eval =>
val runResult = eval.outPath / "hello-mill"
val Right((result, evalCount)) =
eval.apply(BuildInfoPlain.run(runResult.toString))
eval.apply(BuildInfoPlain.run(T.task(Args(runResult.toString))))

assert(
os.exists(runResult),
Expand All @@ -173,7 +173,7 @@ object BuildInfoTests extends TestSuite {
val runResult = eval.outPath / "hello-mill"

val Right((result2, evalCount2)) =
eval.apply(BuildInfoStatic.run(runResult.toString))
eval.apply(BuildInfoStatic.run(T.task(Args(runResult.toString))))

assert(os.exists(buildInfoSourcePath(eval)))
assert(!os.exists(buildInfoResourcePath(eval)))
Expand All @@ -184,7 +184,7 @@ object BuildInfoTests extends TestSuite {
"java" - workspaceTest(BuildInfoJava, "java") { eval =>
val runResult = eval.outPath / "hello-mill"
val Right((result, evalCount)) =
eval.apply(BuildInfoJava.run(runResult.toString))
eval.apply(BuildInfoJava.run(T.task(Args(runResult.toString))))

assert(
os.exists(runResult),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ object CodeartifactPublishModule extends ExternalModule {
)
}

import mill.main.TokenReaders._

lazy val millDiscover: mill.define.Discover[this.type] =
mill.define.Discover[this.type]
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,5 @@ object GitlabPublishModule extends ExternalModule {
)
}

import mill.main.TokenReaders._

lazy val millDiscover: mill.define.Discover[this.type] = mill.define.Discover[this.type]
}
5 changes: 3 additions & 2 deletions contrib/playlib/src/mill/playlib/PlayModule.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package mill.playlib

import mill.define.Task
import mill.playlib.api.Versions
import mill.scalalib._
import mill.{Agg, T}
import mill.{Agg, Args, T}

trait PlayApiModule extends Dependencies with Router with Server {
trait PlayTests extends super.Tests with TestModule.ScalaTest {
Expand All @@ -17,7 +18,7 @@ trait PlayApiModule extends Dependencies with Router with Server {
override def sources = T.sources { millSourcePath }
}

def start(args: String*) = T.command { run(args: _*) }
def start(args: Task[Args] = T.task(Args())) = T.command { run(args) }

}
trait PlayModule extends PlayApiModule with Static with Twirl
11 changes: 3 additions & 8 deletions contrib/proguard/src/mill/contrib/proguard/Proguard.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package mill.contrib.proguard

import scala.util.Properties

import coursier.Repositories
import mill.java9rtexport.Export
import mill.T
import mill.Agg
import mill.api.{Logger, Loose, PathRef, Result}
import mill.define.{Sources, Target}
import mill.api.{Loose, PathRef}
import mill.modules.Jvm
import mill.scalalib.Lib.resolveDependencies
import mill.scalalib.{Dep, DepSyntax, Lib, ScalaModule}
import os.{Path, PathChunk, Shellable, proc}
import mill.scalalib.{DepSyntax, ScalaModule}
import os.{Path, Shellable}

/**
* Adds proguard capabilities when mixed-in to a module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package contrib.scalapblib

import coursier.MavenRepository
import coursier.core.Version
import mill.define.Sources
import mill.api.{IO, Loose, PathRef}
import mill.scalalib.Lib.resolveDependencies
import mill.scalalib._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package mill.contrib.scalapblib

import mill.T
import mill._
import mill.api.{PathRef, Result}
import mill.define.Sources
import mill.util.{TestEvaluator, TestUtil}
import utest.framework.TestPath
import utest.{TestSuite, Tests, assert, _}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import coursier.Repository
import mill._
import mill.api.{Loose, PathRef}
import mill.contrib.scoverage.api.ScoverageReportWorkerApi.ReportType
import mill.define.{Command, Persistent, Sources, Target, Task}
import mill.scalalib.api.ZincWorkerUtil
import mill.scalalib.{Dep, DepSyntax, JavaModule, ScalaModule}
import mill.api.Result
Expand Down
1 change: 0 additions & 1 deletion contrib/twirllib/src/mill/twirllib/TwirlModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mill
package twirllib

import coursier.{Dependency, Repository}
import mill.define.{Sources, Task}
import mill.api.PathRef
import mill.scalalib._
import mill.api.Loose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ object Version {
implicit val readWriter: ReadWriter[Version] =
readwriter[String].bimap(_.toString, Version.of)

implicit val read: mainargs.TokensReader[Version] = new mainargs.TokensReader[Version](
"<version>",
s => Right(Version.of(s.last))
)
implicit val read: mainargs.TokensReader.Simple[Version] =
new mainargs.TokensReader.Simple[Version] {
def shortName = "<version>"
def read(s: Seq[String]) = Right(Version.of(s.last))
}
}
Loading