Skip to content

Commit

Permalink
Improve performances of Bloop/install (#4600)
Browse files Browse the repository at this point in the history
Prevents having to iteratively querying the location of each artifact's
resolved files. This makes a big difference in large mill projects.
  • Loading branch information
Baccata authored Feb 21, 2025
1 parent 3fe568a commit 601c5ae
Showing 1 changed file with 38 additions and 56 deletions.
94 changes: 38 additions & 56 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -317,63 +317,45 @@ class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
import coursier._
import coursier.util._

def source(r: Resolution) = Resolution(
r.dependencies
.map(d =>
d.withAttributes(
d.attributes.withClassifier(coursier.Classifier("sources"))
)
)
.toSeq
)

import scala.concurrent.ExecutionContext.Implicits.global
val unresolved = Resolution(deps)
val fetch =
ResolutionProcess.fetch(repos, coursier.cache.Cache.default.fetch)
val gatherTask =
for {
resolved <- unresolved.process.run(fetch)
resolvedSources <- source(resolved).process.run(fetch)
all = resolved.dependencyArtifacts() ++ resolvedSources.dependencyArtifacts()
gathered <- Gather[Task].gather(all.distinct.map {
case (dep, pub, art) =>
coursier.cache.Cache.default.file(art).run.map(dep -> _)
})
} yield gathered
.collect {
case (dep, Right(file)) if os.Path(file).ext == "jar" =>
(
dep.module.organization,
dep.module.name,
dep.version,
Option(dep.attributes.classifier).filter(_.nonEmpty),
file
)
}
.groupBy {
case (org, mod, version, _, _) => (org, mod, version)
}
.view
.mapValues {
_.map {
case (_, mod, _, classifier, file) =>
BloopConfig.Artifact(mod.value, classifier.map(_.value), None, file.toPath)
}.toList
}
.map {
case ((org, mod, version), artifacts) =>
BloopConfig.Module(
organization = org.value,
name = mod.value,
version = version,
configurations = None,
artifacts = artifacts
)
}
.toList

gatherTask.unsafeRun()
Fetch(coursier.cache.FileCache())
.addRepositories(repos*)
.addDependencies(deps*)
.withMainArtifacts()
.addClassifiers(coursier.Classifier("sources"))
.runResult()
.fullDetailedArtifacts
.collect {
case (dep, _, _, Some(file)) if os.Path(file).ext == "jar" =>
(
dep.module.organization,
dep.module.name,
dep.version,
Option(dep.attributes.classifier).filter(_.nonEmpty),
file
)
}
.groupBy {
case (org, mod, version, _, _) => (org, mod, version)
}
.view
.mapValues {
_.map {
case (_, mod, _, classifier, file) =>
BloopConfig.Artifact(mod.value, classifier.map(_.value), None, file.toPath)
}.toList
}
.map {
case ((org, mod, version), artifacts) =>
BloopConfig.Module(
organization = org.value,
name = mod.value,
version = version,
configurations = None,
artifacts = artifacts
)
}
.toList
}

val bloopResolution: Task[BloopConfig.Resolution] = Task.Anon {
Expand Down

0 comments on commit 601c5ae

Please sign in to comment.