Skip to content

Commit

Permalink
Upgrade ammonite to 1.1.2-28-e8b4996
Browse files Browse the repository at this point in the history
This is mainly to get com-lihaoyi/Ammonite#851 which
should reduce the amount of unnecessary work done by incremental
compilation in the Mill build. This requires some code changes since
this means we now depend on a more recent version of coursier, as a
side-effect this means that we do not depend on scalaz anymore.

Also use the same ammonite version in the Mill build and in
ScalaModule#ammoniteReplClasspath.
  • Loading branch information
smarter committed Aug 22, 2018
1 parent e57f026 commit a9c1b00
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ object core extends MillModule {
)

def ivyDeps = Agg(
ivy"com.lihaoyi:::ammonite:1.1.2-6-27842d9",
// Keep synchronized with ammonite in Versions.scala
ivy"com.lihaoyi:::ammonite:1.1.2-28-e8b4996",
// Necessary so we can share the JNA classes throughout the build process
ivy"net.java.dev.jna:jna:4.5.0",
ivy"net.java.dev.jna:jna-platform:4.5.0"
Expand Down
21 changes: 13 additions & 8 deletions main/src/mill/modules/Jvm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import java.util.jar.{JarEntry, JarFile, JarOutputStream}

import ammonite.ops._
import coursier.{Cache, Dependency, Fetch, Repository, Resolution}
import coursier.util.{Gather, Task}
import geny.Generator
import mill.main.client.InputPumper
import mill.eval.{PathRef, Result}
Expand Down Expand Up @@ -413,17 +414,19 @@ object Jvm {

def load(artifacts: Seq[coursier.Artifact]) = {
val logger = None
val loadedArtifacts = scalaz.concurrent.Task.gatherUnordered(

import scala.concurrent.ExecutionContext.Implicits.global
val loadedArtifacts = Gather[Task].gather(
for (a <- artifacts)
yield coursier.Cache.file(a, logger = logger).run
yield coursier.Cache.file[Task](a, logger = logger).run
.map(a.isOptional -> _)
).unsafePerformSync
).unsafeRun

val errors = loadedArtifacts.collect {
case (false, scalaz.-\/(x)) => x
case (true, scalaz.-\/(x)) if !x.notFound => x
case (false, Left(x)) => x
case (true, Left(x)) if !x.notFound => x
}
val successes = loadedArtifacts.collect { case (_, scalaz.\/-(x)) => x }
val successes = loadedArtifacts.collect { case (_, Right(x)) => x }
(errors, successes)
}

Expand Down Expand Up @@ -459,8 +462,10 @@ object Jvm {
mapDependencies = mapDependencies
)

val fetch = Fetch.from(repositories, Cache.fetch())
val resolution = start.process.run(fetch).unsafePerformSync
val fetch = Fetch.from(repositories, Cache.fetch[Task]())

import scala.concurrent.ExecutionContext.Implicits.global
val resolution = start.process.run(fetch).unsafeRun()
(deps.toSeq, resolution)
}
}
2 changes: 1 addition & 1 deletion scalalib/src/mill/scalalib/ScalaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ trait ScalaModule extends JavaModule { outer =>
unmanagedClasspath() ++
resolveDeps(T.task{
runIvyDeps() ++ scalaLibraryIvyDeps() ++ transitiveIvyDeps() ++
Agg(ivy"com.lihaoyi:::ammonite:1.1.2")
Agg(ivy"com.lihaoyi:::ammonite:${Versions.ammonite}")
})()
}

Expand Down
2 changes: 2 additions & 0 deletions scalalib/src/mill/scalalib/Versions.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mill.scalalib

object Versions {
// Keep synchronized with ammonite dependency in core in build.sc
val ammonite = "1.1.2-28-e8b4996"
// Keep synchronized with zinc dependency in scalalib.worker in build.sc
val zinc = "1.1.7"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package mill.scalalib.dependency.metadata

import coursier.Cache
import coursier.maven.MavenRepository
import coursier.util.Task
import mill.scalalib.dependency.versions.Version

private[dependency] final case class MavenMetadataLoader(mavenRepo: MavenRepository)
extends MetadataLoader {

private val fetch = Cache.fetch()
private val fetch = Cache.fetch[Task]()

override def getVersions(module: coursier.Module): List[Version] = {
import scala.concurrent.ExecutionContext.Implicits.global
// TODO fallback to 'versionsFromListing' if 'versions' doesn't work? (needs to be made public in coursier first)
val allVersions = mavenRepo.versions(module, fetch).run.unsafePerformSync
val allVersions = mavenRepo.versions(module, fetch).run.unsafeRun
allVersions
.map(_.available.map(Version(_)))
.getOrElse(List.empty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import coursier.Fetch.Content
import coursier.core.{Artifact, Module, Project, Repository}
import coursier.ivy.IvyRepository
import coursier.maven.MavenRepository
import scalaz.{EitherT, Monad}
import coursier.util.{EitherT, Monad}
import utest._

object MetadataLoaderFactoryTests extends TestSuite {
Expand All @@ -45,7 +45,7 @@ object MetadataLoaderFactoryTests extends TestSuite {
}
}
'ivyRepository - {
val ivyRepo = IvyRepository(
val Right(ivyRepo) = IvyRepository.parse(
"https://dl.bintray.com/sbt/sbt-plugin-releases/" + coursier.ivy.Pattern.default.string,
dropInfoAttributes = true)
assertMatch(MetadataLoaderFactory(ivyRepo)) { case None => }
Expand Down

0 comments on commit a9c1b00

Please sign in to comment.