Skip to content

Commit

Permalink
Better error reporting for the linking stage and NoOp for linking JVM
Browse files Browse the repository at this point in the history
When linking a JVM project the link task now simply noops. This lets
clients send all build projects to the link task and the task will only
link where possible. This way the client does not need to be explicit
when linking (although still possible).

Errors when linking are now accumulated and error logged. Bsp returns an
error code when encountering linking errors.
  • Loading branch information
KristianAN committed Dec 19, 2024
1 parent 2dde187 commit cd1b42f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
27 changes: 14 additions & 13 deletions frontend/src/main/scala/bloop/bsp/BloopBspServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ final class BloopBspServices(
def doLink(
project: Project,
newState: State
) =
): Task[(State, Right[Nothing, CompileResult])] =
project.platform match {
case platform @ Js(config, _, _) =>
val cmd = Commands.Link(List(project.name))
Expand All @@ -449,7 +449,9 @@ final class BloopBspServices(
}
(linkState, result)
}
case Jvm(_, _, _, _, _, _) => ???
case Jvm(_, _, _, _, _, _) =>
// We can just NoOp here as we have already run the compile step before doLink
Task.now((newState, Right(bsp.CompileResult(originId, bsp.StatusCode.Ok, None, None))))
case platform @ Native(config, _, userMainClass) =>
val cmd = Commands.Link(List(project.name))
val target = ScalaNativeToolchain.linkTargetFrom(project, config)
Expand All @@ -470,24 +472,23 @@ final class BloopBspServices(

linkExecution.materialize.map {
case Success(linkRunsSeq) =>
linkRunsSeq
.map(_._2)
.foldLeft(Option.empty[CompileResult])((_, res) => // TODO propogate stuff better here
res match {
case Left(_) => None
case Right(value) => Some(value)
}
) match {
case None =>
(newState, Right(bsp.CompileResult(originId, bsp.StatusCode.Error, None, None)))
case Some(result) => (newState, Right(result))
val errors = linkRunsSeq.collect { case (_, Left(err)) => err }
if (errors.nonEmpty) {
logger.error(
s"Encountered errors when liking\n${errors.map(_.getMessage()).mkString("\n")}"
)
(newState, Right(bsp.CompileResult(originId, bsp.StatusCode.Error, None, None)))
} else {
linkRunsSeq.last
}
case Failure(e) =>
val errorMessage =
Response.internalError(s"Failed linking: ${e.getMessage}")
(newState, Left(errorMessage))
}

case (newState, Right(CompileResult(_, errorCode, _, _))) =>
Task.now((newState, Right(bsp.CompileResult(originId, errorCode, None, None))))
case (newState, Left(error)) =>
Task.now((newState, Left(error)))
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/main/scala/bloop/engine/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ object Interpreter {
case platform @ Platform.Native(config, _, _) =>
val target = ScalaNativeToolchain.linkTargetFrom(project, config)
LinkTask.linkNative(cmd, project, state, None, target, platform)
case _ => Task.now(state)
}

case Right(mainClass) =>
Expand Down

0 comments on commit cd1b42f

Please sign in to comment.