Skip to content

Commit

Permalink
Merge branch 'main' into remove-double-slash
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Aug 5, 2024
2 parents a293b46 + 3ac8c4a commit b3d9cd9
Show file tree
Hide file tree
Showing 23 changed files with 180 additions and 171 deletions.
6 changes: 3 additions & 3 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ private class MillBuildServer(
case m: JavaModule =>
T.task {
(
m.resolveDeps(
T.task(m.transitiveCompileIvyDeps() ++ m.transitiveIvyDeps()),
m.defaultResolver().resolveDeps(
m.transitiveCompileIvyDeps() ++ m.transitiveIvyDeps(),
sources = true
)(),
),
m.unmanagedClasspath(),
m.repositoriesTask()
)
Expand Down
5 changes: 1 addition & 4 deletions contrib/flyway/src/mill/contrib/flyway/FlywayModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ trait FlywayModule extends JavaModule {
def flywayDriverDeps: T[Agg[Dep]]

def jdbcClasspath = T {
resolveDeps(T.task {
val bind = bindDependency()
flywayDriverDeps().map(bind)
})()
defaultResolver().resolveDeps(flywayDriverDeps())
}

private def strToOptPair[A](key: String, v: String) =
Expand Down
9 changes: 3 additions & 6 deletions contrib/jmh/src/mill/contrib/jmh/JmhModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ trait JmhModule extends JavaModule {
}

def generatorDeps = T {
resolveDeps(
T.task {
val bind = bindDependency()
Agg(ivy"org.openjdk.jmh:jmh-generator-bytecode:${jmhGeneratorByteCodeVersion()}").map(bind)
}
)()
defaultResolver().resolveDeps(
Agg(ivy"org.openjdk.jmh:jmh-generator-bytecode:${jmhGeneratorByteCodeVersion()}")
)
}
}
11 changes: 5 additions & 6 deletions contrib/playlib/src/mill/playlib/RouterModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,16 @@ trait RouterModule extends ScalaModule with Version {
def generatorType: RouteCompilerType = RouteCompilerType.InjectedGenerator

def routerClasspath: T[Agg[PathRef]] = T {
resolveDeps(T.task {
val bind = bindDependency()
defaultResolver().resolveDeps(
playMinorVersion() match {
case "2.6" | "2.7" | "2.8" =>
Agg(ivy"com.typesafe.play::routes-compiler:${playVersion()}").map(bind)
Agg(ivy"com.typesafe.play::routes-compiler:${playVersion()}")
case "2.9" =>
Agg(ivy"com.typesafe.play::play-routes-compiler:${playVersion()}").map(bind)
Agg(ivy"com.typesafe.play::play-routes-compiler:${playVersion()}")
case _ =>
Agg(ivy"org.playframework::play-routes-compiler:${playVersion()}").map(bind)
Agg(ivy"org.playframework::play-routes-compiler:${playVersion()}")
}
})()
)
}

protected val routeCompilerWorker: RouteCompilerWorkerModule = RouteCompilerWorkerModule
Expand Down
6 changes: 3 additions & 3 deletions contrib/proguard/src/mill/contrib/proguard/Proguard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ trait Proguard extends ScalaModule {
* These are downloaded from JCenter and fed to `java -cp`
*/
def proguardClasspath: T[Loose.Agg[PathRef]] = T {
resolveDeps(T.task {
Agg(ivy"com.guardsquare:proguard-base:${proguardVersion()}").map(bindDependency())
})()
defaultResolver().resolveDeps(
Agg(ivy"com.guardsquare:proguard-base:${proguardVersion()}")
)
}

private def steps: T[Seq[String]] = T {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ trait ScalaPBModule extends ScalaModule {
else T { Seq.empty[PathRef] }

def scalaPBProtoClasspath: T[Agg[PathRef]] = T {
resolveDeps(T.task { transitiveCompileIvyDeps() ++ transitiveIvyDeps() })()
defaultResolver().resolveDeps(transitiveCompileIvyDeps() ++ transitiveIvyDeps())
}

def scalaPBUnpackProto: T[PathRef] = T {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,11 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>

def scoverageToolsClasspath: T[Agg[PathRef]] = T {
scoverageReportWorkerClasspath() ++
resolveDeps(T.task {
scoverageReporterIvyDeps().map(bindDependency())
})()
defaultResolver().resolveDeps(scoverageReporterIvyDeps())
}

def scoverageClasspath: T[Agg[PathRef]] = T {
resolveDeps(T.task {
scoveragePluginDeps().map(bindDependency())
})()
defaultResolver().resolveDeps(scoveragePluginDeps())
}

def scoverageReportWorkerClasspath: T[Agg[PathRef]] = T {
Expand Down Expand Up @@ -241,9 +237,7 @@ trait ScoverageModule extends ScalaModule { outer: ScalaModule =>
val outerScoverageClassesPath = outer.scoverage.compile().classes
(super.runClasspath().map { path =>
if (outerClassesPath == path) outerScoverageClassesPath else path
} ++ resolveDeps(T.task {
outer.scoverageRuntimeDeps().map(bindDependency())
})()).distinct
} ++ defaultResolver().resolveDeps(outer.scoverageRuntimeDeps())).distinct
}
}
}
5 changes: 1 addition & 4 deletions contrib/twirllib/src/mill/twirllib/TwirlModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ trait TwirlModule extends mill.Module { twirlModule =>
lazy val twirlCoursierResolver: TwirlResolver = new TwirlResolver {}

def twirlClasspath: T[Loose.Agg[PathRef]] = T {
twirlCoursierResolver.resolveDeps(T.task {
val bind = twirlCoursierResolver.bindDependency()
twirlIvyDeps().map(bind)
})
twirlCoursierResolver.defaultResolver().resolveDeps(twirlIvyDeps())
}

def twirlImports: T[Seq[String]] = T {
Expand Down
10 changes: 5 additions & 5 deletions example/javamodule/13-annotation-processors-lombok/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ Test foo.HelloWorldTest.testSimple finished...
// a module to contain the exact annotation processors you want, and pass
// in `-processorpath` to `javacOptions` explicitly:

object processors extends JavaModule{
def ivyDeps = Agg(ivy"org.projectlombok:lombok:1.18.34")
}

object bar extends JavaModule {
def compileIvyDeps = Agg(ivy"org.projectlombok:lombok:1.18.34")

def processors = T{
defaultResolver().resolveDeps(Agg(ivy"org.projectlombok:lombok:1.18.34"))
}

def javacOptions = Seq(
"-processorpath",
processors.runClasspath().map(_.path).mkString(":"),
processors().map(_.path).mkString(":"),
)

object test extends JavaTests with TestModule.Junit4
Expand Down
18 changes: 10 additions & 8 deletions example/javaweb/4-hello-micronaut/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ object hello extends RootModule with MicronautModule {
trait MicronautModule extends MavenModule{
def micronautVersion: String

object processors extends JavaModule{
def ivyDeps = Agg(
ivy"io.micronaut.data:micronaut-data-processor:4.7.0",
ivy"io.micronaut:micronaut-http-validation:$micronautVersion",
ivy"io.micronaut.serde:micronaut-serde-processor:2.9.0",
ivy"io.micronaut.validation:micronaut-validation-processor:4.5.0",
ivy"io.micronaut:micronaut-inject-java:$micronautVersion"
def processors = T{
defaultResolver().resolveDeps(
Agg(
ivy"io.micronaut.data:micronaut-data-processor:4.7.0",
ivy"io.micronaut:micronaut-http-validation:$micronautVersion",
ivy"io.micronaut.serde:micronaut-serde-processor:2.9.0",
ivy"io.micronaut.validation:micronaut-validation-processor:4.5.0",
ivy"io.micronaut:micronaut-inject-java:$micronautVersion"
)
)
}

def javacOptions = Seq(
"-processorpath",
processors.runClasspath().map(_.path).mkString(":"),
processors().map(_.path).mkString(":"),
"-parameters",
"-Amicronaut.processing.incremental=true",
"-Amicronaut.processing.group=example.micronaut",
Expand Down
18 changes: 10 additions & 8 deletions example/javaweb/5-todo-micronaut/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,21 @@ object hello extends RootModule with MicronautModule {
trait MicronautModule extends MavenModule{
def micronautVersion: String

object processors extends JavaModule{
def ivyDeps = Agg(
ivy"io.micronaut.data:micronaut-data-processor:4.7.0",
ivy"io.micronaut:micronaut-http-validation:$micronautVersion",
ivy"io.micronaut.serde:micronaut-serde-processor:2.9.0",
ivy"io.micronaut.validation:micronaut-validation-processor:4.5.0",
ivy"io.micronaut:micronaut-inject-java:$micronautVersion"
def processors = T {
defaultResolver().resolveDeps(
Agg(
ivy"io.micronaut.data:micronaut-data-processor:4.7.0",
ivy"io.micronaut:micronaut-http-validation:$micronautVersion",
ivy"io.micronaut.serde:micronaut-serde-processor:2.9.0",
ivy"io.micronaut.validation:micronaut-validation-processor:4.5.0",
ivy"io.micronaut:micronaut-inject-java:$micronautVersion"
)
)
}

def javacOptions = Seq(
"-processorpath",
processors.runClasspath().map(_.path).mkString(":"),
processors().map(_.path).mkString(":"),
"-parameters",
"-Amicronaut.processing.incremental=true",
"-Amicronaut.processing.group=example.micronaut",
Expand Down
10 changes: 6 additions & 4 deletions example/thirdparty/netty/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ trait NettyJniModule extends NettyModule {
Seq(PathRef(T.dest))
}
def clang = T{
val Seq(sourceJar) = resolveDeps(
deps = T.task(Agg(ivy"io.netty:netty-jni-util:0.0.9.Final").map(bindDependency())),
sources = true
)().toSeq
val Seq(sourceJar) = defaultResolver()
.resolveDeps(
Agg(ivy"io.netty:netty-jni-util:0.0.9.Final").map(bindDependency()),
sources = true
)
.toSeq

os.makeDir.all(T.dest / "src" / "main" / "c")
os.proc("jar", "xf", sourceJar.path).call(cwd = T.dest / "src" / "main" / "c")
Expand Down
18 changes: 5 additions & 13 deletions idea/src/mill/idea/GenIdeaImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,16 @@ case class GenIdeaImpl(
}

val externalLibraryDependencies = T.task {
mod.resolveDeps(T.task {
val bind = mod.bindDependency()
mod.mandatoryIvyDeps().map(bind)
})()
mod.defaultResolver().resolveDeps(mod.mandatoryIvyDeps())
}

val externalDependencies = T.task {
mod.resolvedIvyDeps() ++
T.traverse(mod.transitiveModuleDeps)(_.unmanagedClasspath)().flatten
}
val extCompileIvyDeps =
mod.resolveDeps(T.task {
val bind = mod.bindDependency()
mod.compileIvyDeps().map(bind)
})
val extCompileIvyDeps = T.task {
mod.defaultResolver().resolveDeps(mod.compileIvyDeps())
}
val extRunIvyDeps = mod.resolvedRunIvyDeps

val externalSources = T.task {
Expand All @@ -175,10 +170,7 @@ case class GenIdeaImpl(
}

val scalacPluginDependencies = T.task {
mod.resolveDeps(T.task {
val bind = mod.bindDependency()
scalacPluginsIvyDeps().map(bind)
})()
mod.defaultResolver().resolveDeps(scalacPluginsIvyDeps())
}

val facets = T.task {
Expand Down
7 changes: 5 additions & 2 deletions main/api/src/mill/api/Result.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ sealed trait Result[+T] {
def flatMap[V](f: T => Result[V]): Result[V]
def asSuccess: Option[Result.Success[T]] = None
def asFailing: Option[Result.Failing[T]] = None

def getOrThrow: T = this match {
case Result.Success(v) => v
case f: Result.Failing[_] => throw f
}
}

object Result {
Expand Down Expand Up @@ -55,7 +58,7 @@ object Result {
* A failed task execution.
* @tparam T The result type of the computed task.
*/
sealed trait Failing[+T] extends Result[T] {
sealed trait Failing[+T] extends java.lang.Exception with Result[T] {
def map[V](f: T => V): Failing[V]
def flatMap[V](f: T => Result[V]): Failing[V]
override def asFailing: Option[Result.Failing[T]] = Some(this)
Expand Down
1 change: 1 addition & 0 deletions main/eval/src/mill/eval/GroupEvaluator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ private[mill] trait GroupEvaluator {
mill.api.SystemStreams.withStreams(multiLogger.systemStreams) {
try task.evaluate(args).map(Val(_))
catch {
case f: Result.Failing[Val] => f
case NonFatal(e) =>
Result.Exception(
e,
Expand Down
5 changes: 2 additions & 3 deletions runner/src/mill/runner/MillBuildRootModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,8 @@ class MillBuildRootModule()(implicit
)
}

override def resolveDeps(deps: Task[Agg[BoundDep]], sources: Boolean): Task[Agg[PathRef]] = {
val excludeProvided = T.task { deps().map(_.exclude(resolveDepsExclusions(): _*)) }
super.resolveDeps(excludeProvided, sources)
override def bindDependency: Task[Dep => BoundDep] = T.task { dep: Dep =>
super.bindDependency().apply(dep).exclude(resolveDepsExclusions(): _*)
}

override def unmanagedClasspath: T[Agg[PathRef]] = T {
Expand Down
7 changes: 3 additions & 4 deletions scalajslib/src/mill/scalajslib/ScalaJSModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,13 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>
trait TestScalaJSModule extends ScalaJSModule with TestModule {

def scalaJSTestDeps = T {
resolveDeps(T.task {
val bind = bindDependency()
defaultResolver().resolveDeps(
Loose.Agg(
ivy"org.scala-js::scalajs-library:${scalaJSVersion()}",
ivy"org.scala-js::scalajs-test-bridge:${scalaJSVersion()}"
)
.map(dep => bind(dep.withDottyCompat(scalaVersion())))
})
.map(_.withDottyCompat(scalaVersion()))
)
}

def fastLinkJSTest: Target[Report] = T.persistent {
Expand Down
53 changes: 52 additions & 1 deletion scalalib/src/mill/scalalib/CoursierModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package mill.scalalib
import coursier.cache.FileCache
import coursier.{Dependency, Repository, Resolve}
import coursier.core.Resolution
import mill.{Agg, T}
import mill.T
import mill.define.Task
import mill.api.PathRef

import scala.annotation.nowarn
import scala.concurrent.Await
import scala.concurrent.duration.Duration
import mill.Agg

/**
* This module provides the capability to resolve (transitive) dependencies from (remote) repositories.
Expand All @@ -32,6 +33,17 @@ trait CoursierModule extends mill.Module {
Lib.depToDependencyJava(_: Dep)
}

def defaultResolver: Task[CoursierModule.Resolver] = T.task {
new CoursierModule.Resolver(
repositories = repositoriesTask(),
bind = bindDependency(),
mapDependencies = Some(mapDependencies()),
customizer = resolutionCustomizer(),
coursierCacheCustomizer = coursierCacheCustomizer(),
ctx = Some(implicitly[mill.api.Ctx.Log])
)
}

/**
* Task that resolves the given dependencies using the repositories defined with [[repositoriesTask]].
*
Expand Down Expand Up @@ -108,3 +120,42 @@ trait CoursierModule extends mill.Module {
T.task { None }

}
object CoursierModule {

class Resolver(
repositories: Seq[Repository],
bind: Dep => BoundDep,
mapDependencies: Option[Dependency => Dependency] = None,
customizer: Option[coursier.core.Resolution => coursier.core.Resolution] = None,
ctx: Option[mill.api.Ctx.Log] = None,
coursierCacheCustomizer: Option[
coursier.cache.FileCache[coursier.util.Task] => coursier.cache.FileCache[coursier.util.Task]
] = None
) {

def resolveDeps[T: CoursierModule.Resolvable](
deps: IterableOnce[T],
sources: Boolean = false
): Agg[PathRef] = {
Lib.resolveDependencies(
repositories = repositories,
deps = deps.map(implicitly[CoursierModule.Resolvable[T]].bind(_, bind)),
sources = sources,
mapDependencies = mapDependencies,
customizer = customizer,
coursierCacheCustomizer = coursierCacheCustomizer,
ctx = ctx
).getOrThrow
}
}

sealed trait Resolvable[T] {
def bind(t: T, bind: Dep => BoundDep): BoundDep
}
implicit case object ResolvableDep extends Resolvable[Dep] {
def bind(t: Dep, bind: Dep => BoundDep): BoundDep = bind(t)
}
implicit case object ResolvableBoundDep extends Resolvable[BoundDep] {
def bind(t: BoundDep, bind: Dep => BoundDep): BoundDep = t
}
}
Loading

0 comments on commit b3d9cd9

Please sign in to comment.