Skip to content

Commit

Permalink
Remove dependency from define on internal (com-lihaoyi#4517)
Browse files Browse the repository at this point in the history
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
lihaoyi and autofix-ci[bot] authored Feb 9, 2025
1 parent b55ca58 commit 1580715
Show file tree
Hide file tree
Showing 25 changed files with 149 additions and 132 deletions.
2 changes: 1 addition & 1 deletion bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ private class MillBuildServer(
Strict.Agg(cleanTask),
logger = new MillBspLogger(client, cleanTask.hashCode, ev.baseLogger)
)
if (cleanResult.failing.keyCount > 0) (
if (cleanResult.failing.size > 0) (
msg + s" Target ${compileTargetName} could not be cleaned. See message from mill: \n" +
(cleanResult.results(cleanTask) match {
case TaskResult(Result.Failure(msg, _), _) => msg
Expand Down
27 changes: 27 additions & 0 deletions core/api/package.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package build.core.api

import mill.contrib.buildinfo.BuildInfo
import mill._

object `package` extends RootModule with build.MillStableScalaModule with BuildInfo {
def moduleDeps = Seq(build.core.client)
def buildInfoPackageName = "mill.api"
def buildInfoMembers = Seq(
BuildInfo.Value("millVersion", build.millVersion(), "Mill version."),
BuildInfo.Value("millDocUrl", build.Settings.docUrl, "Mill documentation url."),
BuildInfo.Value(
"millReportNewIssueUrl",
build.Settings.newIssueUrl,
"URL to create a new issue in Mills issue tracker."
)
)

def ivyDeps = Agg(
build.Deps.osLib,
build.Deps.mainargs,
build.Deps.upickle,
build.Deps.pprint,
build.Deps.fansi,
build.Deps.sbtTestInterface
)
}
14 changes: 14 additions & 0 deletions core/client/package.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package build.core.client

import mill._
import mill.contrib.buildinfo.BuildInfo
import mill.scalalib._

object `package` extends RootModule with build.MillPublishJavaModule with BuildInfo {
def buildInfoPackageName = "mill.main.client"
def buildInfoMembers = Seq(BuildInfo.Value("millVersion", build.millVersion(), "Mill version."))

object test extends JavaTests with TestModule.Junit4 {
def ivyDeps = Agg(build.Deps.junitInterface, build.Deps.commonsIo)
}
}
26 changes: 26 additions & 0 deletions core/define/package.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package build.core.define

import mill._
import mill.scalalib._

object `package` extends RootModule with build.MillStableScalaModule {
def moduleDeps = Seq(build.core.api)

def compileIvyDeps = Task {
if (scalaVersion().startsWith("3.")) Agg(build.Deps.scalaCompiler(scalaVersion()))
else Agg(build.Deps.scalaReflect(scalaVersion()))
}

def ivyDeps = Agg(
build.Deps.millModuledefs,
// TODO: somewhere sourcecode is included transitively,
// but we need the latest version to bring the macro improvements.
build.Deps.sourcecode,
// Necessary so we can share the JNA classes throughout the build process
build.Deps.jna,
build.Deps.jnaPlatform,
build.Deps.jarjarabrams,
build.Deps.mainargs,
build.Deps.scalaparse
)
}
1 change: 0 additions & 1 deletion core/define/src/mill/define/BaseModule.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mill.define

import mill.api.PathRef
import mill.internal.Watchable

import scala.collection.mutable

Expand Down
1 change: 0 additions & 1 deletion core/define/src/mill/define/Cross.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mill.define

import mill.api.BuildScriptException
import mill.internal.Lazy

import scala.collection.mutable
import scala.reflect.ClassTag
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mill.internal
package mill.define

class Lazy[T](t: () => T) {
lazy val value: T = t()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mill.internal
package mill.define

import mill.api.internal

Expand Down
7 changes: 7 additions & 0 deletions core/exec/package.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package build.core.exec

import mill._

object `package` extends RootModule with build.MillStableScalaModule {
def moduleDeps = Seq(build.core.define, build.core.internal)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package mill.exec
import mill.api.*
import mill.api.Strict.Agg
import mill.define.*
import mill.internal.MultiBiMap

trait ExecResults {
def rawValues: Seq[Result[Val]]
def evaluated: Agg[Task[?]]
def transitive: Agg[Task[?]]
def failing: MultiBiMap[Task[?], Result.Failing[Val]]
def results: collection.Map[Task[?], TaskResult[Val]]
def failing: Map[Task[?], Seq[Result.Failing[Val]]]
def results: Map[Task[?], TaskResult[Val]]
def values: Seq[Val] = rawValues.collect { case Result.Success(v) => v }
}
6 changes: 2 additions & 4 deletions core/exec/src/mill/exec/ExecutionCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ private[mill] trait ExecutionCore extends GroupExecution {
Strict.Agg.from(
finishedOptsMap.values.flatMap(_.toSeq.flatMap(_.newEvaluated)).iterator.distinct
),
plan.transitive,
getFailing(plan.sortedGroups, results),
getFailing(plan.sortedGroups, results).items().map { case (k, v) => (k, v.toSeq) }.toMap,
results.map { case (k, v) => (k, v.map(_._1)) }
)
}
Expand All @@ -275,8 +274,7 @@ private[mill] object ExecutionCore {
case class Results(
rawValues: Seq[Result[Val]],
evaluated: Agg[Task[?]],
transitive: Agg[Task[?]],
failing: MultiBiMap[Task[?], Result.Failing[Val]],
failing: Map[Task[?], Seq[Result.Failing[Val]]],
results: Map[Task[?], TaskResult[Val]]
) extends ExecResults
}
7 changes: 7 additions & 0 deletions core/internal/package.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package build.core.internal

import mill._

object `package` extends RootModule with build.MillPublishScalaModule {
def moduleDeps = Seq(build.core.api)
}
73 changes: 1 addition & 72 deletions core/package.mill
Original file line number Diff line number Diff line change
@@ -1,79 +1,8 @@
package build.core
// imports
import mill._
import mill.scalalib._
import mill.contrib.buildinfo.BuildInfo
import mill.T
import mill.define.Cross
import mill.scalalib.api.ZincWorkerUtil

object `package` extends RootModule with build.MillStableScalaModule {
def moduleDeps = Seq(define, exec, resolve)
object api extends build.MillStableScalaModule with BuildInfo {
def moduleDeps = Seq(client)
def buildInfoPackageName = "mill.api"
def buildInfoMembers = Seq(
BuildInfo.Value("millVersion", build.millVersion(), "Mill version."),
BuildInfo.Value("millDocUrl", build.Settings.docUrl, "Mill documentation url."),
BuildInfo.Value(
"millReportNewIssueUrl",
build.Settings.newIssueUrl,
"URL to create a new issue in Mills issue tracker."
)
)

def ivyDeps = Agg(
build.Deps.osLib,
build.Deps.mainargs,
build.Deps.upickle,
build.Deps.pprint,
build.Deps.fansi,
build.Deps.sbtTestInterface
)
}

object internal extends build.MillPublishScalaModule {
def moduleDeps = Seq(api)
}
object define extends build.MillStableScalaModule {
def moduleDeps = Seq(api, internal)
def compileIvyDeps = Task {
if (ZincWorkerUtil.isScala3(scalaVersion())) Agg(build.Deps.scalaCompiler(scalaVersion()))
else Agg(build.Deps.scalaReflect(scalaVersion()))
}
def ivyDeps = Agg(
build.Deps.millModuledefs,
// TODO: somewhere sourcecode is included transitively,
// but we need the latest version to bring the macro improvements.
build.Deps.sourcecode,
// Necessary so we can share the JNA classes throughout the build process
build.Deps.jna,
build.Deps.jnaPlatform,
build.Deps.jarjarabrams,
build.Deps.mainargs,
build.Deps.scalaparse
)
}

object exec extends build.MillStableScalaModule {
def moduleDeps = Seq(define)
}

object resolve extends build.MillStableScalaModule {
def moduleDeps = Seq(define)
}

object client extends build.MillPublishJavaModule with BuildInfo {
def buildInfoPackageName = "mill.main.client"
def buildInfoMembers = Seq(BuildInfo.Value("millVersion", build.millVersion(), "Mill version."))

object test extends JavaTests with TestModule.Junit4 {
def ivyDeps = Agg(build.Deps.junitInterface, build.Deps.commonsIo)
}
}

object server extends build.MillPublishScalaModule {
def moduleDeps = Seq(client, api)
}
def moduleDeps = Seq(build.core.define, build.core.exec, build.core.resolve)

}
7 changes: 7 additions & 0 deletions core/resolve/package.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package build.core.resolve

import mill._

object `package` extends RootModule with build.MillStableScalaModule {
def moduleDeps = Seq(build.core.define, build.core.internal)
}
7 changes: 7 additions & 0 deletions core/server/package.mill
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package build.core.server

import mill._

object `package` extends RootModule with build.MillPublishScalaModule {
def moduleDeps = Seq(build.core.client, build.core.api)
}
10 changes: 5 additions & 5 deletions core/src/mill/eval/Evaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import mill.exec.{
ProfileLogger,
TaskResult
}
import mill.internal.Watchable
import mill.define.Watchable
import mill.main.client.OutFiles
import mill.main.client.OutFiles.*
import mill.resolve.{Resolve, SelectMode}
Expand Down Expand Up @@ -183,7 +183,7 @@ final case class Evaluator private[mill] (
}

val errorStr = Evaluator.formatFailing(evaluated)
evaluated.failing.keyCount match {
evaluated.failing.size match {
case 0 =>
val nameAndJson = for (t <- selectedTargets.toSeq) yield {
t match {
Expand All @@ -206,7 +206,7 @@ private[mill] object Evaluator {
class EvalOrThrow(evaluator: Evaluator, exceptionFactory: ExecResults => Throwable) {
def apply[T: ClassTag](task: Task[T]): T =
evaluator.evaluate(Agg(task)) match {
case r if r.failing.items().nonEmpty =>
case r if r.failing.nonEmpty =>
throw exceptionFactory(r)
case r =>
// Input is a single-item Agg, so we also expect a single-item result
Expand All @@ -216,7 +216,7 @@ private[mill] object Evaluator {

def apply[T: ClassTag](tasks: Seq[Task[T]]): Seq[T] =
evaluator.evaluate(tasks) match {
case r if r.failing.items().nonEmpty =>
case r if r.failing.nonEmpty =>
throw exceptionFactory(r)
case r => r.values.map(_.value).asInstanceOf[Seq[T]]
}
Expand All @@ -238,7 +238,7 @@ private[mill] object Evaluator {
val defaultEnv: Map[String, String] = System.getenv().asScala.toMap

def formatFailing(evaluated: ExecResults): String = {
(for ((k, fs) <- evaluated.failing.items())
(for ((k, fs) <- evaluated.failing)
yield {
val fss = fs.map {
case Result.Failure(t, _) => t
Expand Down
2 changes: 1 addition & 1 deletion idea/src/mill/idea/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ case class GenIdeaImpl(
val resolvedModules: Seq[ResolvedModule] = {
resolveTasks.toSeq.flatMap { case (evaluator, tasks) =>
evaluator.evaluate(tasks) match {
case r if r.failing.items().nonEmpty =>
case r if r.failing.nonEmpty =>
throw GenIdeaException(
s"Failure during resolving modules: ${Evaluator.formatFailing(r)}"
)
Expand Down
4 changes: 2 additions & 2 deletions main/init/test/src/mill/init/InitModuleTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object InitModuleTests extends TestSuite {
test("no args") {
val results = evaluator.evaluator.evaluate(Agg(initmodule.init(None)))

assert(results.failing.keyCount == 0)
assert(results.failing.size == 0)

val Result.Success(Val(value)) = results.rawValues.head: @unchecked
val consoleShown = outStream.toString
Expand All @@ -42,7 +42,7 @@ object InitModuleTests extends TestSuite {
test("non existing example") {
val nonExistingModuleId = "nonExistingExampleId"
val results = evaluator.evaluator.evaluate(Agg(initmodule.init(Some(nonExistingModuleId))))
assert(results.failing.keyCount == 1)
assert(results.failing.size == 1)
assert(errStream.toString.contains(initmodule.moduleNotExistMsg(nonExistingModuleId)))
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/mill/main/MainModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import mill.moduledefs.Scaladoc
import mill.resolve.SelectMode.Separated
import mill.resolve.SelectMode
import mill.util.Util
import mill.internal.Watchable
import mill.define.Watchable
import pprint.{Renderer, Tree, Truncated}

import java.util.concurrent.LinkedBlockingQueue
Expand Down
Loading

0 comments on commit 1580715

Please sign in to comment.