Skip to content

WIP: streamline mill.api.Ctx usage #4794

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libs/scalalib/api/src/mill/scalalib/api/JvmWorkerApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import mill.api.internal.CompileProblemReporter
import mill.define.PathRef

object JvmWorkerApi {
type Ctx = mill.define.TaskCtx.Dest & mill.define.TaskCtx.Log
type Ctx = mill.define.TaskCtx
}
trait JvmWorkerApi {

Expand Down
5 changes: 4 additions & 1 deletion libs/scalalib/src/mill/scalalib/CoursierModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import coursier.cache.FileCache
import coursier.core.Resolution
import coursier.params.ResolutionParams
import coursier.{Dependency, Repository, Resolve, Type}
import mill.define.Task
import mill.define.{Task, TaskCtx}
import mill.define.{PathRef}
import mill.api.{Result}
import mill.util.Jvm
Expand Down Expand Up @@ -44,6 +44,7 @@ trait CoursierModule extends mill.define.Module {
mapDependencies = Some(mapDependencies()),
customizer = resolutionCustomizer(),
coursierCacheCustomizer = coursierCacheCustomizer(),
ctx = Some(Task.ctx()),
resolutionParams = resolutionParams(),
offline = Task.offline
)
Expand All @@ -64,6 +65,7 @@ trait CoursierModule extends mill.define.Module {
mapDependencies = Some(mapDependencies()),
customizer = resolutionCustomizer(),
coursierCacheCustomizer = coursierCacheCustomizer(),
ctx = Some(Task.ctx()),
resolutionParams = resolutionParams(),
offline = Task.offline
)
Expand Down Expand Up @@ -192,6 +194,7 @@ object CoursierModule {
bind: Dep => BoundDep,
mapDependencies: Option[Dependency => Dependency] = None,
customizer: Option[coursier.core.Resolution => coursier.core.Resolution] = None,
ctx: Option[TaskCtx] = None,
coursierCacheCustomizer: Option[
coursier.cache.FileCache[coursier.util.Task] => coursier.cache.FileCache[coursier.util.Task]
] = None,
Expand Down
2 changes: 1 addition & 1 deletion libs/scalalib/src/mill/scalalib/TestModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ object TestModule {
def handleResults(
doneMsg: String,
results: Seq[TestResult],
ctx: TaskCtx.Env & TaskCtx.Dest,
ctx: TaskCtx,
testReportXml: Option[String],
props: Option[Map[String, String]] = None
): Result[(String, Seq[TestResult])] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mill.scalalib.dependency

import mill.define.TaskCtx.Log
import mill.define.*
import mill.scalalib.dependency.updates.{
DependencyUpdates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LocalIvyPublisher(localIvyRepo: os.Path) {
ivy: Either[String, os.Path],
artifact: Artifact,
publishInfos: Seq[PublishInfo]
)(implicit ctx: TaskCtx.Log): Seq[os.Path] = {
)(implicit ctx: TaskCtx): Seq[os.Path] = {

ctx.log.info(s"Publishing ${artifact} to ivy repo ${localIvyRepo}")
val releaseDir = localIvyRepo / artifact.group / artifact.id / artifact.version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class LocalM2Publisher(m2Repo: os.Path) {
* @param pom The POM of this module
* @param artifact Coordinates of this module
* @param publishInfos Files to publish in this module
* @param ctx
* @return
*/
def publish(
pom: os.Path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@ package mill.scalalib.publish

import mill.define.{TaskCtx, PathRef}
import mill.api.{Logger}
import mill.api.internal.{CompileProblemReporter, TestReporter}
import mill.internal.DummyLogger
import os.Path
import utest.{TestSuite, Tests, assert, test}

object LocalM2PublisherTests extends TestSuite {

class DummyCtx extends TaskCtx {
override def log: Logger = DummyLogger
// stubs
override def arg[T](index: Int): T = ???
override def args: IndexedSeq[?] = ???
override def reporter: Int => Option[CompileProblemReporter] = ???
override def systemExit: Int => Nothing = ???
override def testReporter: TestReporter = ???
override def dest: os.Path = ???
override def env: Map[String, String] = ???
override def fork: TaskCtx.Fork.Api = ???
override def jobs: Int = ???
override def workspace: Path = ???
override def offline: Boolean = ???
override def fail(msg: String): Nothing = ???
}

override def tests: Tests = Tests {

implicit val dummyLog: TaskCtx.Log = new TaskCtx.Log {
override def log: Logger = DummyLogger
}
implicit val dummyCtx: TaskCtx = new DummyCtx

def publishAndCheck(repo: os.Path): Unit = {
val subrepo = repo / "group/org/id/version"
Expand Down
2 changes: 1 addition & 1 deletion libs/testrunner/src/mill/testrunner/TestRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import mill.util.Jvm
args: Seq[String],
testReporter: TestReporter,
classFilter: Class[?] => Boolean = _ => true
)(implicit ctx: TaskCtx.Log): (String, Seq[mill.testrunner.TestResult]) = {
)(implicit ctx: TaskCtx): (String, Seq[mill.testrunner.TestResult]) = {
Jvm.withClassLoader(
classPath = entireClasspath.toVector,
sharedPrefixes = Seq("sbt.testing.")
Expand Down
Loading