Skip to content

Commit

Permalink
add meta-build modules
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi committed Apr 5, 2023
1 parent ee05abb commit 39e0069
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 116 deletions.
53 changes: 37 additions & 16 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ class MillBuildServer(
idToModule match {
case None =>
val modules: Seq[Module] =
ModuleUtils.transitiveModules(evaluator.rootModule) ++ Seq(`mill-build`)
ModuleUtils.transitiveModules(evaluator.rootModule) ++ millBuildRootModules
val map = modules.collect {
case m: MillBuildRootModule =>
val uri = sanitizeUri(m.millSourcePath)
val id = new BuildTargetIdentifier(uri)
log.debug(s"mill-build segments: ${`mill-build`.millModuleSegments.render}")
for(millBuild <- millBuildRootModules){
log.debug(s"mill-build segments: ${millBuild.millModuleSegments.render}")
}
(id, m)
case m: BspModule =>
val uri = sanitizeUri(`mill-build`.millSourcePath / m.millModuleSegments.parts)
val uri = sanitizeUri(??? : os.Path)
val id = new BuildTargetIdentifier(uri)
(id, m)
}.toMap
Expand All @@ -74,18 +76,36 @@ class MillBuildServer(
private[MillBuildServer] var modulesToId: Option[Map[BspModule, BuildTargetIdentifier]] = None
}

lazy val `mill-build`: mill.scalalib.bootstrap.MillBuildRootModule = {
implicit val millBaseModuleInfo: mill.main.RootModule.Info = mill.main.RootModule.Info(
evaluator.rootModule.millSourcePath,
_root_.mill.define.Discover[bootstrapModule.type]
)
object bootstrapModule extends mill.scalalib.bootstrap.MillBuildRootModule.BootstrapModule(
topLevelProjectRoot0 = evaluator.rootModule.millSourcePath,
lazy val millBuildRootModules: Seq[mill.scalalib.bootstrap.MillBuildRootModule] = {
val evaluated = new mill.scalalib.bootstrap.MillBuildBootstrap(
projectRoot = evaluator.rootModule.millSourcePath,
enclosingClasspath = Nil
)
home = os.home,
keepGoing = false,
env = Map.empty,
threadCount = None,
targetsAndParams = Seq("resolve", "_"),
prevRunnerState = mill.scalalib.bootstrap.RunnerState.empty,
logger = evaluator.baseLogger
).evaluate()

val allModules =
evaluated.result.bootstrapModuleOpt.toSeq ++
evaluated.result.frames
.zipWithIndex
// The depth=0 frame is for running user code, not for the build
.drop(1)
.flatMap{
case (f, i) =>
f.classLoaderOpt
.flatMap(
mill.scalalib.bootstrap.MillBuildBootstrap
.getRootModule0(_, i, evaluator.rootModule.millSourcePath)
.toOption

)
}

bootstrapModule.build
allModules.map(_.asInstanceOf[mill.scalalib.bootstrap.MillBuildRootModule])
}

def bspModulesById: Map[BuildTargetIdentifier, BspModule] = {
Expand Down Expand Up @@ -517,7 +537,7 @@ class MillBuildServer(
import state._

val modules = bspModulesById.values.toSeq.collect { case m: JavaModule => m }
val millBuildTargetId = bspIdByModule(`mill-build`)
val millBuildTargetIds = millBuildRootModules.map(bspIdByModule(_)).toSet

val params = TaskParameters.fromTestParams(testParams)
val argsMap =
Expand All @@ -537,7 +557,7 @@ class MillBuildServer(
}

val overallStatusCode = testParams.getTargets.asScala
.filter(_ != millBuildTargetId)
.filter(millBuildTargetIds.contains)
.foldLeft(StatusCode.OK) { (overallStatusCode, targetId) =>
bspModulesById(targetId) match {
case testModule: TestModule =>
Expand Down Expand Up @@ -603,8 +623,9 @@ class MillBuildServer(
completable(s"buildTargetCleanCache ${cleanCacheParams}") { state =>
import state._

val targetIds = millBuildRootModules.map(_.buildTargetId)
val (msg, cleaned) =
cleanCacheParams.getTargets.asScala.filter(_ != `mill-build`.buildTargetId).foldLeft((
cleanCacheParams.getTargets.asScala.filter(targetIds.contains).foldLeft((
"",
true
)) {
Expand Down
76 changes: 38 additions & 38 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -696,44 +696,44 @@ object contrib extends MillModule {
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
}

object playlib extends MillModule {
override def moduleDeps = Seq(twirllib, playlib.api)
override def compileModuleDeps = Seq(scalalib)

override def testArgs = T {
val mapping = Map(
"MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_6" -> worker("2.6").assembly().path,
"MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_7" -> worker("2.7").assembly().path,
"MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_8" -> worker("2.8").assembly().path,
"TEST_PLAY_VERSION_2_6" -> Deps.Play_2_6.playVersion,
"TEST_PLAY_VERSION_2_7" -> Deps.Play_2_7.playVersion,
"TEST_PLAY_VERSION_2_8" -> Deps.Play_2_8.playVersion
)

scalalib.worker.testArgs() ++
scalalib.backgroundwrapper.testArgs() ++
(for ((k, v) <- mapping.to(Seq)) yield s"-D$k=$v")
}
override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)

object api extends MillPublishModule

object worker extends Cross[WorkerModule](Deps.play.keys.toSeq: _*)
class WorkerModule(playBinary: String) extends MillInternalModule {
override def sources = T.sources {
// We want to avoid duplicating code as long as the Play APIs allow.
// But if newer Play versions introduce incompatibilities,
// just remove the shared source dir for that worker and implement directly.
Seq(PathRef(millSourcePath / os.up / "src-shared")) ++ super.sources()
}
override def scalaVersion = Deps.play(playBinary).scalaVersion
override def moduleDeps = Seq(playlib.api)
override def ivyDeps = Agg(
Deps.osLib,
Deps.play(playBinary).routesCompiler
)
}
}
// object playlib extends MillModule {
// override def moduleDeps = Seq(twirllib, playlib.api)
// override def compileModuleDeps = Seq(scalalib)
//
// override def testArgs = T {
// val mapping = Map(
// "MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_6" -> worker("2.6").assembly().path,
// "MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_7" -> worker("2.7").assembly().path,
// "MILL_CONTRIB_PLAYLIB_ROUTECOMPILER_WORKER_2_8" -> worker("2.8").assembly().path,
// "TEST_PLAY_VERSION_2_6" -> Deps.Play_2_6.playVersion,
// "TEST_PLAY_VERSION_2_7" -> Deps.Play_2_7.playVersion,
// "TEST_PLAY_VERSION_2_8" -> Deps.Play_2_8.playVersion
// )
//
// scalalib.worker.testArgs() ++
// scalalib.backgroundwrapper.testArgs() ++
// (for ((k, v) <- mapping.to(Seq)) yield s"-D$k=$v")
// }
// override def testModuleDeps: Seq[JavaModule] = super.testModuleDeps ++ Seq(scalalib)
//
// object api extends MillPublishModule
//
// object worker extends Cross[WorkerModule](Deps.play.keys.toSeq: _*)
// class WorkerModule(playBinary: String) extends MillInternalModule {
// override def sources = T.sources {
// // We want to avoid duplicating code as long as the Play APIs allow.
// // But if newer Play versions introduce incompatibilities,
// // just remove the shared source dir for that worker and implement directly.
// Seq(PathRef(millSourcePath / os.up / "src-shared")) ++ super.sources()
// }
// override def scalaVersion = Deps.play(playBinary).scalaVersion
// override def moduleDeps = Seq(playlib.api)
// override def ivyDeps = Agg(
// Deps.osLib,
// Deps.play(playBinary).routesCompiler
// )
// }
// }

object scalapblib extends MillModule {
override def compileModuleDeps = Seq(scalalib)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mill.integration

import mill.runner.RunnerState
import mill.scalalib.bootstrap.RunnerState
import utest._

import scala.util.matching.Regex
Expand Down
7 changes: 5 additions & 2 deletions integration/src/mill/integration/IntegrationTestSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package mill.integration
import mainargs.Flag
import mill.MillCliConfig
import mill.define.SelectMode
import mill.runner.{MillBuildBootstrap, MillMain, RunnerState, Watching}
import mill.runner.{MillMain, Watching}
import mill.scalalib.bootstrap.{MillBuildBootstrap, RunnerState}
import mill.util.SystemStreams
import os.Path
import utest._
Expand Down Expand Up @@ -64,9 +65,11 @@ abstract class IntegrationTestSuite extends TestSuite {
setIdle = _ => (),
evaluate = (prevStateOpt: Option[RunnerState]) => {
MillMain.adjustJvmProperties(userSpecifiedProperties, sys.props.toMap)
val a = config.keepGoing
new MillBuildBootstrap(
projectRoot = wd,
config = config,
home = config.home,
keepGoing = config.keepGoing.value,
env = Map.empty,
threadCount = threadCount,
targetsAndParams = s.toList,
Expand Down
4 changes: 3 additions & 1 deletion runner/src/mill/runner/MillMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import scala.util.Properties
import io.github.retronym.java9rtexport.Export
import mill.api.{DummyInputStream, internal}
import mill.main.BspServerResult
import mill.scalalib.bootstrap.{MillBuildBootstrap, RunnerState}
import mill.util.SystemStreams

@internal
Expand Down Expand Up @@ -190,7 +191,8 @@ object MillMain {

new MillBuildBootstrap(
projectRoot = os.pwd,
config = config,
home = config.home,
keepGoing = config.keepGoing.value,
env = env,
threadCount = threadCount,
targetsAndParams = targetsAndParams,
Expand Down
1 change: 1 addition & 0 deletions runner/src/mill/runner/MillServerMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import mill.BuildInfo
import mill.main.client._
import mill.api.internal
import mill.main.client.lock.{Lock, Locks}
import mill.scalalib.bootstrap.RunnerState
import mill.util.SystemStreams

@internal
Expand Down
3 changes: 2 additions & 1 deletion runner/src/mill/runner/Watching.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mill.runner

import mill.api.internal
import mill.define.Watchable
import mill.scalalib.bootstrap.Result
import mill.util.{ColorLogger, SystemStreams}

import java.io.InputStream
Expand All @@ -13,7 +14,7 @@ import scala.annotation.tailrec
*/
@internal
object Watching {
case class Result[T](watched: Seq[Watchable], error: Option[String], result: T)


def watchLoop[T](
logger: ColorLogger,
Expand Down
Loading

0 comments on commit 39e0069

Please sign in to comment.