Skip to content

Commit

Permalink
Clean up usage of old T.* syntax, doc review for Mill Fundamentals (#…
Browse files Browse the repository at this point in the history
…4422)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
lihaoyi and autofix-ci[bot] authored Jan 28, 2025
1 parent 76b8f64 commit bcb6724
Show file tree
Hide file tree
Showing 137 changed files with 934 additions and 866 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,19 @@ jobs:
millargs: "contrib.__.test"
install-android-sdk: false

# Run this one using `.native` as a smoketest. Also make sure the java-version
# is the same as that used in the `build-linux` job to avoid diverging code
# hashes (https://github.com/com-lihaoyi/mill/pull/4410)
- java-version: 11
millargs: "example.javalib.__.native.server.test"
- java-version: 17
millargs: "example.javalib.__.local.server.test"
install-android-sdk: false

- java-version: 17
millargs: "example.kotlinlib.__.local.server.test"
install-android-sdk: false

- java-version: 17
millargs: "example.scalalib.__.local.server.test"
# Run this one using `.native` as a smoketest. Also make sure the java-version
# is the same as that used in the `build-linux` job to avoid diverging code
# hashes (https://github.com/com-lihaoyi/mill/pull/4410)
- java-version: 11
millargs: "example.scalalib.__.native.server.test"
install-android-sdk: false

- java-version: 17
Expand Down
6 changes: 3 additions & 3 deletions bsp/src/mill/bsp/BSP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object BSP extends ExternalModule with CoursierModule {
// we create a file containing the additional jars to load
val libUrls = bspWorkerLibs().map(_.path.toNIO.toUri.toURL).iterator.toSeq
val cpFile =
T.workspace / Constants.bspDir / s"${Constants.serverName}-${BuildInfo.millVersion}.resources"
Task.workspace / Constants.bspDir / s"${Constants.serverName}-${BuildInfo.millVersion}.resources"
os.write.over(
cpFile,
libUrls.mkString("\n"),
Expand All @@ -51,9 +51,9 @@ object BSP extends ExternalModule with CoursierModule {
*/
def startSession(allBootstrapEvaluators: Evaluator.AllBootstrapEvaluators)
: Command[BspServerResult] = Task.Command {
T.log.errorStream.println("BSP/startSession: Starting BSP session")
Task.log.errorStream.println("BSP/startSession: Starting BSP session")
val res = BspContext.bspServerHandle.runSession(allBootstrapEvaluators.value)
T.log.errorStream.println(s"BSP/startSession: Finished BSP session, result: ${res}")
Task.log.errorStream.println(s"BSP/startSession: Finished BSP session, result: ${res}")
res
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import mill.api.Result
import scalalib._
import mill.contrib.artifactory.ArtifactoryPublishModule.checkArtifactoryCreds
import mill.define.{ExternalModule, Task}
import mill.define.Command

trait ArtifactoryPublishModule extends PublishModule {
def artifactoryUri: String
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -59,9 +60,9 @@ object ArtifactoryPublishModule extends ExternalModule {
publishArtifacts: mill.main.Tasks[PublishModule.PublishData],
readTimeout: Int = 60000,
connectTimeout: Int = 5000
) = Task.Command {
): Command[Unit] = Task.Command {

val artifacts = T.sequence(publishArtifacts.value)().map {
val artifacts = Task.sequence(publishArtifacts.value)().map {
case data @ PublishModule.PublishData(_, _) => data.withConcretePath
}
new ArtifactoryPublisher(
Expand All @@ -70,7 +71,7 @@ object ArtifactoryPublishModule extends ExternalModule {
checkArtifactoryCreds(credentials)(),
readTimeout,
connectTimeout,
T.log
Task.log
).publishAll(
artifacts: _*
)
Expand All @@ -79,8 +80,8 @@ object ArtifactoryPublishModule extends ExternalModule {
private def checkArtifactoryCreds(credentials: String): Task[String] = Task.Anon {
if (credentials.isEmpty) {
(for {
username <- T.env.get("ARTIFACTORY_USERNAME")
password <- T.env.get("ARTIFACTORY_PASSWORD")
username <- Task.env.get("ARTIFACTORY_USERNAME")
password <- Task.env.get("ARTIFACTORY_PASSWORD")
} yield {
Result.Success(s"$username:$password")
}).getOrElse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import mill.api.Result
import scalalib._
import mill.contrib.bintray.BintrayPublishModule.checkBintrayCreds
import mill.define.{ExternalModule, Task}
import mill.define.Command

trait BintrayPublishModule extends PublishModule {

Expand Down Expand Up @@ -44,7 +45,7 @@ trait BintrayPublishModule extends PublishModule {
release,
readTimeout,
connectTimeout,
T.log
Task.log
).publish(bintrayPublishArtifacts())
}
}
Expand All @@ -69,25 +70,25 @@ object BintrayPublishModule extends ExternalModule {
publishArtifacts: mill.main.Tasks[BintrayPublishData],
readTimeout: Int = 60000,
connectTimeout: Int = 5000
) = Task.Command {
): Command[Unit] = Task.Command {
new BintrayPublisher(
bintrayOwner,
bintrayRepo,
checkBintrayCreds(credentials)(),
release,
readTimeout,
connectTimeout,
T.log
Task.log
).publishAll(
T.sequence(publishArtifacts.value)(): _*
Task.sequence(publishArtifacts.value)(): _*
)
}

private def checkBintrayCreds(credentials: String): Task[String] = Task.Anon {
if (credentials.isEmpty) {
(for {
username <- T.env.get("BINTRAY_USERNAME")
password <- T.env.get("BINTRAY_PASSWORD")
username <- Task.env.get("BINTRAY_USERNAME")
password <- Task.env.get("BINTRAY_PASSWORD")
} yield {
Result.Success(s"$username:$password")
}).getOrElse(
Expand Down
10 changes: 5 additions & 5 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
* under pwd/.bloop.
*/
def install() = Task.Command {
val res = T.traverse(computeModules)(_.bloop.writeConfigFile())()
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)) {
Expand Down Expand Up @@ -91,7 +91,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
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)
}

Expand Down Expand Up @@ -139,7 +139,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
* from module#sources in bloopInstall
*/
def moduleSourceMap = Task.Input {
val sources = T.traverse(computeModules) { m =>
val sources = Task.traverse(computeModules) { m =>
m.allSources.map { paths =>
name(m) -> paths.map(_.path)
}
Expand Down Expand Up @@ -203,7 +203,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
// //////////////////////////////////////////////////////////////////////////

val classpath = Task.Anon {
val transitiveCompileClasspath = T.traverse(module.transitiveModuleCompileModuleDeps)(m =>
val transitiveCompileClasspath = Task.traverse(module.transitiveModuleCompileModuleDeps)(m =>
Task.Anon { m.localCompileClasspath().map(_.path) ++ Agg(classes(m)) }
)().flatten

Expand Down Expand Up @@ -273,7 +273,7 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
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
Expand Down
8 changes: 4 additions & 4 deletions contrib/buildinfo/src/mill/contrib/buildinfo/BuildInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ trait BuildInfo extends JavaModule {

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
)

Expand All @@ -54,7 +54,7 @@ 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]
Expand Down Expand Up @@ -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))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -42,7 +42,7 @@ object CodeartifactPublishModule extends ExternalModule {
connectTimeout: Int = 5000
) =
Task.Command {
val artifacts = T.sequence(publishArtifacts.value)().map {
val artifacts = Task.sequence(publishArtifacts.value)().map {
case data @ PublishModule.PublishData(_, _) => data.withConcretePath
}
new CodeartifactPublisher(
Expand All @@ -51,7 +51,7 @@ object CodeartifactPublishModule extends ExternalModule {
credentials,
readTimeout,
connectTimeout,
T.log
Task.log
).publishAll(
artifacts: _*
)
Expand Down
6 changes: 3 additions & 3 deletions contrib/docker/src/mill/contrib/docker/DockerModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ trait DockerModule { outer: JavaModule =>
* [[https://docs.docker.com/engine/reference/commandline/cli/#environment-variables Environment variables]]
* for more information.
*/
def dockerEnv: T[Map[String, String]] = T.env
def dockerEnv: T[Map[String, String]] = Task.env

/**
* Commands to add as RUN instructions.
Expand Down Expand Up @@ -161,15 +161,15 @@ trait DockerModule { outer: JavaModule =>
}

final def build = Task {
val dest = T.dest
val dest = Task.dest
val env = dockerEnv()

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))

Expand Down
2 changes: 1 addition & 1 deletion contrib/flyway/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,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 = Task.Input(T.ctx.env("FLYWAY_PASSWORD"))`
For example `def flywayPassword = Task.Input(Task.ctx.env("FLYWAY_PASSWORD"))`
2 changes: 1 addition & 1 deletion contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/gitlab/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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.mill` 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.mill` 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.

Expand Down Expand Up @@ -131,7 +131,7 @@ override def gitlabHeaders(
props: Map[String, String] // System properties
): 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package mill.contrib.gitlab

import coursier.core.Authentication
import coursier.maven.MavenRepository
import mill.T
import mill.api.Result
import mill.api.Result.{Failure, Success}
import mill.define.Task
Expand All @@ -14,7 +13,7 @@ trait GitlabMavenRepository {

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)))

Expand Down
10 changes: 5 additions & 5 deletions contrib/gitlab/src/mill/contrib/gitlab/GitlabPublishModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait GitlabPublishModule extends PublishModule { outer =>
def gitlabHeaders(
systemProps: Map[String, String] = sys.props.toMap
): Task[GitlabAuthHeaders] = Task.Anon {
val auth = tokenLookup.resolveGitlabToken(T.env, systemProps, T.workspace)
val auth = tokenLookup.resolveGitlabToken(Task.env, systemProps, Task.workspace)
auth match {
case Left(msg) =>
Failure(
Expand All @@ -36,13 +36,13 @@ trait GitlabPublishModule extends PublishModule { outer =>

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)
}

Expand All @@ -62,15 +62,15 @@ object GitlabPublishModule extends ExternalModule {
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)

new GitlabPublisher(
uploader.upload,
repo,
T.log
Task.log
).publishAll(
artifacts: _*
)
Expand Down
6 changes: 3 additions & 3 deletions contrib/jmh/src/mill/contrib/jmh/JmhModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ trait JmhModule extends JavaModule {
classPath = (runClasspath() ++ generatorDeps()).map(_.path) ++
Seq(compileGeneratedSources().path, resources),
mainArgs = args,
workingDir = T.ctx().dest,
workingDir = Task.ctx().dest,
javaHome = zincWorker().javaHome().map(_.path)
)
}
Expand All @@ -52,7 +52,7 @@ trait JmhModule extends JavaModule {

def compileGeneratedSources =
Task {
val dest = T.ctx().dest
val dest = Task.ctx().dest
val (sourcesDir, _) = generateBenchmarkSources()
val sources = os.walk(sourcesDir).filter(os.isFile)

Expand All @@ -72,7 +72,7 @@ trait JmhModule extends JavaModule {
// returns sources and resources directories
def generateBenchmarkSources =
Task {
val dest = T.ctx().dest
val dest = Task.ctx().dest
val forkedArgs = forkArgs().toSeq
val sourcesDir = dest / "jmh_sources"
val resourcesDir = dest / "jmh_resources"
Expand Down
Loading

0 comments on commit bcb6724

Please sign in to comment.