Skip to content

Commit a99d9f3

Browse files
authored
Remove T.* APIs (#5166)
These were replaced by `Task.*` in 0.12.x, but kept around for compatibility. We should remove them in 1.0.0's cleanup
1 parent 96c13dd commit a99d9f3

File tree

41 files changed

+245
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+245
-162
lines changed

contrib/docker/src/mill/contrib/docker/DockerModule.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ trait DockerModule { outer: JavaModule =>
1414
* Tags that should be applied to the built image
1515
* In the standard registry/repository:tag format
1616
*/
17-
def tags: T[Seq[String]] = T(List(outer.artifactName()))
17+
def tags: T[Seq[String]] = Task { List(outer.artifactName()) }
1818
def labels: T[Map[String, String]] = Map.empty[String, String]
1919
def baseImage: T[String] = "gcr.io/distroless/java:latest"
20-
def pullBaseImage: T[Boolean] = T(baseImage().endsWith(":latest"))
20+
def pullBaseImage: T[Boolean] = Task { baseImage().endsWith(":latest") }
2121

2222
/**
2323
* JVM runtime options. Each item of the Seq should consist of an option and its desired value, like

contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ trait FlywayModule extends JavaModule {
1818
import FlywayModule._
1919

2020
def flywayUrl: T[String]
21-
def flywayUser: T[String] = T("")
22-
def flywayPassword: T[String] = T("")
21+
def flywayUser: T[String] = Task { "" }
22+
def flywayPassword: T[String] = Task { "" }
2323
def flywayFileLocations: T[Seq[PathRef]] = Task {
2424
resources().map(pr => PathRef(pr.path / "db/migration", pr.quick))
2525
}

contrib/proguard/readme.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object foo extends ScalaModule with Proguard {
3232
override def obfuscate: T[Boolean] = Task { false }
3333
3434
// https://github.com/Guardsquare/proguard/releases
35-
override def proguardVersion = T("7.3.2")
35+
override def proguardVersion = Task { "7.3.2" }
3636
3737
// tell Proguard where to enter your app, so it can optimise outwards from there
3838
override def entryPoint = Task {

contrib/proguard/src/mill/contrib/proguard/Proguard.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ trait Proguard extends ScalaModule {
156156
Task.log.warn(
157157
"Proguard is set to not warn about message: can't find referenced method 'void invoke()' in library class java.lang.invoke.MethodHandle"
158158
)
159-
T.log.warn(
159+
Task.log.warn(
160160
"""Proguard is set to not warn about message: "scala.quoted.Type: can't find referenced class scala.AnyKind""""
161161
)
162162
Seq[String](

core/define/src/mill/define/Task.scala

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import scala.quoted.*
1717
* single output of type [[T]].
1818
*
1919
* Generally not instantiated manually, but instead constructed via the
20-
* [[Target.apply]] & similar macros.
20+
* [[Task.apply]] & similar macros.
2121
*/
2222
sealed abstract class Task[+T] extends Task.Ops[T] with Applyable[Task, T] with TaskApi[T] {
2323

@@ -51,7 +51,92 @@ sealed abstract class Task[+T] extends Task.Ops[T] with Applyable[Task, T] with
5151
}
5252
}
5353

54-
object Task extends TaskBase {
54+
object Task {
55+
56+
/**
57+
* Returns the [[mill.define.TaskCtx]] that is available within this task
58+
*/
59+
def ctx()(implicit c: mill.define.TaskCtx): mill.define.TaskCtx = c
60+
61+
/**
62+
* `Task.dest` is a unique `os.Path` (e.g. `out/classFiles.dest/` or `out/run.dest/`)
63+
* that is assigned to every Target or Command. It is cleared before your
64+
* task runs, and you can use it as a scratch space for temporary files or
65+
* a place to put returned artifacts. This is guaranteed to be unique for
66+
* every Target or Command, so you can be sure that you will not collide or
67+
* interfere with anyone else writing to those same paths.
68+
*/
69+
def dest(implicit ctx: mill.define.TaskCtx.Dest): os.Path = ctx.dest
70+
71+
/**
72+
* `Task.log` is the default logger provided for every task. While your task is running,
73+
* `System.out` and `System.in` are also redirected to this logger. The logs for a
74+
* task are streamed to standard out/error as you would expect, but each task's
75+
* specific output is also streamed to a log file on disk, e.g. `out/run.log` or
76+
* `out/classFiles.log` for you to inspect later.
77+
*
78+
* Messages logged with `log.debug` appear by default only in the log files.
79+
* You can use the `--debug` option when running mill to show them on the console too.
80+
*/
81+
def log(implicit ctx: mill.define.TaskCtx.Log): Logger = ctx.log
82+
83+
/**
84+
* `Task.env` is the environment variable map passed to the Mill command when
85+
* it is run; typically used inside a `Task.Input` to ensure any changes in
86+
* the env vars are properly detected.
87+
*
88+
* Note that you should not use `sys.env`, as Mill's long-lived server
89+
* process means that `sys.env` variables may not be up to date.
90+
*/
91+
def env(implicit ctx: mill.define.TaskCtx.Env): Map[String, String] = ctx.env
92+
93+
/**
94+
* Returns the implicit [[mill.define.TaskCtx.Args.args]] in scope.
95+
*/
96+
def args(implicit ctx: mill.define.TaskCtx.Args): IndexedSeq[?] = ctx.args
97+
98+
/**
99+
* Report test results to BSP for IDE integration
100+
*/
101+
def testReporter(implicit ctx: mill.define.TaskCtx): TestReporter = ctx.testReporter
102+
103+
/**
104+
* Report build results to BSP for IDE integration
105+
*/
106+
def reporter(implicit ctx: mill.define.TaskCtx): Int => Option[CompileProblemReporter] =
107+
ctx.reporter
108+
109+
/**
110+
* This is the `os.Path` pointing to the project root directory.
111+
*
112+
* This is the preferred access to the project directory, and should
113+
* always be prefered over `os.pwd`* (which might also point to the
114+
* project directory in classic cli scenarios, but might not in other
115+
* use cases like BSP or LSP server usage).
116+
*/
117+
def workspace(implicit ctx: mill.define.TaskCtx): os.Path = ctx.workspace
118+
119+
/**
120+
* Provides the `.fork.async` and `.fork.await` APIs for spawning and joining
121+
* async futures within your task in a Mill-friendly mannter
122+
*/
123+
def fork(implicit ctx: mill.define.TaskCtx): mill.define.TaskCtx.Fork.Api = ctx.fork
124+
125+
def offline(implicit ctx: mill.define.TaskCtx): Boolean = ctx.offline
126+
127+
def fail(msg: String)(implicit ctx: mill.define.TaskCtx): Nothing = ctx.fail(msg)
128+
129+
/**
130+
* Converts a `Seq[Task[T]]` into a `Task[Seq[T]]`
131+
*/
132+
def sequence[T](source: Seq[Task[T]]): Task[Seq[T]] = new Task.Sequence[T](source)
133+
134+
/**
135+
* Converts a `Seq[T]` into a `Task[Seq[V]]` using the given `f: T => Task[V]`
136+
*/
137+
def traverse[T, V](source: Seq[T])(f: T => Task[V]): Task[Seq[V]] = {
138+
new Task.Sequence[V](source.map(f))
139+
}
55140

56141
/**
57142
* A specialization of [[InputImpl]] defined via `Task.Sources`, [[SourcesImpl]]
@@ -269,21 +354,21 @@ trait NamedTask[+T] extends Task[T] with NamedTaskApi[T] {
269354
*/
270355
trait Target[+T] extends NamedTask[T]
271356

272-
object Target extends TaskBase {
357+
object Target {
273358

274359
/**
275360
* A target is the most common [[Task]] a user would encounter, commonly
276361
* defined using the `def foo = Task {...}` syntax. [[TargetImpl]]s require that their
277362
* return type is JSON serializable. In return they automatically caches their
278363
* return value to disk, only re-computing if upstream [[Task]]s change
279364
*/
280-
implicit inline def apply[T](inline t: T)(implicit
365+
implicit inline def create[T](inline t: T)(implicit
281366
inline rw: ReadWriter[T],
282367
inline ctx: ModuleCtx
283368
): Target[T] =
284369
${ TaskMacros.targetResultImpl[T]('{ Result.Success(t) })('rw, 'ctx, '{ false }) }
285370

286-
implicit inline def apply[T](inline t: Result[T])(implicit
371+
implicit inline def create[T](inline t: Result[T])(implicit
287372
inline rw: ReadWriter[T],
288373
inline ctx: ModuleCtx
289374
): Target[T] =

core/define/src/mill/define/TaskCtx.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ object TaskCtx {
5555
}
5656

5757
@compileTimeOnly(
58-
"Target.ctx() / Task.ctx() / Task.* APIs can only be used with a Task{...} block"
58+
"Task.ctx() / Task.* APIs can only be used with a Task{...} block"
5959
)
6060
@ImplicitStub
6161
implicit def taskCtx: TaskCtx = ???

core/define/test/src/mill/define/ApplicativeTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object ApplicativeTests extends TestSuite {
1515
value
1616
}
1717
}
18-
@compileTimeOnly("Target.ctx() can only be used with a Task{...} block")
18+
@compileTimeOnly("Task.ctx() can only be used with a Task{...} block")
1919
@ImplicitStub
2020
implicit def taskCtx: String = ???
2121

core/util/src/mill/mill.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package object mill extends mill.define.JsonFormatters with mill.util.TokenReaders0 {
2-
val T = define.Target
32
type T[+T] = define.Target[T]
4-
val Target = define.Target
53
type Target[+T] = define.Target[T]
64
val PathRef = mill.define.PathRef
75
type PathRef = mill.define.PathRef

dist/scripts/package.mill

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ object `package` extends mill.Module { scripts =>
2121
"mill-best-version" -> "0.12.10", // TODO: build.millVersionTruth()
2222
"mill-download-cache-unix" -> "~/.cache/mill/download",
2323
"mill-download-cache-win" -> "%USERPROFILE%\\\\.mill\\\\download",
24-
"template-file" -> templateFile().path.relativeTo(T.workspace).toString
24+
"template-file" -> templateFile().path.relativeTo(Task.workspace).toString
2525
)
2626
def substitutionMarkers: T[(String, String)] = ("{{{", "}}}")
2727
def inRepoDir: Task[os.SubPath] = Task.Anon { os.sub / finalName() }
2828

2929
/** Compiles the script from the [[templateFile]] and substitutes all [[substitutions]]. */
3030
def compile0: T[PathRef] = Task {
31-
val script = T.dest / finalName()
31+
val script = Task.dest / finalName()
3232
val template = templateFile().path
3333
val (start, end) = substitutionMarkers()
3434

@@ -89,7 +89,7 @@ object `package` extends mill.Module { scripts =>
8989
Task.traverse(scriptsModules)(m =>
9090
Task.Anon {
9191
val script = m.compile0().path
92-
val dest = T.workspace / m.inRepoDir()
92+
val dest = Task.workspace / m.inRepoDir()
9393
if (os.isDir(dest)) {
9494
sys.error(s"Install destination is a directory: ${dest}")
9595
} else if (os.exists(dest)) {

example/thirdparty/ollama-js/build.mill

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ trait OllamaModule extends TypeScriptModule {
9393
p.last == "node_modules" ||
9494
p.last == "package-lock.json"
9595
)
96-
.foreach(p => os.copy.over(p, T.dest / p.relativeTo(out), createFolders = true))
96+
.foreach(p => os.copy.over(p, Task.dest / p.relativeTo(out), createFolders = true))
9797

98-
os.call("node_modules/.bin/unbuild", cwd = T.dest)
98+
os.call("node_modules/.bin/unbuild", cwd = Task.dest)
9999

100100
// prepare bundled ouptut to be used as `unmanagedDeps` in examples section.
101-
os.makeDir.all(T.dest / "ollama")
102-
os.copy(T.dest / "package.json", T.dest / "ollama" / "package.json")
103-
os.copy(T.dest / "dist", T.dest / "ollama" / "dist")
101+
os.makeDir.all(Task.dest / "ollama")
102+
os.copy(Task.dest / "package.json", Task.dest / "ollama" / "package.json")
103+
os.copy(Task.dest / "dist", Task.dest / "ollama" / "dist")
104104

105-
PathRef(T.dest / "ollama")
105+
PathRef(Task.dest / "ollama")
106106
}
107107
}
108108

0 commit comments

Comments
 (0)