Skip to content

Commit

Permalink
more - needs clean-up, only checking if CI passes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Nov 27, 2024
1 parent 03857e0 commit 745b500
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 112 deletions.
2 changes: 1 addition & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ object Deps {
val asmTree = ivy"org.ow2.asm:asm-tree:9.7.1"
val bloopConfig = ivy"ch.epfl.scala::bloop-config:1.5.5"

val coursierVersion = "2.1.18"
val coursierVersion = "2.1.19"
val coursier = ivy"io.get-coursier::coursier:$coursierVersion"
val coursierInterface = ivy"io.get-coursier:interface:1.0.24"
val coursierJvm = ivy"io.get-coursier::coursier-jvm:$coursierVersion"
Expand Down
15 changes: 4 additions & 11 deletions main/util/src/mill/util/CoursierSupport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ trait CoursierSupport {
coursierCacheCustomizer: Option[FileCache[Task] => FileCache[Task]] = None,
resolveFilter: os.Path => Boolean = _ => true,
artifactTypes: Option[Set[Type]] = None,
resolutionParams: ResolutionParams = ResolutionParams(),
bomDeps: IterableOnce[(Module, String)] = Nil
resolutionParams: ResolutionParams = ResolutionParams()
): Result[Agg[PathRef]] = {
val (localTestDeps, remoteDeps) =
deps.iterator.toSeq.partitionMap(d => isLocalTestDep(d).toLeft(d))
Expand All @@ -77,8 +76,7 @@ trait CoursierSupport {
customizer,
ctx,
coursierCacheCustomizer,
resolutionParams,
bomDeps
resolutionParams
)

resolutionRes.flatMap { resolution =>
Expand Down Expand Up @@ -191,8 +189,7 @@ trait CoursierSupport {
customizer,
ctx,
coursierCacheCustomizer,
ResolutionParams(),
Nil
ResolutionParams()
)
(deps0, res.getOrThrow)
}
Expand Down Expand Up @@ -256,17 +253,14 @@ trait CoursierSupport {
customizer: Option[Resolution => Resolution] = None,
ctx: Option[mill.api.Ctx.Log] = None,
coursierCacheCustomizer: Option[FileCache[Task] => FileCache[Task]] = None,
resolutionParams: ResolutionParams = ResolutionParams(),
bomDeps: IterableOnce[(Module, String)] = Nil
resolutionParams: ResolutionParams = ResolutionParams()
): Result[Resolution] = {

val rootDeps = deps.iterator
.map(d => mapDependencies.fold(d)(_.apply(d)))
.filter(dep => isLocalTestDep(dep).isEmpty)
.toSeq

val bomDeps0 = bomDeps.iterator.toSeq

val forceVersions = force.iterator
.map(mapDependencies.getOrElse(identity[Dependency](_)))
.map { d => d.module -> d.version }
Expand All @@ -280,7 +274,6 @@ trait CoursierSupport {
val resolve = Resolve()
.withCache(coursierCache0)
.withDependencies(rootDeps)
.withBomModuleVersions(bomDeps0)
.withRepositories(repositories)
.withResolutionParams(resolutionParams0)
.withMapDependenciesOpt(mapDependencies)
Expand Down
52 changes: 20 additions & 32 deletions scalalib/src/mill/scalalib/CoursierModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ trait CoursierModule extends mill.Module {
def resolveDeps(
deps: Task[Agg[BoundDep]],
sources: Boolean = false,
artifactTypes: Option[Set[Type]] = None,
bomDeps: Task[Agg[(Module, String)]] = Task.Anon(Agg.empty[(Module, String)])
artifactTypes: Option[Set[Type]] = None
): Task[Agg[PathRef]] =
Task.Anon {
Lib.resolveDependencies(
Expand All @@ -68,25 +67,16 @@ trait CoursierModule extends mill.Module {
mapDependencies = Some(mapDependencies()),
customizer = resolutionCustomizer(),
coursierCacheCustomizer = coursierCacheCustomizer(),
ctx = Some(implicitly[mill.api.Ctx.Log]),
bomDeps = bomDeps()
ctx = Some(implicitly[mill.api.Ctx.Log])
)
}

// bin-compat shim
def resolveDeps(
deps: Task[Agg[BoundDep]],
sources: Boolean,
artifactTypes: Option[Set[Type]]
): Task[Agg[PathRef]] =
resolveDeps(deps, sources, artifactTypes, Task.Anon(Agg.empty[(Module, String)]))

@deprecated("Use the override accepting artifactTypes", "Mill after 0.12.0-RC3")
def resolveDeps(
deps: Task[Agg[BoundDep]],
sources: Boolean
): Task[Agg[PathRef]] =
resolveDeps(deps, sources, None, Task.Anon(Agg.empty[(Module, String)]))
resolveDeps(deps, sources, None)

/**
* Map dependencies before resolving them.
Expand Down Expand Up @@ -205,8 +195,7 @@ object CoursierModule {
def resolveDeps[T: CoursierModule.Resolvable](
deps: IterableOnce[T],
sources: Boolean = false,
artifactTypes: Option[Set[coursier.Type]] = None,
bomDeps: IterableOnce[(Module, String)] = Nil
artifactTypes: Option[Set[coursier.Type]] = None
): Agg[PathRef] = {
Lib.resolveDependencies(
repositories = repositories,
Expand All @@ -217,25 +206,16 @@ object CoursierModule {
customizer = customizer,
coursierCacheCustomizer = coursierCacheCustomizer,
ctx = ctx,
resolutionParams = resolutionParams,
bomDeps = bomDeps
resolutionParams = resolutionParams
).getOrThrow
}

// bin-compat shim
def resolveDeps[T: CoursierModule.Resolvable](
deps: IterableOnce[T],
sources: Boolean,
artifactTypes: Option[Set[coursier.Type]]
): Agg[PathRef] =
resolveDeps(deps, sources, artifactTypes, Nil)

@deprecated("Use the override accepting artifactTypes", "Mill after 0.12.0-RC3")
def resolveDeps[T: CoursierModule.Resolvable](
deps: IterableOnce[T],
sources: Boolean
): Agg[PathRef] =
resolveDeps(deps, sources, None, Nil)
resolveDeps(deps, sources, None)

/**
* Processes dependencies and BOMs with coursier
Expand All @@ -248,13 +228,11 @@ object CoursierModule {
*
* @param deps dependencies that might have placeholder versions ("_" as version)
* @param resolutionParams coursier resolution parameters
* @param bomDeps dependencies to read Bill-Of-Materials from
* @return dependencies with version placeholder filled and data read from the BOM dependencies
*/
def processDeps[T: CoursierModule.Resolvable](
deps: IterableOnce[T],
resolutionParams: ResolutionParams = ResolutionParams(),
bomDeps: IterableOnce[(Module, String)] = Nil
resolutionParams: ResolutionParams = ResolutionParams()
): (Seq[Dependency], DependencyManagement.Map) = {
val deps0 = deps
.map(implicitly[CoursierModule.Resolvable[T]].bind(_, bind))
Expand All @@ -265,10 +243,20 @@ object CoursierModule {
customizer = customizer,
coursierCacheCustomizer = coursierCacheCustomizer,
ctx = ctx,
resolutionParams = resolutionParams,
bomDeps = bomDeps
resolutionParams = resolutionParams
).getOrThrow
(res.processedRootDependencies, res.bomDepMgmt)
val depMgmt: DependencyManagement.Map =
if (res.processedRootDependencies.isEmpty) Map.empty
else {
val overrides = res.processedRootDependencies.map(_.overrides)
overrides.tail.foldLeft(overrides.head) { (acc, map) =>
acc.filter {
case (key, values) =>
map.get(key).contains(values)
}
}
}
(res.processedRootDependencies, depMgmt)
}
}

Expand Down
Loading

0 comments on commit 745b500

Please sign in to comment.