Skip to content

Commit

Permalink
Support meta-build in Bloop
Browse files Browse the repository at this point in the history
  • Loading branch information
lolgab committed Jun 14, 2024
1 parent 56323c8 commit c4a83cd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion contrib/bloop/src/mill/contrib/bloop/Bloop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import mill.eval.Evaluator
/**
* Usage : `mill mill.contrib.bloop.Bloop/install`
*/
object Bloop extends BloopImpl(() => Evaluator.currentEvaluator.value, os.pwd)
object Bloop extends BloopImpl(() => Evaluator.allBootstrapEvaluators.value.value, os.pwd)
28 changes: 15 additions & 13 deletions contrib/bloop/src/mill/contrib/bloop/BloopImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import mill._
import mill.api.Result
import mill.define.{Discover, ExternalModule, Module => MillModule}
import mill.eval.Evaluator
import mill.scalalib.internal.{JavaModuleUtils, ModuleUtils}
import mill.scalalib.internal.JavaModuleUtils
import mill.scalajslib.ScalaJSModule
import mill.scalajslib.api.{JsEnvConfig, ModuleKind}
import mill.scalalib._
Expand All @@ -17,7 +17,8 @@ import mill.scalanativelib.api.ReleaseMode
* `mill.contrib.bloop.Bloop` object, and usable in tests by passing
* a custom evaluator.
*/
class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer =>
class BloopImpl(evs: () => Seq[Evaluator], wd: os.Path) extends ExternalModule {
outer =>
import BloopFormats._

private val bloopDir = wd / ".bloop"
Expand Down Expand Up @@ -116,12 +117,14 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
}

protected def computeModules: Seq[JavaModule] = {
val eval = ev()
if (eval != null)
JavaModuleUtils.transitiveModules(eval.rootModule, accept)
.collect { case jm: JavaModule => jm }
else
Seq.empty
val evals = evs()
evals.flatMap { eval =>
if (eval != null)
JavaModuleUtils.transitiveModules(eval.rootModule, accept)
.collect { case jm: JavaModule => jm }
else
Seq.empty
}
}

// class-based pattern matching against path-dependant types doesn't seem to work.
Expand All @@ -144,10 +147,7 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
Result.Success(sources.toMap)
}

protected def name(m: JavaModule): String = ModuleUtils.moduleDisplayName(m) match {
case "" => "root-module"
case n => n
}
protected def name(m: JavaModule): String = m.bspDisplayName.replace('/', '-')

protected def bloopConfigPath(module: JavaModule): os.Path =
bloopDir / s"${name(module)}.json"
Expand Down Expand Up @@ -358,6 +358,7 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
.groupBy {
case (org, mod, version, _, _) => (org, mod, version)
}
.view
.mapValues {
_.map {
case (_, mod, _, classifier, file) =>
Expand All @@ -374,8 +375,9 @@ class BloopImpl(ev: () => Evaluator, wd: os.Path) extends ExternalModule { outer
artifacts = artifacts
)
}
.toList

gatherTask.unsafeRun().toList
gatherTask.unsafeRun()
}

val bloopResolution: Task[BloopConfig.Resolution] = T.task {
Expand Down
2 changes: 1 addition & 1 deletion contrib/bloop/test/src/mill/contrib/bloop/BloopTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object BloopTests extends TestSuite {

val workdir = os.pwd / "target" / "workspace" / "bloop"
val testEvaluator = TestEvaluator.static(build)
val testBloop = new BloopImpl(() => testEvaluator.evaluator, workdir)
val testBloop = new BloopImpl(() => Seq(testEvaluator.evaluator), workdir)

object build extends TestUtil.BaseModule {

Expand Down

0 comments on commit c4a83cd

Please sign in to comment.