Skip to content

Commit

Permalink
Merge branch 'main' into ci-java-21
Browse files Browse the repository at this point in the history
  • Loading branch information
lefou authored Oct 15, 2024
2 parents affe9a1 + 7c0f7a0 commit 817971f
Show file tree
Hide file tree
Showing 314 changed files with 6,363 additions and 1,323 deletions.
2 changes: 1 addition & 1 deletion .config/mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.12.0-RC3
0.12.0-RC3-46-80d164
2 changes: 1 addition & 1 deletion .github/workflows/run-mill-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
shell: bash
continue-on-error: true

- uses: actions/upload-artifact@v4.3.5
- uses: actions/upload-artifact@v4.4.3
with:
path: .
name: ${{ inputs.os }}-artifact
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }

- run: ./mill -i docs.githubPages
- run: ./mill -i docs.githubPages + docs.checkBrokenLinks

linux:
needs: build-linux
Expand Down
7 changes: 3 additions & 4 deletions bsp/src/mill/bsp/BSP.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ object BSP extends ExternalModule with CoursierModule {
}

private def bspConnectionJson(jobs: Int, debug: Boolean): String = {
val props = sys.props
val millPath = props
.get("mill.main.cli")
val millPath = sys.env.get("MILL_MAIN_CLI")
.orElse(sys.props.get("mill.main.cli"))
// we assume, the classpath is an executable jar here
.orElse(props.get("java.class.path"))
.orElse(sys.props.get("java.class.path"))
.getOrElse(throw new IllegalStateException("System property 'java.class.path' not set"))

upickle.default.write(
Expand Down
2 changes: 1 addition & 1 deletion bsp/src/mill/bsp/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ private[mill] object Constants {
val bspProtocolVersion = BuildInfo.bsp4jVersion
val bspWorkerImplClass = "mill.bsp.worker.BspWorkerImpl"
val bspWorkerBuildInfoClass = "mill.bsp.worker.BuildInfo"
val languages: Seq[String] = Seq("scala", "java")
val languages: Seq[String] = Seq("java", "scala", "kotlin")
val serverName = "mill-bsp"
}
4 changes: 2 additions & 2 deletions bsp/worker/src/mill/bsp/worker/MillBspLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import mill.util.{ColorLogger, ProxyLogger}
private class MillBspLogger(client: BuildClient, taskId: Int, logger: Logger)
extends ProxyLogger(logger)
with ColorLogger {
def infoColor = fansi.Color.Blue
def errorColor = fansi.Color.Red
override def infoColor = fansi.Color.Blue
override def errorColor = fansi.Color.Red

override def ticker(s: String): Unit = {
try {
Expand Down
54 changes: 35 additions & 19 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ch.epfl.scala.bsp4j
import ch.epfl.scala.bsp4j._
import com.google.gson.JsonObject
import mill.api.{DummyTestReporter, Result, Strict}
import mill.bsp.BspServerResult
import mill.bsp.{BspServerResult, Constants}
import mill.bsp.worker.Utils.{makeBuildTarget, outputPaths, sanitizeUri}
import mill.define.Segment.Label
import mill.define.{Args, Discover, ExternalModule, Task}
Expand Down Expand Up @@ -33,6 +33,8 @@ private class MillBuildServer(
) extends ExternalModule
with BuildServer {

import MillBuildServer._

lazy val millDiscover: Discover = Discover[this.type]

private[worker] var cancellator: Boolean => Unit = shutdownBefore => ()
Expand Down Expand Up @@ -71,7 +73,7 @@ private class MillBuildServer(

// TODO: scan BspModules and infer their capabilities

val supportedLangs = Seq("java", "scala").asJava
val supportedLangs = Constants.languages.asJava
val capabilities = new BuildServerCapabilities

capabilities.setBuildTargetChangedProvider(false)
Expand Down Expand Up @@ -154,7 +156,7 @@ private class MillBuildServer(
override def workspaceBuildTargets(): CompletableFuture[WorkspaceBuildTargetsResult] =
completableTasksWithState(
"workspaceBuildTargets",
targetIds = _.bspModulesById.keySet.toSeq,
targetIds = _.bspModulesIdList.map(_._1),
tasks = { case m: BspModule => m.bspBuildTargetData }
) { (ev, state, id, m: BspModule, bspBuildTargetData) =>
val depsIds = m match {
Expand All @@ -173,14 +175,12 @@ private class MillBuildServer(
bsp4j.ScalaPlatform.forValue(d.platform.number),
d.jars.asJava
)
for (jvmBuildTarget <- d.jvmBuildTarget)
target.setJvmBuildTarget(MillBuildServer.jvmBuildTarget(jvmBuildTarget))
Some((dataKind, target))

case Some((dataKind, d: JvmBuildTarget)) =>
val target = new bsp4j.JvmBuildTarget().tap { it =>
d.javaHome.foreach(jh => it.setJavaHome(jh.uri))
d.javaVersion.foreach(jv => it.setJavaVersion(jv))
}
Some((dataKind, target))
Some((dataKind, jvmBuildTarget(d)))

case Some((dataKind, d)) =>
debug(s"Unsupported dataKind=${dataKind} with value=${d}")
Expand Down Expand Up @@ -230,8 +230,7 @@ private class MillBuildServer(
tasks = {
case module: MillBuildRootModule =>
Task.Anon {
module.scriptSources().map(p => sourceItem(p.path, false)) ++
module.sources().map(p => sourceItem(p.path, false)) ++
module.sources().map(p => sourceItem(p.path, false)) ++
module.generatedSources().map(p => sourceItem(p.path, true))
}
case module: JavaModule =>
Expand All @@ -253,7 +252,7 @@ private class MillBuildServer(
override def buildTargetInverseSources(p: InverseSourcesParams)
: CompletableFuture[InverseSourcesResult] = {
completable(s"buildtargetInverseSources ${p}") { state =>
val tasksEvaluators = state.bspModulesById.iterator.collect {
val tasksEvaluators = state.bspModulesIdList.iterator.collect {
case (id, (m: JavaModule, ev)) =>
Task.Anon {
val src = m.allSourceFiles()
Expand All @@ -264,11 +263,9 @@ private class MillBuildServer(
} -> ev
}.toSeq

val ids = tasksEvaluators
.groupMap(_._2)(_._1)
val ids = groupList(tasksEvaluators)(_._2)(_._1)
.flatMap { case (ev, ts) => ev.evalOrThrow()(ts) }
.flatten
.toSeq

new InverseSourcesResult(ids.asJava)
}
Expand Down Expand Up @@ -635,16 +632,15 @@ private class MillBuildServer(
State
) => V): CompletableFuture[V] = {
val prefix = hint.split(" ").head
completable(hint) { state: State =>
completable(hint) { (state: State) =>
val ids = state.filterNonSynthetic(targetIds(state).asJava).asScala
val tasksSeq = ids.flatMap { id =>
val (m, ev) = state.bspModulesById(id)
tasks.lift.apply(m).map(ts => (ts, (ev, id)))
}

val evaluated = tasksSeq
// group by evaluator (different root module)
.groupMap(_._2)(_._1)
// group by evaluator (different root module)
val evaluated = groupList(tasksSeq.toSeq)(_._2)(_._1)
.map { case ((ev, id), ts) =>
val results = ev.evaluate(ts)
val failures = results.results.collect {
Expand Down Expand Up @@ -675,7 +671,7 @@ private class MillBuildServer(
}
}

agg(evaluated.flatten.toSeq.asJava, state)
agg(evaluated.flatten.asJava, state)
}
}

Expand Down Expand Up @@ -773,3 +769,23 @@ private class MillBuildServer(
debug("onRunReadStdin is current unsupported")
}
}

private object MillBuildServer {

/**
* Same as Iterable.groupMap, but returns a sequence instead of a map, and preserves
* the order of appearance of the keys from the input sequence
*/
private def groupList[A, K, B](seq: Seq[A])(key: A => K)(f: A => B): Seq[(K, Seq[B])] = {
val keyIndices = seq.map(key).distinct.zipWithIndex.toMap
seq.groupMap(key)(f)
.toSeq
.sortBy { case (k, _) => keyIndices(k) }
}

def jvmBuildTarget(d: JvmBuildTarget): bsp4j.JvmBuildTarget =
new bsp4j.JvmBuildTarget().tap { it =>
d.javaHome.foreach(jh => it.setJavaHome(jh.uri))
d.javaVersion.foreach(jv => it.setJavaVersion(jv))
}
}
13 changes: 7 additions & 6 deletions bsp/worker/src/mill/bsp/worker/State.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import mill.define.Module
import mill.eval.Evaluator

private class State(workspaceDir: os.Path, evaluators: Seq[Evaluator], debug: String => Unit) {
lazy val bspModulesById: Map[BuildTargetIdentifier, (BspModule, Evaluator)] = {
lazy val bspModulesIdList: Seq[(BuildTargetIdentifier, (BspModule, Evaluator))] = {
val modules: Seq[(Module, Seq[Module], Evaluator)] = evaluators
.map(ev => (ev.rootModule, JavaModuleUtils.transitiveModules(ev.rootModule), ev))

val map = modules
.flatMap { case (rootModule, otherModules, eval) =>
(Seq(rootModule) ++ otherModules).collect {
modules
.flatMap { case (rootModule, modules, eval) =>
modules.collect {
case m: BspModule =>
val uri = Utils.sanitizeUri(
rootModule.millSourcePath /
Expand All @@ -24,9 +24,10 @@ private class State(workspaceDir: os.Path, evaluators: Seq[Evaluator], debug: St
(new BuildTargetIdentifier(uri), (m, eval))
}
}
.toMap
}
lazy val bspModulesById: Map[BuildTargetIdentifier, (BspModule, Evaluator)] = {
val map = bspModulesIdList.toMap
debug(s"BspModules: ${map.view.mapValues(_._1.bspDisplayName).toMap}")

map
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import mill.bsp.worker.Utils.{makeBuildTarget, sanitizeUri}
import mill.scalalib.bsp.{BspBuildTarget, BspModule}
import mill.scalalib.bsp.BspModule.Tag

import java.util.UUID
import scala.jdk.CollectionConverters._
import ch.epfl.scala.bsp4j.BuildTarget

Expand All @@ -15,11 +14,11 @@ import ch.epfl.scala.bsp4j.BuildTarget
*/
class SyntheticRootBspBuildTargetData(topLevelProjectRoot: os.Path) {
val id: BuildTargetIdentifier = new BuildTargetIdentifier(
Utils.sanitizeUri(topLevelProjectRoot / s"synth-build-target-${UUID.randomUUID()}")
Utils.sanitizeUri(topLevelProjectRoot / "mill-synthetic-root-target")
)

val bt: BspBuildTarget = BspBuildTarget(
displayName = Some(topLevelProjectRoot.last + "-root"),
displayName = Some("mill-synthetic-root"),
baseDirectory = Some(topLevelProjectRoot),
tags = Seq(Tag.Manual),
languageIds = Seq.empty,
Expand Down
2 changes: 1 addition & 1 deletion bsp/worker/src/mill/bsp/worker/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private object Utils {
originId: String,
bspIdsByModule: Map[BspModule, BuildTargetIdentifier],
client: BuildClient
): Int => Option[CompileProblemReporter] = { moduleHashCode: Int =>
): Int => Option[CompileProblemReporter] = { (moduleHashCode: Int) =>
bspIdsByModule.find(_._1.hashCode == moduleHashCode).map {
case (module: JavaModule, targetId) =>
val buildTarget = module.bspBuildTarget
Expand Down
Loading

0 comments on commit 817971f

Please sign in to comment.