Skip to content

Commit

Permalink
Add "Overhaul transitive module handling in dependency resolution" PR…
Browse files Browse the repository at this point in the history
… changes
  • Loading branch information
alexarchambault committed Jan 8, 2025
1 parent 447cf79 commit 8080950
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
32 changes: 24 additions & 8 deletions main/util/src/mill/util/CoursierSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import coursier.{Artifacts, Classifier, Dependency, Repository, Resolution, Reso
import mill.api.Loose.Agg
import mill.api.{Ctx, PathRef, Result}

import java.util.concurrent.ConcurrentHashMap

import scala.collection.mutable
import scala.util.chaining.scalaUtilChainingOps
import coursier.cache.ArchiveCache
Expand Down Expand Up @@ -39,17 +41,31 @@ trait CoursierSupport {
* come from the build and not from remote repositories or ~/.ivy2/local. See
* `MillJavaModule#{testTransitiveDeps,writeLocalTestOverrides}` in the Mill build.
*/
private class TestOverridesRepo(root: os.ResourcePath) extends Repository {
private final class TestOverridesRepo(root: os.ResourcePath) extends Repository {

private val map = new ConcurrentHashMap[Module, Option[String]]

private def listFor(mod: Module): Either[os.ResourceNotFoundException, String] = {
val classpathKey = s"${mod.organization.value}-${mod.name.value}"
val entryPath = root / classpathKey

try Right(os.read(entryPath))
catch {
case e: os.ResourceNotFoundException =>
Left(e)
}
def entryPath = root / s"${mod.organization.value}-${mod.name.value}"

val inCacheOpt = Option(map.get(mod))

inCacheOpt
.getOrElse {

val computedOpt =
try Some(os.read(entryPath))
catch {
case _: os.ResourceNotFoundException =>
None
}
val concurrentOpt = Option(map.putIfAbsent(mod, computedOpt))
concurrentOpt.getOrElse(computedOpt)
}
.toRight {
new os.ResourceNotFoundException(entryPath)
}
}

def find[F[_]: Monad](
Expand Down
16 changes: 14 additions & 2 deletions scalalib/src/mill/scalalib/CoursierModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,22 @@ object CoursierModule {
).getOrThrow

(
res.finalDependenciesCache.getOrElse(deps0.head.dep, ???),
res.finalDependenciesCache.getOrElse(
deps0.head.dep,
sys.error(
s"Should not happen - could not find root dependency ${deps0.head.dep} in Resolution#finalDependenciesCache"
)
),
DependencyManagement.addDependencies(
Map.empty,
res.projectCache.get(deps0.head.dep.moduleVersion).getOrElse(???)._2.dependencyManagement
res.projectCache
.get(deps0.head.dep.moduleVersion)
.map(_._2.dependencyManagement)
.getOrElse {
sys.error(
s"Should not happen - could not find root dependency ${deps0.head.dep.moduleVersion} in Resolution#projectCache"
)
}
)
)
}
Expand Down

0 comments on commit 8080950

Please sign in to comment.